iOS 如何允许用户从 LockScreen 或 ControlCenter 控制当前音频持续时间?

How to allow user to control current audio duration from LockScreen or ControlCenter in iOS?

我允许用户在我的 app.I 中播放音轨,但是我在锁上设置当前音频播放的滑块时遇到问题 screen.Here 是它的屏幕截图:

如何设置当前歌曲播放并允许用户使用锁定屏幕上的歌曲滑块更改它?

您了解过 MPRemoteCommandCenter 的方法和属性了吗,我相信您可以使用这里的命令向前或向后跳过。 恐怕你不会得到类似于 iTunes 音乐的平滑滑块,因为他们没有为开发人员公开类似的东西。

要在锁定屏幕上设置曲目持续时间,您必须像下面这样设置 MPMediaItemPropertyPlaybackDuration::

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
            NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithDouble:songDuration],MPMediaItemPropertyPlaybackDuration,
                                      nil];


            [center setNowPlayingInfo:songInfo];