Read Status of Default Mediaplayer - android

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.

Related

Cast icon when changing volume via HW buttons

I am developing an application which supports GoogleCast. I am using a CastCompanionLibrary and everything works fine, but there is one little problem there in my application.
I need to change the layout, which appears in case that user changes the volume via HW buttons. In my application, there the layout looks like this:
There is a Cast icon in this layout, but it is white and visibility of them is very bad. For example, in YouTube application, there the same layout looks like this:
So, my question is simple: how can I change the layout, or how can I change the Cast icon in layout? I do not see it in CastCompanionLibrary.
Thanks for any advice.
As far as I know, the UI that you see there when you change the volume is provided by the system through MediaSession or RemoteControlClient, etc and not the application itself. As a result, I am not aware of any way to change that. The UI that you see in YT is a custom UI, and handling of the volume is done through app; in fact if you send the YT app to background and change the volume, you see a different UI so they seem to have decided to capture hardware volume themselves and provide their own custom UI. This is doable as long as your app is in front; as soon as it loses focus (for example when it goes to background), your app doesn't receive the volume key events and your app cannot do much (that is what happens to YT as well). Try Google Play Music and see how their UI looks like when you change volume while casting.
In order to achieve this, the player service must maintain an "active" MediaSessionCompat. The service should proactively sync media player's playback state with the MediaSessionCompat. In addition to this, service must call MediaRouter#setMediaSessionCompat() with the media session on its initialization.
If all of these conditions are met, then whilst casting, the service can call MediaSessionCompat#setPlaybackToRemote(VolumeProviderCompat). Then whenever the player is in "playing" state, volume events will be delivered to MediaSession which calls the VolumeProviderCompat. To switch back to regular media controls, i.e. on cast session end, the service can call MediaSessionCompat#setPlaybackToLocal(AudioManager.STREAM_*).
Sample implementation - Android MediaRouter Volume events

Stop ringtone and audio in Android when listening audio

I am building an Android app for webradio.
I am using vitamio player that extends the functions of the standard MediaPlayer. This problem could also be happening in the standard Media Player as well.
If I'm listening radio and I receive a call, ringtone starts, but the radio doesn't stop!!!
How can I stop it ?
Which event?
Otherwise, I think what you are looking for if you are a developer of the said app is provided at this link. It provides an example of hooks that monitor phone state. On the ringing or call active states you can set your app to a paused or silent state.

Is detecting Video Playing Events possible in android?

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.

Calling setVolumeControlStream from a Service

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/

How to launch android application when volume key is pressed android

i want to launch my application when the volume turned to very low..
Edit:
Or my application should run in background and it should listen to the volume changes.. I think it sounds good...
Is it possible to do that?
Use registerMediaButtonEventReceiver with a BroadcastReceiver that handles ACTION_MEDIA_BUTTON.
This thread explains it:
Volume change listener?

Categories

Resources