Skip to content

Commit

Permalink
Merge pull request #1 from pjay/init-nsurl
Browse files Browse the repository at this point in the history
Add initializer from NSURL
  • Loading branch information
Tom Baranes committed Feb 2, 2016
2 parents f65e803 + 3ce2df4 commit f424215
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Source/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ public class AudioPlayer: NSObject {
let path = NSBundle.mainBundle().pathForResource(soundFileComponents[0], ofType: soundFileComponents[1])
try self.init(contentsOfPath: path!)
}

public init(contentsOfPath path: String) throws {
public convenience init(contentsOfPath path: String) throws {
let fileURL = NSURL(fileURLWithPath: path)
URL = fileURL
name = fileURL.lastPathComponent
sound = try? AVAudioPlayer(contentsOfURL: fileURL)
try self.init(contentsOfURL: fileURL)
}

public init(contentsOfURL URL: NSURL) throws {
self.URL = URL
name = URL.lastPathComponent
sound = try? AVAudioPlayer(contentsOfURL: URL)
super.init()

sound?.delegate = self
Expand Down

0 comments on commit f424215

Please sign in to comment.