App with AVPlayer plays mp4 interrupt iPod music after launched

后端 未结 2 1892
南方客
南方客 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.

提交回复
热议问题