0

Possible Duplicate:
iOS: Updating Media Information in the Background

I have an application that streams music from a server, I want to show the information of the now playing music when the user lock the iPhone screen actually I have found this code online:

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

if (playingInfoCenter) {
    MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
    NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"Artist", MPMediaItemPropertyArtist,
                              @"Title", MPMediaItemPropertyTitle,
                              @"AlbumTitle", MPMediaItemPropertyAlbumTitle,
                              nil];
    center.nowPlayingInfo = songInfo;

}

But I don't know where to inject this code I tried to put it inside the IBAction method which is linked to the play button but it didn't work. Is there any one can help me with that ? please. Thanks in advance.

Community
  • 1
  • 1
4slices
  • 241
  • 6
  • 15
  • Are you actually playing background audio? – CodaFi Dec 02 '12 at 19:25
  • @CodaFi : Yes I play a background audio. – 4slices Dec 02 '12 at 19:27
  • @Till : In my app I use UIWebView to open the files so I'm not using the AVPlayer which is located in the question you mentioned my code to open these files here : [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.website.com/file.mp3"]]]; – 4slices Dec 02 '12 at 19:34
  • @4slices still this part of that question is exactly what you were missing: `if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){ [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; //These two steps are important if you want the user to be able to change tracks with remote controls (you'll have to handle the remote control events yourself). }` – Till Dec 02 '12 at 19:37
  • where shall I insert this code? is it inside the play button action ? or some where else? – 4slices Dec 02 '12 at 19:40
  • @4slices all of that is drafted in the quoted answer.... Please dude, do read that answer - yes, it is not a webview but the mechanics are the exact same. – Till Dec 02 '12 at 20:00

0 Answers0