7

AVAudioPlayer(not )を使用してオーディオ プレーヤーを実装しましたAVPlayer。次の方法でリモート コントロール イベントを処理できます。これまでのところ問題なく動作しますがsubtypes、これらのイベントにはさらに 2 つのイベントがあります:UIEventSubtypeRemoteControlEndSeekingForwardUIEventSubtypeRemoteControlEndSeekingBackward.

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    //if it is a remote control event handle it correctly
    if (event.type == UIEventTypeRemoteControl)
    {
        if (event.subtype == UIEventSubtypeRemoteControlPlay)
        {
            [self playAudio];
        }
        else if (event.subtype == UIEventSubtypeRemoteControlPause)
        {
            [self pauseAudio];
        }
        else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause)
        {
            [self togglePlayPause];
        }
        else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingBackward)
        {
            [self rewindTheAudio]; //this method rewinds the audio by 15 seconds.
        }
        else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingForward)
        {
            [self fastForwardTheAudio]; //this method fast-forwards the audio by 15 seconds.
        }

}

だから質問:

  1. 正しく動作させるために、これら 2 つのサブタイプも実装する必要がありますか?

  2. この方法では、ロック画面でrewindplay/pause、およびボタンのみが有効になりますが、ファイルのタイトル、アートワーク、および期間は表示されません。fast forwardまたはを使用してその情報を表示するにはどうすればよいですAVAudioPlayerAVAudioSession(これを実装するためにもう 1 つのライブラリ/API は必要ありません)。

    2-a。検索中に発見MPNowPlayingInfoCenterしたのですが、よくわかりません。上記のものを実装するためにそれを使用する必要がありますか? :-[

4

1 に答える 1

11

あなたは正しいです、MPNowPlayingInfoCenterこれを行う唯一の方法です。では、 とリンクしてMediaPlayer.frameworkください。トラックの再生を処理するクラスで、 import <MediaPlayer/MediaPlayer.h>. トラックが変更されるたびに、次のようにします。

NSDictionary *info = @{ MPMediaItemPropertyArtist: artistName,
                            MPMediaItemPropertyAlbumTitle: albumName,
                            MPMediaItemPropertyTitle: songName };

    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = info;
于 2013-12-03T22:55:35.310 に答える