问题
I have my app successfully streaming an MP3 via AVPlayer. I implemented a MPVolumeView to pull in AirPlay support which works great but I notice that the title info on my apple tv, does not show anything from the streamed MP3 but rather just "Unknown" info. Is there anyway to control this info from the app or is this an issue caused by the MP3 being streamed? Any help would be much appreciated!!
回答1:
I wanted to update this question in case someone else needed to control what is seen on their Apple TV during AirPlay. This functionality is for iOS5 yet the code sample below will compile properly on an app that includes iOS4 support.
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
UIImage *albumArtImage = [UIImage imageNamed:@"Album-Image-Name.png"];
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:albumArtImage];
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Artist Name", MPMediaItemPropertyArtist,
@"Title Name", MPMediaItemPropertyTitle,
@"Album Name", MPMediaItemPropertyAlbumTitle,
artwork, MPMediaItemPropertyArtwork,
nil];
center.nowPlayingInfo = songInfo;
}
This is all setup when you call the play method on your media player, such as AVPlayer.
回答2:
If you are using iOS 5 take a look at MPNowPlayingInfoCenter. It is simple to use and get metadata to the AppleTv and other devices. You may need to implement support for remote control as well. The only thing I do not have working properly yet is the duration and current position.
来源:https://stackoverflow.com/questions/6021175/airplay-meta-data-on-apple-tv-from-app-avplayer-mpvolumeview