iOS Question Audio Over Bluetooth

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All

I have an application that plays audio files.

I do have one of these bluetooth/fm units that makes it possible to play music over the car audio system, by converting the bluetooth audio to FM:
https://www.amazon.ca/VicTsing-Transmitter-Bluetooth-Flexible-Gooseneck/dp/B0196A4U6O

with B4A, the received audio plays over the car system no problem.

With B4I MediaPlayer it is not ...while playing music is fine.

Below is the code I am using

B4X:
    Dim no As NativeObject = Me
    no.RunMethod("setAudioSession", Null)

    mpRef.Initialize( FileFolder, FileName, "mp")
    mpRef.Looping = False
    mpRef.Play

Any ideas how to make this work?

iCAB
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

Thanks for your reply.
Here is the code I am using

B4X:
#If OBJC
#import <AVFoundation/AVFoundation.h>
- (void) setAudioSession {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error: nil];
}
#end if
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

Thanks for your help.
I had to OR(|) the options to have both working (otherwise the speaker won't work ).

Here is the new code

B4X:
#If OBJC
#import <AVFoundation/AVFoundation.h>
- (void) setAudioSession {
//[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error: nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionDefaultToSpeaker error: nil];
}
#end if

Thanks again for the exceptional support

iCAB
 
Upvote 0
Top