Created
November 16, 2016 23:45
-
-
Save StephenGilboy/8bbf72db20e887aa1d63d974a5a82682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var curNode = AVAudioPlayerNode() | |
func play() { | |
curNode.play(); | |
NotificationCenter.default.post(name: Notification.Name(rawValue: audioPlayerDidStartPlaying), object: self) | |
} | |
func pause() { | |
curNode.pause(); | |
NotificationCenter.default.post(name: Notification.Name(rawValue: audioPlayerDidPause), object: self) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let audioPlayerDidPause = "com.jcmoods.audioPlayerDidPauseNotificationKey"; | |
let audioPlayerDidStartPlaying = "com.jcmoods.audioPlayerDidStartPlayingNotificationKey"; | |
var paused: Bool? = true | |
var player: AudioPlayer; | |
func play() { | |
player.play(); | |
} | |
func pause() { | |
player.pause(); | |
} | |
func playerDidStartPlaying() { | |
paused = false; | |
print("playing"); | |
} | |
func playerDidPause() { | |
paused = true | |
print("pause called") | |
} | |
override func viewDidLoad() { | |
player = new AudioPlayer(); | |
NotificationCenter.default.addObserver(self, selector: "playerDidStartPlaying", name: NSNotification.Name(rawValue: audioPlayerDidStartPlaying), object: nil) | |
NotificationCenter.default.addObserver(self, selector: "playerDidPause", name: NSNotification.Name(rawValue: audioPlayerDidPause), object: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment