App with AVPlayer plays mp4 interrupt iPod music after launched

后端 未结 2 1863
南方客
南方客 2021-01-14 15:06

My App plays mp4 using AVPlayer, when my application finish launching, it interrupt the iPod music, although I have set the audio session to allow mix with others in

<
相关标签:
2条回答
  • 2021-01-14 15:51

    Finally, I figure out what's wrong.

    AudioSessionInitialize(NULL, NULL, NULL, NULL);  
    UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
    UInt32 allowMixWithOthers = true;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixWithOthers), &allowMixWithOthers);
    AudioSessionSetActive(true);
    

    AudioSessionSetActive must be called after AudioSessionSetProperty, it works fine now.

    0 讨论(0)
  • 2021-01-14 15:57

    In iOS 6/7 you can use AVAudioSession because AudioSessionSetProperty is deprecated.

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
    
    0 讨论(0)
提交回复
热议问题