ios – 如何在iPhone锁屏幕中设置当前播放音频的标题?

播放音乐时,音乐标题显示在锁定屏幕的时间之下.

我也看到了TuneIn收音机如何通过显示当前播放的广播电台的名字.

你如何做到这一点?

解决方法

阅读文档: MPNowPlayingInfoCenter

这里是一个可以在iOS 5上运行的示例代码,它不会在旧版本的iOS上崩溃.

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

if (playingInfoCenter) {
    MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
    NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                             @"Some artist",MPMediaItemPropertyArtist,@"Some title",MPMediaItemPropertyTitle,@"Some Album",MPMediaItemPropertyAlbumTitle,nil];
    center.NowPlayingInfo = songInfo;
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...