AirPlay Meta Data on Apple TV from App (AVPlayer - MPVolumeView)

落爺英雄遲暮 提交于 2019-12-23 19:04:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!