Pergunta

I am incorporating the iPod player in my app. I am able to create a queue, then play the songs. I am not able to get the current song's property values. I have registered for the notifications and the log shows the notifications are bing triggered.

MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
NSLog(@"currentItem = %@", currentItem);

Log output shows: currentItem = (null)

I'm running Xcode 4.5.2 iOS 6.0.

Any help is greatly appreciated.

Foi útil?

Solução

For anyone else who may run into the same issue, the problem was that I synced my Music after running my application. You need to observe for Library changes:

MPMediaLibraryDidChangeNotification

[[MPMediaLibrary defaultLibrary] beginGeneratingLibraryChangeNotifications];

Outras dicas

You wrote NSLog(@"currentItem = %@", currentItem); in your codes but maybe you have not got a full understand of what MPMediaItem is.

MPMediaItem is not NSString, and that's why you got null here. MPMediaItem has a lot of properties including song title, album name and artist name. To access the properties of MPMediaItem such as the title, use valueForProperty: method.

NSLog(@"currentItem = %@", [currentItem valueForProperty:MPMediaItemPropertyTitle])

Something like this.

I also had the problem that I mixed by accident the application player

[MPMusicPlayerController applicationMusicPlayer]

and the ipod player

[MPMusicPlayerController iPodMusicPlayer]

I was using the iPodMusicPlayer for playing music and tried to adjust the volume of the applicationMusicPlayer by accident.

So just beware not to mix them unintentionally ;-)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top