我想要完成的任务的一个很好的例子是在最新版本的 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.
发布评论
评论(3)
问题解决了。
简而言之,要启用远程控制事件,1)使用:
- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent
和 2) 把这是你的视图控制器:
我必须感谢 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 :
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 !这是文档:
http://developer. apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/RemoteControl/RemoteControl.html
但请注意,只有当您的应用程序中有活动的音频会话时,它才会起作用。
我将其与
AVAudioSession
和AVAudioSessionCategoryPlayback
类别和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
withAVAudioSessionCategoryPlayback
category andAVAudioPlayer
and "remote controls" work only when I haveAVAudioSession
active andAVAudioPlayer
object created.如果您使用新的后台音频 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.