iOS 7使用AVPlayer在锁定屏幕上回放歌曲 [英] iOS 7 rewind songs on lock screen using AVPlayer

查看:137
本文介绍了iOS 7使用AVPlayer在锁定屏幕上回放歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何从锁定屏幕iOS 7回放歌曲的方式。音量滑块可用,所有按钮都正常工作但上部滑块不可用!

I havn't found the way how to rewind song from lock screen iOS 7. Volume slider is available, all the buttons work correctly but the upper slider is not available!

AVPlayer是我正在使用的课程。

AVPlayer is the class I'm using.

感谢任何帮助!

推荐答案

您需要在正在播放的信息中设置此项。

You'll need to set this in the "now-playing info".

每当项目(曲目)发生变化时,请执行以下操作: / p>

Whenever the item (track) changes, do something like

NSMutableDictionary *nowPlayingInfo = [[NSMutableDictionary alloc] init];
[nowPlayingInfo setObject:track.artistName forKey:MPMediaItemPropertyArtist];
[nowPlayingInfo setObject:track.trackTitle forKey:MPMediaItemPropertyTitle];
...
[nowPlayingInfo setObject:[NSNumber numberWithDouble:self.player.rate] forKey:MPNowPlayingInfoPropertyPlaybackRate];
[nowPlayingInfo setObject:[NSNumber numberWithDouble:self.currentPlaybackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nowPlayingInfo;

每当播放速率发生变化(播放/暂停)时,请执行

Whenever the playback rate changes (play/pause), do

NSMutableDictionary *nowPlayingInfo = [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo mutableCopy];
[nowPlayingInfo setObject:[NSNumber numberWithDouble:self.player.rate] forKey:MPNowPlayingInfoPropertyPlaybackRate];
[nowPlayingInfo setObject:[NSNumber numberWithDouble:self.currentPlaybackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nowPlayingInfo;

您可以像这样获得当前播放时间:

You can get the current playback time like this:

- (NSTimeInterval)currentPlaybackTime {
  CMTime time = self.player.currentTime;
  if (CMTIME_IS_VALID(time)) {
    return time.value / time.timescale;
  }
  return 0;
}

这篇关于iOS 7使用AVPlayer在锁定屏幕上回放歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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