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.
Related
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.
I have an audio recording service in my app which will record the sound continuously. So, it will always occupy the AudioRecord. It means no other app can use audio recorder as it is already occupied by the service. Is there any way to notify that other app is requesting for audio recorder(so that I can release it) and also when the app releases it(so that I can assign it back to the service)?
Maybe a possible way is to create a BroadcastReceiver which receives an event from the app which is requesting the control over the mic source. The onReceive() method should interact with the service and release the resource. When the other app is finishing it can revert the process to start the service again. If you can't get control over the behavior of the requesting app I think there's a slightly different problem. Anyway:
The problem is all about knowing when the resource is being requested, this can be done through AudioManager intent types.
Be sure to check Managing audio focus which talks about audio focus loss in TRANSIENT way!
As #Rekire mentioned, there is possibly no way to achieve this. Also, AudioManager provide no such broadcasts, so it is not possible for different apps. Maybe rooting the device is the only option.
This can be done with AudioManager.OnAudioFocusChangeListener callback. Just stop recording on AUDIOFOCUS_LOSS_TRANSIENT event and start again on AUDIOFOCUS_GAIN event.
This solution works well for Google Voice Search (Google Search widget, Google Chrome, etc).
But unfortunately it works poorly for other ordinary applications (for example HTC M7 Voice Recorder app is not able to start recording on first click on "Record" button, second click do the trick - it seems app should be ready to retry recording on failure several times).
Currently there is no MedaiStatus.PLAYER_STATE_LOADING state to tell if the video is being loaded to the chromecast device.
Is there a way i can ask the GoogleCast device if I am loading data, as apposed to Buffering, Idle, Playing, or Paused?
We don't have such event exposed through the SDK. There is a couple of nice diagrams here that show the flow and events that are captured (see section Media Events). If there is a any reason that you need a certain event (exposed by MediaElement) that are not exposed through the SDK, you should consider doing the following:
Listen to that event on the MediaElement directly and inform your senders accordingly. The receiver SDK does exactly the same thing; it gets all its media events from the media element.
Open a feature request on our SDK tracker. There, you need to explain in detail why you need that feature and basically build a case that shows it is a valuable feature not just for your particular case, but in general.
I'm currently developing a custom SystemUI for Android, so I have no permission Problems.
I want a "Mediaplayer Widget" like on the Lockscreen. I think I can easily control the default Mediaplayer (or any Mediaplayer?) by injecting KeyEvents to the System.
My Problem is: How can I ensure to get updated about songchanges and opening/closing the Mediaplayer?.
Update
I found the Source of the ScreenLock and found the Code for IRemoteControlDisplay but now I dont't know how to use it. I tried to Debug it and it appears, that right after initalization, the onListenerDetached method gets called twice...
Your question seems to be answered already. I just researched and got the following links that might help you.
It is clear that you have to work on running a service to monitor the changes using listeners such as: OnBufferingUpdateListener, OnCompletionListener, OnErrorListener, OnInfoListener, OnPreparedListener.
State change listener for MediaPlayer
Android music player app: how to set a complete listener for media player that is running in a service?
Listen to volume changes:
Is there a listener to listen for changes in the volume in android?
Constantly check for volume change in Android services
Hope this helps.
I need to call setVolumeControlStream from a service that plays some sound via STREAM_SYSTEM.
Obviously in an Activity that is no problem, but how can I do this with a service?
From the looks of it, this isn't possible the way you are trying to do it.
As said in the android reference
The suggested audio stream will be tied to the window of this Activity
Hence with a service that has no activity, there is no window to tie the audio stream to.
However, It looks like you should be able to receive media key events (including volume keys) from a broadcaster as shown here which would allow you to change your service volume without an activity being visible.
I think this library can provide you what you need:
http://code.google.com/p/media-volume-control/