iOS:在后台更新媒体信息 [英] iOS: Updating Media Information in the Background

查看:97
本文介绍了iOS:在后台更新媒体信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用MPNowPlayingInfoCenter为我的应用程序显示正在播放的歌曲,但我希望将HTTP Live Streaming合并到我的应用程序中,该应用程序将在后台发生任意数量的不同曲目。

I'm currently using MPNowPlayingInfoCenter for my app to show which song is playing, but I am looking to incorporate HTTP Live Streaming into my application, which will have any number of different tracks occurring in the background.

有没有办法在应用程序在后台设置nowPlayingInfo(在一定时间后调用一个函数?),即使应用程序在技术上实际上并不在后台运行?

Is there a way to set the nowPlayingInfo while the application is in the background (Call a function after a certain amount of time?), even though applications technically don't actually run in the background?

或者有没有办法在我的服务器上使用简单的调用来设置正在播放的信息,这将返回正确的信息 - 使用返回字符串的API调用或图片?

Or is there a way to set the now playing information using a simple call on my server that will return the proper information - Using an API call that returns a string or image?

我知道这是可能的,因为Songza已经做到了,但也许他们已经获得使用Apple的某些私人方法的许可(如果那也是一件事你可以这样做。

I know that it is possible, since Songza has already done it, but maybe they have received permission to use certain private methods from Apple (if thats even a thing you can do).

推荐答案

如果你正在使用 AVPlayer 课程和您的应用程序的主要目的是播放音乐,然后你就可以在后台运行它,从而在曲目改变时更新 nowPlayingInfo

If you're using the AVPlayer class and the primary purpose of your app is to play music, then you'll be able to run it in the background and thus update the nowPlayingInfo when the track is changed.

只是一个简单的例子:

- (void)viewDidLoad {
    [super viewDidLoad]

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        [self becomeFirstResponder];
        //These two steps are important if you want the user to be able to change tracks with remote controls (you'll have to handle the remote control events yourself).
    }
    self.yourPlayer = [[AVPlayer alloc] init];
}

取消注册 dealloc中的远程控制事件方法:

[[UIApplication sharedApplication] endReceivingRemoteControlEvents]

info.plist 中的所需背景模式更改为应用播放音频

这篇关于iOS:在后台更新媒体信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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