开发者

How can I replace iPod with my app icon while my app is playing audio in background?

I (and you) know how to play audio in background开发者_如何学运维.

But my question is like that, some music play apps replace iPod icon which is shown on the first background app page with their icon while they are playing audio in background.

How can I do that?


We can do it using AudioSession like the following code.

AudioSessionInitialize (
                         NULL,    // 'NULL' to use the default (main) run loop
                         NULL,    // 'NULL' to use the default run loop mode
                         NULL,    //  a reference to your interruption callback
                         NULL     //  data to pass to your interruption listener callback
                              );

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory );
AudioSessionSetActive(true);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜