How to connect the audio to bluetooth when playing using AVPlayer

后端 未结 3 1629
感动是毒
感动是毒 2020-12-15 21:57

I am playing the audio from an url using AVPlayer, but when the iPhone is connected to a Bluetooth device it is not playing via Bluetooth, how to play via Bluetooth if it is

3条回答
  •  甜味超标
    2020-12-15 22:03

    You need to set a category and options on the AVAudioSession.

    Try this when the app starts:

    //configure audio session
    NSError *setCategoryError = nil;
    BOOL setCategorySuccess = [[AVAudioSession sharedInstance]
                               setCategory:AVAudioSessionCategoryPlayback
                               withOptions:AVAudioSessionCategoryOptionAllowBluetooth
                               error:&setCategoryError];
    
    if (setCategorySuccess) {
        NSLog(@"Audio Session options set.");
    } else {
        NSLog(@"WARNING: Could not set audio session options.");
    }
    

提交回复
热议问题