I'm building a music player and it should be paused when a voice/video chat is taking place. I know I could use an audio focus listener but is there any other way to achieve this?
I've googled a lot but still can't find anything related.
Is there any broadcast event like VOICE/VIDEO_CHAT_START(END) or AUDIO_RECORD_START(END)? Or something like TelephonyManager I could add a listener to?
This question is different from this one. I want to detect events for audio recording instead of playing to be exactly.
Related
I want to add custom actions when a Bluetooth headset / earpiece buttons are pressed.
Apparently for this I need to listen to Media Events using mediaSession.setCallback(callback)function. But for that I need to also play some Media as well, right? I dont want to play any sound. Can I ask MediaSession to play nothing and just receive the media events?
My goal is to override the default Bluetooth headset actions. How can I achieve that? Or any listener that can listen to all Bluetooth buttons.
I think you might be looking for BluetoothHeadset.
There you can register for events as well as vendor specific events which I'm sure you can use along with your logcat to find out exactly what events are being issued when certain buttons are being clicked.
Here is an example as well that might help getting you started: https://github.com/devunwired/accessory-samples/blob/master/BluetoothAudioProxy/src/com/example/BluetoothAudioProxy/HeadsetService.java
Anyone know if there's a way to control the buttons on both regular and bluetooth headsets?
I want to use the regular answer button to play/pause the current media that I'm playing through the Ti.Media.AudioPlayer.
I've tried to get the Ti.Android.ACTION_MEDIA_BUTTON to work on Android but without any success the BroadCastListener isn't firing when i press button on either a regular headset or a bluetooth headset.
For iOS I have no clue if this is possible to solve.
On iOS if you set the audioSessionCategory to PLAYBACK and the controls on your headset should interact with the music you're playing.
For Android it looks like you'd need a module to expose a broadcast receiver that would pick up the events as explained here. I couldn't find an existing module that does this already.
I am able to launch the Music Player using the layouts etc. NowI am trying to figure out a way, if my UiAutomator test can listen in on the already launched Android Music Player's events- something like the listeners that the Media Player class provides.
This is needed because I want to figure out a few things like when the song ends(figure out when the EOS happens) ,was the seek successful etc..
All help is appreciated.
Thanks!
I'm writing an Android music player, and is stuck on audio focus issue.
It seems like audio focus mainly affects media button receiving, but after reading the document I have no idea about when to gain and give up focus.
My music app will run in background, and need to detect play/pause button every time. That is, even when my app is not running, a user should be able to press headset's play button and start music.
It seems I should never give up audio focus, so why should I implement it?
Does anyone know practically how audio focus should be used? Thank you!
It seems like audio focus mainly affects media button receiving, but
after reading the document I have no idea about when to gain and give
up focus.
They both are separate functionalities, and thus have separate listeners. You may have audio focus taken away from you but you may still choose to respond to play pause hardware keys
That is, even when my app is not running, a user should be able to
press headset's play button and start music.
I am assuming that you meant by the above line is that you are still playing music but not showing an activity. To keep listening to hardware button press, dont unregister your media button receiver(dont call audioManager.unregisterMediaButtonEventReceiver(receiver) yet).
It seems I should never give up audio focus, so why should I implement
it?
you dont give up the focus , it gets taken from you. To handle that gracefully you have AudioFocus listener. For ex, consider an incoming phone call. Would you still like to continue playing your music?
I want to detect events like "Video is playing" "Video has been paused" "Video Play has stopped".
I do not want to write my own player. I just need to log the events of the default video player that has been called. Is there any broadcast event that I can register to for the default player in android?
It is not possible unless you have a custom rom.
I'm not sure exactly what you need, but the answer is "maybe".
Specifically:
It is possible to detect if an activity was paused? (thread problem)
Q: It is possible to detect if an activity was paused?
A: Yes see here. Just override the onPause in your activity
It might be as simple as that.
Alternatively, look at the Media Player state diagram and available methods here:
http://developer.android.com/reference/android/media/MediaPlayer.html
There is a possibility to bnd to Android's music player service. It is described here. You can obtain the current track and stuff, but I'm not sure whether you can register to events. Let us know if you find out more.