如何在 iOS 7 锁屏上设置当前播放时长和已用时间? [英] How to set current playback duration and elapsed time on iOS 7 lockscreen?

查看:13
本文介绍了如何在 iOS 7 锁屏上设置当前播放时长和已用时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 iOS 5 开始,每个音乐播放器都可以在 [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo 上设置当前播放的音乐信息,如标题、艺术家、专辑标题和插图,以显示在锁定屏幕上.

Starting from iOS 5, every music player can set current playing music information such as title, artist, album title, and artwork on [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo to show on lock screen.

在 iOS 7 上,锁定屏幕和控制中心都添加了播放位置滑块、持续时间和已用时间信息.但是,我找不到任何文档来设置这些类型的信息并启用滑块更改播放位置.

On iOS 7, playback position slider, duration, and elapsed time information are added to both lock screen and control center. However, I cannot find any documents to set these kinds of information and enable the slider to change playback position.

有什么办法可以解决这个问题吗?

Is there any way to solve this problem?

推荐答案

即使文档说默认为 1.0,您也需要将播放速率设置为 1.0f.

You need to setup playback rate to 1.0f even if documentation says it's 1.0 by default.

NSDictionary *mediaInfo = @{
    MPMediaItemPropertyTitle: audio.title,
    MPMediaItemPropertyArtist: audio.artist,
    MPMediaItemPropertyPlaybackDuration: audio.duration,
    MPNowPlayingInfoPropertyPlaybackRate: @(1.0)
};

[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];

这篇关于如何在 iOS 7 锁屏上设置当前播放时长和已用时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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