android route specific audio to bluetooth headset - android

i'm trying to write an app that will get audio notifications and will stream them on a bluetooth headset. i want this done while other audio frames are playing through the device's speaker (for instance, there is a song playing on another app).
i only want the audio notification to play on the headset, other audio frames should still come out of the speaker.
right now, it doesn't matter whether the other audio frame will pause while the notification is played on the headset or not.
i've looked and found no example of how to do this.
is it at all possible?
can someone direct me?
with regards,
Tamir.

Related

Play audio over an active phone call, so other end can hear it

A and B are talking on the phone. During the call, A presses a button that pulls audio from a resource and plays it over the phone call to B.
Is this possible using the Android framework? The goal is for the person on the other end of the call to hear the audio.
If it's not possible, is it a hardware limitation or a limit of the Android framework?
I believe that you cannot achieve that, according to the documentation HERE :
Note: You can play back the audio data only to the standard output device.
Currently, that is the mobile device speaker or a Bluetooth headset.
You cannot play sound files in the conversation audio during a call.
According to http://developer.android.com/reference/android/media/AudioManager.html, there are a number of channels though which audio can be played:
STREAM_ALARM The audio stream for alarms
STREAM_DTMF The audio stream for DTMF Tones
STREAM_MUSIC The audio stream for music playback
STREAM_NOTIFICATION The audio stream for notifications
STREAM_RING The audio stream for the phone ring
STREAM_SYSTEM The audio stream for system sounds
STREAM_VOICE_CALL The audio stream for phone calls
These are what the android framework allows for. It would seem to me that two are of potential interest to you: STREAM_DTMF or, more likely, STREAM_VOICE_CALL. I haven't experimented personally, but if I was trying to do this, I would start by trying those two.

Play audio file during ongoing voice call so that caller can hear it

I'm trying to make an answering machine.
When there is an incoming call in my device I'll pick it up and start an audio file enabling speaker so that the microphone can take the speaker voice and the caller can hear it.
The application is working. This is what I implemented. But the problem is when I receive the call and start the audio play, the speaker is set on but the microphone doesn't pick up anything from the speaker though it can pick sounds from other source. Hence caller can't here the audio.
Anyone have an insight of this problem? I mean why won't the microphone pick the voice from the speaker but at the same time pick sounds from other sources?

Bluetooth SCO to single android application, not to entire android system

I am using following code in my application to use bluetooth headset for audio IN and OUT. It is working fine.
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
am.startBluetoothSco();
am.setBluetoothScoOn(true);
But, When I played song using Music Player app, along with my application also running, the song is coming in bluetooth headset. This is because I changed the Audio Manager of android system to Bluetooth SCO.
But my requirement is the audio IN and OUT must work with bluetooth headset to my application only and it should not disturb other apps, Is it possible ?? or not ??
Please provide your valuable suggestions. Any help will be appreciated. Thanks.
When you add a SCO channel you are essentially adding an audio channel. Think of it like a wired handsfree. When you connect the handsfree all audio is routed to it and not just one specific applications's audio. To use the BT headset only for your app, connect the SCO channel when the app starts and disconnect when the app is exited or goes into background.

Playing sound over speakers while playing music through headphones

I have an AudioTrack streaming via headphones. I have to send a SoundPool to built-in speakers only, without interrupting the AudioTrack playing over the headphones. Any hacks gangsters?
Many Android devices use a single output thread in the AudioFlinger / audio HAL for all local playback (earpiece, speaker, wired headset/headphones), making different routing of two tracks simultaneously impossible (which is why on many devices the media streams are forcibly muted if a notification is played and you've got a wired headset attached; because otherwise you'd hear the music in the loudspeaker while the notification is played).
On some devices it might be possible to do what you're looking for if you manage to do a setForceUse(FOR_MEDIA, FORCE_SPEAKER) and use the MUSIC stream type for the stuff you want to play in the loudspeaker, and the VOICE_CALL stream type for the stuff that you want to play in the wired headset.
I'm not sure if there's any way for an application to perform that setForceUse call though. Perhaps you can get at the handleMessage method of the AudioService class through reflection and send it an MSG_SET_FORCE_USE message.. I've never tried it myself so it might fail miserably.
EDIT: I've now tested the setForceUse way of forcing MEDIA streams to the loudspeaker while a wired headset is attached on an actual device, and it does work (though I can't guarantee that it will work across all devices). The implementation was slightly different from what I described above. See my answer to how to turn speaker on/off programatically in android 4.0 for the code I used.

android - notification tone over bluetooth

is there a way to play a tone over bluetooth?
I'm not trying to stream audio or anything fancy, I just want the headset to make a beep sound like when pressing an on screen button or getting a call.
There is no current way to assign the device to play a sound. It will always play to the default output device.
If the Bluetooth headset is the default output device at that time, the MediaPlayer sounds will be heard in it.
Audio and Video
Audio and Video Playback
Media can be played from anywhere:
from a raw resource, from a file from
the system, or from an available
network (URL).
You can play back the audio data only
to the standard output device;
currently, that is the mobile device
speaker or Bluetooth headset. You
cannot play sound files in the
conversation audio.

Categories

Resources