gpt4 book ai didi

iOS 7 使用 AVPlayer 在锁定屏幕上倒回歌曲

转载 作者:可可西里 更新时间:2023-11-01 03:27:24 25 4
gpt4 key购买 nike

我还没有找到如何从锁定屏幕 iOS 7 倒回歌曲的方法。音量 slider 可用,所有按钮都可以正常工作,但上部 slider 不可用!

AVPlayer 是我正在使用的类。

感谢任何帮助!

最佳答案

您需要在“正在播放的信息”中进行设置。

每当项目(轨道)发生变化时,做类似的事情

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;

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

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;

可以这样获取当前播放时间:

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

关于iOS 7 使用 AVPlayer 在锁定屏幕上倒回歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18733040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com