Skip to content

Instantly share code, notes, and snippets.

@StephenGilboy
Created November 16, 2016 23:45
Show Gist options
  • Save StephenGilboy/8bbf72db20e887aa1d63d974a5a82682 to your computer and use it in GitHub Desktop.
Save StephenGilboy/8bbf72db20e887aa1d63d974a5a82682 to your computer and use it in GitHub Desktop.
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)
}
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