0

AVPlayerItems で表される曲を再生するために AVPlayer を使用する iOS アプリケーションを使用しています。

MPNowPlayingInfoCenter.defaultCenter() の nowPlayingInfo プロパティを設定しようとしましたが、経過時間や再生時間などの他の情報を更新する必要があるため、AVPlayer によって情報がすぐに上書きされるようです。

プログラム実行直後でも

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo?[MPMediaItemPropertyTitle] = "Title"

のプリントアウトMPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo

Info: ["MPNowPlayingInfoPropertyElapsedPlaybackTime": 34.89555007300078, "AVNowPlayingInfoControllerIdentifierKey": <__NSConcreteUUID 0x13778e9b0> 9141DD1C-FD09-4210-B3C7-B948522E3AF6, "playbackDuration": 198.2516666666667, "MPNowPlayingInfoPropertyPlaybackRate": 1]

私は何を間違っていますか?タイトル/アルバム名などの追加のメタデータを AVPlayerItem に保存して、情報センターに表示することはできますか?

また、AVNowPlayingInfoControllerIdentifierKey とは何ですか? AVNowPlayingInfoController という名前のクラスはないようです。

4

1 に答える 1

2

問題は、この行が何もしないことです:

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo?[MPMediaItemPropertyTitle] =
    "Title"

その行が実際に何かを行ったとしても、のコピーを別の辞書として取得し、その別の辞書に書き込むことになります。実際の現在再生中の情報に書き込むことはありません。これは、あなたがやりたいことです。nowPlayingInfo

正しいアプローチは、ディクショナリを作成MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo してから、そのディクショナリに設定することです。

例えば:

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = 
    [MPMediaItemPropertyTitle : "Title"]

(もちろん、ディクショナリにはさらに多くのエントリを含めることができます。)

于 2015-11-29T00:39:46.803 に答える