How can I make the Device sound a beep when socket connection has been established. In other words, how to set a notification tone when an event occurs in Android sdk?
If you are the one opening the socket, use MediaPlayer or SoundPool or ToneGenerator or AudioTrack or something to play back a beep.
If you are trying to arrange for beeps when other applications open sockets, that is not possible without firmware modifications.
Related
I've implemented this solution to get AudioRecord working with bluetooth earpieces.
This works well until no sound is transferred to and from the bluetooth device, however if there is no sound output, and no microphone output for a few seconds, the micro
phone stops listening.
I tried to listen almost all intent actions, but I have nothing when the microphone stops.
How could I get a message on this kind of timeout, or how could I keep this connection on ?
I am developing an app to control a speaker. I want the app to be able to playback music, do karaoke (play music and mic at same time), and provide a basic EQ to the user. My problem so far has been playing music through Bluetooth at all. My app: -discovers all Bluetooth speakers nearby -puts them in a list -pairs with clicked device and sends user to Bluetooth settings to connect to it
Now my problem is successfully playing music over the bluetooth speakers. I use a AudioManager and set it to play over SCO:
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);
And then try to play a music file, but this only plays over the devices speakers and not the connected Bluetooth speakers.
So my question is what am i missing? I read a bit about a A2DP sink but it seems to not be available in recent versions. Any suggestions? Thanks in advance.
TDLR: How do I playback music to paired Bluetooth speakers?
The startBluetoothSco() method returns before SCO is setup. You need to register a BroadcastReceiver for ACTION_SCO_AUDIO_STATE_UPDATED before calling the above method.
http://developer.android.com/reference/android/media/AudioManager.html#startBluetoothSco%28%29
it's a sticky intent to so you can always check the status before calling the setBluetoothScoOn(true).
I have an android client app from which i record audio from mic and send it to an socket. Now I want to build another app that will create a ServerSocket and listen to the audio from the mic and play it.
Will anybody guide me on that?
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.
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.