Question

Is there any way I can access music playing in the native iOS music app? For example on button press in my app it pauses the built in Music app. I've tried MPMusicPlayerController but that doesn't seem to be what I want; or I'm not using it correctly.

This is what I've tried.

    if ([musicPlayer playbackState] == MPMusicPlaybackStatePlaying) {
            [musicPlayer pause];
    } else {
            [musicPlayer play];
    }
Was it helpful?

Solution

Depends on how you instantiate your music player. To get access to the system global payer you should use:

MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

Be aware that if you're using applicationMusicPlayer it will only work for your application and pausing music will not affect the music playing in your Music.app.

See the MPMusicPlayerController documentation overview section for a more extensive description of the two.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top