如何在iOS 4中启用后台iPod控件来控制非iPod音乐?

发布于 2024-09-09 04:09:54 字数 777 浏览 2 评论 0 原文

我想要完成的任务的一个很好的例子是在最新版本的 Spotify iPhone 应用程序中实现的(Pandora 似乎具有相同的功能)。

当 Spotify 在后台时,双击会打开“多任务坞”,其中 iPod 控件(播放/暂停、前进等)允许控制 Spotify 的音乐播放(不是 iPod 应用程序)。此外,当 iphone/ipod touch 锁定时,双击会显示类似的播放控件。

如果您不明白我的意思,这里有一篇带有屏幕截图的文章: http://www. wired.com/gadgetlab/2010/07/spotify-updated-for-ios4-ready-to-replace-ipod/

在我当前的应用程序中,音乐从服务器流式传输(使用 Matt Gallagher 的 AudioStreamer)。我设法让音乐在后台播放。现在,我想将播放链接到“多任务坞”/锁定屏幕。

我应该使用[MPMusicPlayerController iPodMusicPlayer]吗?我应该如何继续?

额外问题:如果你能告诉我如何在“多任务坞”中将 iPod 图标更改为我的应用程序图标(Spotify 也采用了该技巧...),那应该是惊人的。

任何帮助表示赞赏,谢谢。

A good example of what I'm trying to accomplish is implemented in the latest version of the Spotify iPhone application for (Pandora seems to have the same feature) .

When Spotify is in the background, double tapping opens the "multi-task dock", where the ipod controls (play/pause, forward etc) allow to control the music playback of Spotify (not the ipod application). Also, when the iphone/ipod touch is locked, double tapping displays similar playback controls.

If you don't know what I mean, here's an article that has screenshots :
http://www.wired.com/gadgetlab/2010/07/spotify-updated-for-ios4-ready-to-replace-ipod/

In my current application, music is streamed from a server (using Matt Gallagher's AudioStreamer). I've managed to keep the music playing in the background. Now, I'd like to link my playback to the "multi-task dock"/lock screen.

Should I be using [MPMusicPlayerController iPodMusicPlayer] ? How should I proceed ?

Bonus question : if you can tell me how to change the ipod icon to my application icon in the "multi-task dock" (Spotify pulled that trick as well...), that whould be AWESOME.

Any help appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

关于从前 2024-09-16 04:09:54

问题解决了。

简而言之,要启用远程控制事件,1)使用:

- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent

和 2) 把这是你的视图控制器:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
    return YES;
}

我必须感谢 Grant。他分叉了 Matt Gallagher 的 AudioStreamer,实现了 ios4 的所有改进(背景音频和远程控制工作)。您可以在 github 上找到他的源代码以及工作示例:http://github.com/DigitalDJ/AudioStreamer

关于图标:一旦您使用beginReceivingRemoteControlEvents,图标会自动切换到您的应用程序图标。杰出的 !

Problem is solved.

In short, to enable remote control event, 1) use :

- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent

and 2) put this is your view controller :

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
    return YES;
}

I have to give credit to Grant. He has forked Matt Gallagher's AudioStreamer enabling all the ios4 improvements (background audio, and remote controls working). You can find his sources along with a working sample on github : http://github.com/DigitalDJ/AudioStreamer

Regarding the icon : once you use beginReceivingRemoteControlEvents, the icon automatically switches to your app icon. Brilliant !

叶落知秋 2024-09-16 04:09:54

这是文档:

http://developer. apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html

但请注意,只有当您的应用程序中有活动的音频会话时,它才会起作用。

我将其与 AVAudioSessionAVAudioSessionCategoryPlayback 类别和 AVAudioPlayer 一起使用,并且“远程控制”仅在我有 AVAudioSession 激活并创建了 AVAudioPlayer 对象。

Here's the documentation:

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html

Notice however, that it'll work only when you have active audio session in your application.

I'm using it with AVAudioSession with AVAudioSessionCategoryPlayback category and AVAudioPlayer and "remote controls" work only when I have AVAudioSession active and AVAudioPlayer object created.

稍尽春風 2024-09-16 04:09:54

如果您使用新的后台音频 api,您的应用程序的控件将会发生变化。可以找到信息此处。特别是有关背景音频的部分。

The controls will change for your application if you are using the new background audio api's. Information can be found here. Specifically the sections about background audio.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文