iOS 4: Remote controls for background audio

后端 未结 7 1375

I\'m currently attempting to set up background audio for an app I\'m developing for iOS 4. The app doesn\'t have a dedicated music player viewController, howeve

7条回答
  •  温柔的废话
    2020-12-07 18:48

    I struggled with this one for a while and none of the answers above worked. The bug in my code, and I hope that it will help someone reading this, was that I had the AudioSession set to mix with others. You want to be the foreground audio player to get Remote Control events. Check to see if you have INCORRECT code like this:

        [[AVAudioSession sharedInstance] setDelegate: self];
        [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
        UInt32 doSetProperty = 0;
        AudioSessionSetProperty (
                                 kAudioSessionProperty_OverrideCategoryMixWithOthers,
                                 sizeof (doSetProperty),
                                 &doSetProperty
                                 );
        NSError *activationError = nil;
        [[AVAudioSession sharedInstance] setActive: YES error: &activationError];       
    

    And remove the AudioSessionSetProperty, or change doSetProperty to 1.

提交回复
热议问题