-1

i tried to look for it for days in google and i couldn't find an answer. i have an app that play audio stream from the internet and i use MPNowPlayingInfoCenter to display the artist title, song title and artwork. now my question is how to use the play/pause button in the MPNowPlayingInfoCenter to play or stop my audio stream.

Yogendra
  • 1,728
  • 16
  • 28
  • possible duplicate of [iOS MPMoviePlayerController playing audio in background](http://stackoverflow.com/questions/15540726/ios-mpmovieplayercontroller-playing-audio-in-background) – Neeku Jul 07 '14 at 12:54

1 Answers1

1

For this you have to handle remote control Events --

//Add these lines in viewDidAppear()
 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
 [self becomeFirstResponder];

//Add these lines in viewWillDisappear() 
[[UIApplication sharedApplication] endReceivingRemoteControlEvents]; 
[self resignFirstResponder];

Then Use

-(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
 NSLog(@"received event!");
 if (receivedEvent.type == UIEventTypeRemoteControl)
{
    switch (receivedEvent.subtype)
    {
        case UIEventSubtypeRemoteControlPlay:
            //  play the video 
            break;

        case  UIEventSubtypeRemoteControlPause:
            // pause the video 
            break;

        case  UIEventSubtypeRemoteControlNextTrack:
          // to change the video 
            break;

        case  UIEventSubtypeRemoteControlPreviousTrack:
            // to play the privious video 
            break;

        default:
            break;
    }
}

}

Yogendra
  • 1,728
  • 16
  • 28