45

再生を一時停止するときに MPNowPlayingInfoCenter を適切に機能させようとしています。(再生に AVPlayer を使用するストリーミング音楽アプリがあり、Airplay を介して Apple TV で再生しています。) 一時停止以外はすべて、Apple TV UI に正しく反映されているようです。私は次のように初期化しています:

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = @{
    MPMediaItemPropertyTitle: title,
    MPMediaItemPropertyArtist: artist
};
center.nowPlayingInfo = songInfo;

私はストリーミングしているので、再生を開始した時点ではデュレーション情報がありません。ストリームから「準備完了」信号を受信したら、Apple TV に正しく表示される期間を更新します。

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];
[playingInfo setObject:[NSNumber numberWithFloat:length] forKey:MPMediaItemPropertyPlaybackDuration];
center.nowPlayingInfo = playingInfo;

ユーザーがトラックをシークするときに、この手法を使用してシークすることもできます。

[playingInfo setObject:[NSNumber numberWithFloat:length * targetProgress] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];

私が理解できないことの 1 つは、Apple TV で再生ヘッドを一時停止する方法です。ユーザーがUIで一時停止をタップすると、次のようなことをしようとしています:

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];        
[playingInfo setObject:[NSNumber numberWithFloat:0.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];            
center.nowPlayingInfo = playingInfo;

一時停止する代わりに、再生ヘッドをゼロに戻して進めます。

Apple TV UI で再生ヘッドを正しく一時停止するにはどうすればよいですか?

4

3 に答える 3

15

私は解決策を持っています!MPMediaItemPropertyPlaybackDuration のみを設定する

1 - トラックを開始するときに、トラックの合計時間をプロパティに設定します。

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = @{
    MPMediaItemPropertyTitle: title,
    MPMediaItemPropertyArtist: artist
    MPMediaItemPropertyPlaybackDuration : [NSNumber numberWithFloat:length]
};
center.nowPlayingInfo = songInfo;

2 - トラックを一時停止すると... 何もしません。

3 - トラックを再生するときは、プロパティに currentTrackTime を設定します。

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.nowPlayingInfo];        
[playingInfo setObject:[NSNumber numberWithFloat:player.currentTrackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];            
center.nowPlayingInfo = playingInfo;
于 2014-02-11T01:12:56.607 に答える
3

ここであなたが探しているもの、これは非常にうまく機能しており、これをあなたのクラスに追加してください:

- (void)remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {

    if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {

            case UIEventSubtypeRemoteControlTogglePlayPause:[self playPause:nil];

                break;

            default: break;
        }
    }
}

次のような他の CASE コードを追加して、前方または後方の関数を追加できます。

case UIEventSubtypeRemoteControlBeginSeekingBackward:[self yourBackward:nil];
                break;

play pause を呼び出すには、次のようなアクションを作成する必要があります。

- (IBAction)playPause:(id)sender {

    if (yourPlayer.rate == 1.0){

        [yourPlayer pause];
    } else if (yourPlayer.rate == 0.0) {

        [yourPlayer play];
    }
}

重要: 追加する場合は必ず IBAction が必要です

これがあなたを助けることを願っています

于 2013-04-30T13:57:16.243 に答える
-2
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *songInfo = @{
    MPMediaItemPropertyTitle: title,
    MPMediaItemPropertyArtist: artist
};

のような呼び出し

center setnowPlayingInfo = songInfo;
于 2013-10-01T10:30:40.140 に答える