【问题标题】:How to set an title of the currently playing audio in iPhone lock screen?如何在 iPhone 锁屏中设置当前播放音频的标题?
【发布时间】:2012-01-13 07:24:04
【问题描述】:

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

我还看到 TuneIn radio 如何通过显示当前正在播放的广播电台的名称来做到这一点。

你是怎么做到的?

【问题讨论】:

    标签: ios core-audio mpnowplayinginfocenter


    【解决方案1】:

    阅读文档: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;
    }
    

    【讨论】:

    • 不,没有,因为这个 api 只在 iOS 5 中可用。在 iOS 之前,没有 API 可以实现这个。
    • 它适用于 ios5,但在旧版本(例如 ios4)上会崩溃。 ios4有什么替代品吗?如果是,请帮助我。提前致谢。
    • 上面实现的代码在 iOS4 上不会崩溃,但在 iOS 上不能工作,因为 iOS4 不支持它。 iOS4锁屏无法获取歌曲信息。
    • 在 iOS4 中出现以下错误! “adyld:未找到符号:_OBJC_CLASS_$_MPNowPlayingInfoCenter”。我怎样才能消除这个崩溃。
    • 你是否用if语句实现了上面的ti代码来检查类是否可用?
    猜你喜欢
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多