How can I set title music on remote control on ios 7 during I use AVPlayer to play the music in background?
Asked
Active
Viewed 1,748 times
0
-
solution here http://stackoverflow.com/questions/8387262/how-to-set-an-title-of-the-currently-playing-audio-in-iphone-lock-screen – Damien Romito Jan 24 '14 at 19:11
1 Answers
2
the class you want is MPNowPlayingInfoCenter .
create a dictionary of values and pass them to it sorta like this...
NSMutableDictionary *info=[NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Song title",@"Artist name",nil] forKeys:[NSArray arrayWithObjects: MPMediaItemPropertyTitle,MPMediaItemPropertyArtist,nil]];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:info];
Make sure you import the following:
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>
#import <MediaPlayer/MPMediaQuery.h>
the keys in the dictionary are as follows:
MPMediaItemPropertyAlbumTitle
MPMediaItemPropertyAlbumTrackCount
MPMediaItemPropertyAlbumTrackNumber
MPMediaItemPropertyArtist
MPMediaItemPropertyArtwork
MPMediaItemPropertyComposer
MPMediaItemPropertyDiscCount
MPMediaItemPropertyDiscNumber
MPMediaItemPropertyGenre
MPMediaItemPropertyPersistentID
MPMediaItemPropertyPlaybackDuration
MPMediaItemPropertyTitle
MPNowPlayingInfoPropertyElapsedPlaybackTime
MPNowPlayingInfoPropertyPlaybackRate;
MPNowPlayingInfoPropertyPlaybackQueueIndex;
MPNowPlayingInfoPropertyPlaybackQueueCount;
MPNowPlayingInfoPropertyChapterNumber;
MPNowPlayingInfoPropertyChapterCount;
source:

Ben
- 843
- 8
- 9
-
-
@Victor M , Well the code assumes you have registered for remote events and have acquired an audio session with the background audio available and have the multitasking flag for background audio in your plist file set. any of that help? if not, you could show me your implementation and i could try to see what's wrong. – Ben Aug 19 '15 at 23:29
-
@Ben , thank you for reply. I've found my inaccuracy: my `[AVAudioSession sharedInstance]` had wrong options. And correct is: `[AVAudioSession.sharedInstance setActive:YES withOptions:0 error:nil]; [AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback withOptions:0 error:nil]; [UIApplication.sharedApplication beginReceivingRemoteControlEvents];` – Victor Aug 20 '15 at 22:41