1

I am currently doing one music app. in that i need to play buffering audio song in blue tooth headset. i searched for code past 1 day. but i can't. please give solution how to add this in my music app.

One more thing i need to play that audio in bluetooth headset while iphone is in backeground mode and screen lock mode.

   AVAudioSession* audioSession = [AVAudioSession sharedInstance];
//[audioSession setDelegate:self];
NSError *error;
[audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&error];
[audioSession setActive: YES error: nil];


// check the audio route
UInt32 size = sizeof(CFStringRef);
CFStringRef route;

OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);
// if bluetooth headset connected, should be "HeadsetBT"
// if not connected, will be "ReceiverAndMicrophone"

// now, play a quick sound we put in the bundle (bomb.wav)
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef        soundFileURLRef;
SystemSoundID   soundFileObject;
soundFileURLRef  = CFBundleCopyResourceURL (mainBundle,CFSTR ("sample"),CFSTR ("m4a"),NULL);
AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);
AudioServicesPlaySystemSound (soundFileObject);     // should play into headset

I have added this code in my music app. but this code is for Bundle audio file. but i need buffering audio. if it is not possible please tell is my code is correcte to play local audio file through blue tooth headset.?

raja
  • 39
  • 9
  • Please post anything that you've tried, even if it's a non-buffering thing that plays to Bluetooth, or a buffering thing that doesn't play to Bluetooth. Post whatever you've got. – GHC Apr 20 '15 at 06:41
  • BTW You can find sample files on http://techslides.com/sample-files-for-development – WINSergey Feb 23 '17 at 16:15
  • @raja have you added permission about play audio background mode in info.plist ? – Yogendra Girase Jul 05 '17 at 11:29

1 Answers1

0

From what i read in the documentation , setting the category for the audio session should be

AVAudioSessionCategoryPlayAndRecord

or

AVAudioSessionCategoryRecord

if setting the option to

 AVAudioSessionCategoryOptionAllowBluetooth

so you should change that, another thing when i look at the enum: AVAudioSessionCategoryOptions the option to bluetooth is __TVOS_PROHIBITED but i don't know the alternative...

Gili Ariel
  • 572
  • 1
  • 6
  • 18