ios - 如何从锁定屏幕控制 AVPlayer 的播放和暂停。以及如何在锁定屏幕上设置应用程序图像

标签 ios ios7

<分区>

我有一个在线音频播放器应用程序。我希望用户即使在锁定屏幕上也能控制应用程序的播放和暂停。默认情况下已显示按钮。 The code for my app is here.

现在如何启用按钮来控制我的播放器。以及如何在应用程序屏幕锁定时显示我的应用程序的图像。这是示例图片

enter image description here

如果可能,请帮忙。 提前致谢。

最佳答案

iOS 5 以上,MPNowPlayingInfoCenter支持在锁定屏幕和远程播放控件中设置轨道标题和专辑封面图像。
要检查 MPNowPlayingInfoCenter 是否可用,试试这个:-

if ([MPNowPlayingInfoCenter class])  {
   UIImage *albumArtImg = [UIImage imageNamed:@"abc.png"];
   albumArt = [[MPMediaItemArtwork alloc] initWithImage:albumArtImg];

    NSDictionary *dictCurrentlyPlaying = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Temporary", [NSNumber numberWithInt:22], albumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle, MPMediaItemPropertyPlaybackDuration, MPMediaItemPropertyArtwork, nil]];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = dictCurrentlyPlaying;
}

更新:-
请查看这些:-
1。 http://jaysonlane.net/tech-blog/2012/04/lock-screen-now-playing-with-mpnowplayinginfocenter/
2. How to set the title when playing music in background on iPhone?

关于ios - 如何从锁定屏幕控制 AVPlayer 的播放和暂停。以及如何在锁定屏幕上设置应用程序图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21154765/

相关文章:

ios - 如何检查用户的设备是否支持和授权使用iBeacon并且蓝牙已打开?

ios - 如何加载从 iMessage 收到的图像? [IOS 7]

ios - 在 Swift 的 UITableView 中搜索时禁用 scrollViewDidScroll 方法

ios - 如何以编程方式重启未越狱的 iOS 设备?

ios - iOS相机的图像旋转功能已加入AS3

ios - 将 UIImage 圆角化但使圆的外部透明

cocoa - 新的 "iOS data protection APIs"是什么?

ios - 如何使用 NSFileManager 保护或加密视频文件?

ios - 在 iOS 7 中禁用打印屏幕

iOS 7 状态栏在 iPhone 应用程序中恢复为 iOS 6 默认样式?