So, I am making a music player using system.musicplayer(), as it ipod.musicplayer()was deprecated with iOS 8. Anyway, I have pause and play buttons that work fine when the background music application is open in the background, but not when it is (t .e. is removed from multitasking). Before adding the condition, the ifapplication will break, and now nothing happens at all, since I really do not know what to add. Any advice? I am really lost.
@IBAction func playButtonAction(sender: AnyObject) {
if let mediaItem = musicPlayer.nowPlayingItem {
if (self.isPlay) {
musicPlayer.pause()
self.isPlay = false
} else {
musicPlayer.play()
self.isPlay = true
setupCurrentMediaItem()
handleShuffleAndReplayMode()
}
} else {
//music
}
}
cyril source
share