7

我已经使用AVAudioPlayer(not AVPlayer) 实现了一个音频播放器。我可以使用以下方法处理远程控制事件。到目前为止它工作得很好,但是我看到subtypes这些事件还有两个: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. 此方法仅启用锁定屏幕上的rewindplay/pausefast forward按钮,但不显示文件标题、插图和持续时间。如何使用AVAudioPlayeror显示该信息AVAudioSession(我真的不希望再有一个库/API 来实现它)?

    2-a。我MPNowPlayingInfoCenter在搜索时发现,我对它了解不多。我必须用它来实现上面的那些东西吗?:-[

4

1 回答 1

11

MPNowPlayingInfoCenter是对的,只有这样才能做到这一点。所以继续链接MediaPlayer.framework。在处理播放曲目的类中,导入<MediaPlayer/MediaPlayer.h>. 每当您的曲目发生变化时,请执行以下操作:

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

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