如何更改锁定屏幕/控制中心的轨道位置? [英] How to change track position on lock screen/control center?

查看:232
本文介绍了如何更改锁定屏幕/控制中心的轨道位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ios 7音乐应用程序播放歌曲时,用户可以使用滑块更改锁定屏幕/控制中心中的歌曲位置。滑块处于活动状态:

When playing a song with the ios 7 music app the user can use slider to change song position in the lock screen/the control center. Slider is active:

但是在我的应用程序中播放音乐的用户无法做到这一点。滑块未激活:

But when playing music in my app user can't do it. Slider isn't active:

如何在我的应用程序中启用这些功能?

How can i enable these feature in my app?

推荐答案

您可以在iOS 9.1及更高版本的MPRemoteCommandCenter的帮助下更改曲目位置。

You can change track position with help of MPRemoteCommandCenter on iOS 9.1 and higher.

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_0) {
            MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
            [commandCenter.changePlaybackPositionCommand setEnabled:true];
            [commandCenter.changePlaybackPositionCommand addTarget:self action:@selector(changedThumbSliderOnLockScreen:)];
        }

和方法

- (MPRemoteCommandHandlerStatus)changedThumbSliderOnLockScreen:(MPChangePlaybackPositionCommandEvent *)event
{
    // change position
    [self setCurrentPlaybackTime:event.positionTime];
    // update MPNowPlayingInfoPropertyElapsedPlaybackTime
    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];

    return MPRemoteCommandHandlerStatusSuccess;
}

这篇关于如何更改锁定屏幕/控制中心的轨道位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆