tvOS 并在 AVPlayer "空闲"时显示艺术品和标题?



我试图找出如何显示专辑的艺术作品和标题时,播放器没有用户输入一点和tvOS显示其播放器视图?基本上是带有半透明背景和普通艺术品的屏幕。应用程序名称被显示在我期望显示歌曲信息的地方。

目前我已经创建了一个播放音频的tvOS应用程序,并通过添加我自己的标签,通过子视图成功地在主屏幕上显示艺术作品和标题:

   let albumArtView = UIImageView(image: image)
   self.contentOverlayView?.addSubview(albumArtView)

对于滑动面板中的详细信息,我使用:

    playerItem = AVPlayerItem(url: videoURL!)
    // Add station title
    let titleMetadataItem = AVMutableMetadataItem()
    titleMetadataItem.locale = Locale.current
    titleMetadataItem.key = AVMetadataCommonKeyTitle as (NSCopying & NSObjectProtocol)?
    titleMetadataItem.keySpace = AVMetadataKeySpaceCommon
    titleMetadataItem.value = stationName as (NSCopying & NSObjectProtocol)?
    playerItem!.externalMetadata.append(titleMetadataItem)
    // Add station description
    let descriptionMetadataItem = AVMutableMetadataItem()
    descriptionMetadataItem.locale = Locale.current
    descriptionMetadataItem.key = AVMetadataCommonKeyDescription as (NSCopying & NSObjectProtocol)?
    descriptionMetadataItem.keySpace = AVMetadataKeySpaceCommon
    descriptionMetadataItem.value = stationDescription as (NSCopying & NSObjectProtocol)?
    playerItem!.externalMetadata.append(descriptionMetadataItem)
    // Add station artwork
    let image = UIImage(named: "stationAlbumArt")
    let artworkMetadataItem = AVMutableMetadataItem()
    artworkMetadataItem.locale = Locale.current
    artworkMetadataItem.identifier = AVMetadataCommonIdentifierArtwork
    artworkMetadataItem.value = UIImagePNGRepresentation(image!) as (NSCopying & NSObjectProtocol)?
    playerItem!.externalMetadata.append(artworkMetadataItem)

这似乎不会影响通用屏幕。我看到苹果的音乐播放器显示艺术曲目标题和专辑名称,所以我想知道是否playerItem!.externalMetadata是正确的属性要使用这个?

再研究一下,我似乎需要使用'MPNowPlayingInfoCenter':

let title = "track title"
let artist = "artist name"
let artwork = MPMediaItemArtwork(image: UIImage(named: "stationAlbumArt")!)
let nowPlayingInfo = [MPMediaItemPropertyArtist : artist,  MPMediaItemPropertyTitle : title, MPMediaItemPropertyArtwork : artwork] as [String : Any]
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
UIApplication.shared.beginReceivingRemoteControlEvents()

相关内容

  • 没有找到相关文章

最新更新