Detecting if music is playing?

Flafla2 picture Flafla2 · Feb 16, 2010 · Viewed 8.2k times · Source

My app involves music(iPodMusic), and there is a UISwitch toggling play/pause. My goal is to be able to detect if music is playing, so that therefore the play/pause switch can say 'play' when music is playing and 'pause' if it isn't.

Answer

Ole Begemann picture Ole Begemann · Feb 16, 2010
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying) ...