【问题标题】:How can you extract the overall stream title from AVPlayer?如何从 AVPlayer 中提取整个流标题?
【发布时间】:2020-05-06 08:32:58
【问题描述】:

我在 Swift 中使用 AVPlayer 和 AVPlayerItem 来播放互联网广播流。

观察“timedMetadata”给了我当前正在播放的曲目,但我似乎从来没有得到电台标题的句柄

查看这个使用 VLC 的示例,我可以使用 timedMetadata 轻松获取“正在播放”部分,但是我从未收到电台“标题”的整体标题。

我错过了什么,我应该观察其他东西来访问流的/shoutcast/icecast 信息吗?

【问题讨论】:

  • 只是猜测,“标题”是文件名吗?还是和文件名完全不同?
  • 应该使用AVPlayerItemMetadataOutput,类似解决问题见Get AVPlayerItem track title with SwiftUI
  • 感谢@Asperi,但同样的问题:我只能通过该解决方案获得“正在播放”的内容。
  • @keyle,你试过我回答中的代码吗?
  • @elliott-io 没有机会,忙于另一个项目,今晚我会的。

标签: ios swift macos


【解决方案1】:

试试这个:

let title = AVMetadataItem.metadataItems(from: urlAsset.commonMetadata, withKey: AVMetadataKey.commonKeyTitle, keySpace: AVMetadataKeySpace.common).first?.value as? String
print(title)

这适用于标题中包含元数据的媒体(使用 Apple Music 应用程序设置)。如果这不适用于您的媒体,请将其与您当前的代码一起发布到网上某个地方。

【讨论】:

    猜你喜欢
    • 2011-08-27
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多