如何在iOS Lock Screen控制面板中启用音频滑块?

时间:2013-09-22 07:07:13

标签: ios avaudioplayer avaudiosession mpnowplayinginfocenter

我有以下MPNowPlayingInfoCenter字典

@{MPMediaItemPropertyAlbumTitle: @"First Title",
                                MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"Album-Cover.jpg"]],
                                MPMediaItemPropertyPlaybackDuration:[NSNumber numberWithDouble:self.storyAudioPlayer.duration],
                                MPNowPlayingInfoPropertyElapsedPlaybackTime:[NSNumber numberWithDouble:self.storyAudioPlayer.currentTime],
                                MPNowPlayingInfoPropertyPlaybackRate:@1.0
                                }

其他一切正常,但我无法使用滑块寻找歌曲。如图所示。我错过了什么参数?

Lock screen screenshot

3 个答案:

答案 0 :(得分:3)

你做不到。您可以向Apple提交错误报告,以便他们有一天能够实施它。

编辑:现在可以从iOS 9开始了

答案 1 :(得分:3)

您可以借助MPRemoteCommandCenter和changePlaybackPositionCommand在iOS 9.1及更高版本上执行此操作。

查看我的answer

答案 2 :(得分:0)

快速5

您可以使用MPRemoteCommandCenter.changePlaybackPositionCommand来做到这一点。

  

用于更改媒体项中播放位置的命令对象。

let commandCenter = MPRemoteCommandCenter.shared()
    commandCenter.changePlaybackPositionCommand.isEnabled = true
    commandCenter.changePlaybackPositionCommand.addTarget { event in
        if let event = event as? MPChangePlaybackPositionCommandEvent {
            let time = CMTime(seconds: event.positionTime, preferredTimescale: 1000000)
            self.avplayer.seekTo(time)
        }
        return .success
    }