如何在iPhone锁屏中设置当前播放音频的标题? [英] How to set an title of the currently playing audio in iPhone lock screen?

查看:181
本文介绍了如何在iPhone锁屏中设置当前播放音频的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您播放音乐时,音乐标题会显示在锁定屏幕中的时间下方。

When you play a music, the music title is shown below the time in the lock screen.

我还看到了TuneIn无线电如何通过显示名称来实现当前正在播放的广播电台。

I have also seen how TuneIn radio does that by showing the name of the currently playing radio station.

你是怎么做到的?

推荐答案

阅读文档: MPNowPlayingInfoCenter

Read the documentation: MPNowPlayingInfoCenter

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

And here is an example code that will work on iOS 5 and it will not crash on older versions of 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;
}

这篇关于如何在iPhone锁屏中设置当前播放音频的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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