【问题标题】:Change lock screen background audio controls text?更改锁屏背景音频控件文本?
【发布时间】:2011-09-29 20:17:07
【问题描述】:

我有一个使用 AVAudioSession 流式传输背景音频的 iOS 应用。它工作正常,但我很好奇,有没有办法更改锁屏音频控件上的文本?现在它只是显示我的应用程序的名称,但我想将其更改为轨道的名称。

此外,多任务栏在控件下方没有文本 - 有没有办法像 iPod 应用程序那样在其中添加曲目名称?

【问题讨论】:

  • 有人知道如何使用网络音频吗?

标签: ios objective-c swift avaudiosession mpnowplayinginfocenter


【解决方案1】:

iOS 5 现在支持在锁定屏幕和远程播放控件(双击主页按钮并向右滑动时获得的控件)中设置曲目标题以及专辑封面图像。看看 MPNowPlayingInfoCenter 班级。当然,为了最大限度地提高兼容性,您需要测试MPNowPlayingInfoCenter 是否可用,方法如下:

if ([MPNowPlayingInfoCenter class])  {
   /* we're on iOS 5, so set up the now playing center */
   UIImage *albumArtImage = [UIImage imageNamed:@"HitchHikersGuide"];
   albumArt = [[MPMediaItemArtwork alloc] initWithImage:albumArtImage];

    NSDictionary *currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Life, the Universe and Everything", [NSNumber numberWithInt:42], albumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle, MPMediaItemPropertyPlaybackDuration, MPMediaItemPropertyArtwork, nil]];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
}

【讨论】:

  • 你想在这里使用 classFromString 因为这会导致低级操作系统崩溃
  • 不。在 iOS 4.x 中没有正式的设置方法。我什至认为没有非官方的方式可以做到这一点。
【解决方案2】:

这里很快! (无需再检查 iOS 5 及更高版本)

let albumArt = MPMediaItemArtwork(image: UIImage(named:"HitchHikersGuide"))
let albumDict = [MPMediaItemPropertyTitle: "Life, the Universe and Everything", MPMediaItemPropertyPlaybackDuration: 42, MPMediaItemPropertyArtwork: albumArt]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = albumDict

【讨论】:

    猜你喜欢
    • 2013-08-15
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多