How to enable iPod controls in the background to control non-iPod music in iOS 4?

前端 未结 3 594
清歌不尽
清歌不尽 2020-11-29 01:32

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

相关标签:
3条回答
  • 2020-11-29 02:06

    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 !

    0 讨论(0)
  • 2020-11-29 02:15

    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.

    0 讨论(0)
  • 2020-11-29 02:28

    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 讨论(0)
提交回复
热议问题