How to intercept broadcast mediaplayer event in Android? - android

I need to play and stop my application through headset buttons... I found something about com.android.music.musicservicecommand , if I send a broadcast Intent doing
Intent intentStop;
intentStop = new Intent("com.android.music.musicservicecommand");
intentStop.putExtra("command", "stop");
SomafmApp.mycontext.sendBroadcast(intentStop);
media player stops. Do you have a sample code to intercept these events in my application? I found very little around internet, I start thinking that this method is deprecated, but maybe I'm wrong...
Thanks in advance

I think you'll find what you're looking for here: http://android.amberfog.com/?p=415. It provides sample code for controlling the MediaPlayer with headphone controls.

Found this http://android-developers.blogspot.com/2010/06/allowing-applications-to-play-nicer.html . It works great, and shows how to mantain a backward compatibility. Enjoy!

Related

How to pause and play android Native Music Player

I'll Play some notification alerts from my app.. At the time system should pause the music running in the device. For that i'm sending Broadcast event to pause the media.
Intent audioIntent = new Intent("com.android.music.musicservicecommand.pause");
MYActivity.sendBroadcast(audioIntent);
This code is only working and pausing the Google Play Music and Default Music Player.. But this code is not working for Poweramp and VLC.. Kindly post your solution..
You really should supply the code you have written for the broadcast, this is a very hard question to answer without your code... Something like this is what most people use:
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
YourApplicationClass.this.sendBroadcast(i);

Playing Audio During call so that other person on call can hear it

i am developing one application which
needs to play an audio song to callee when call is lifted by callee,
and automatically call has to be disconnected automatically when audio
song playing completed . i tried to find in android API for any
classes or methods to do this, but failed to find... please help me
how to do this..
your answer could be helpful to me...please do reply
Thank you in advance..
AFAIK, it is not possible to play a sound in the ongoing call and also to automatically dosconnect a call. Telephont API doesnt provide any methods to do any od these. So both od these requirement can't be fullfilled in ANdroid.

Programmatic auto attendant on an Android device

Is it possible to create an Android application that automatically attend incoming calls to an Android phone? If so, which APIs may be used to achieve this (a piece of code snippet highly appreciable)?
If the programmatic auto attendant feature not possible, why the Android OS imposes this restriction?
Is iOS behaves as same as Android in this scenario, please explain.
While googling I found something that can be useful. I haven't tried yet still I think this will help have a look at Call Control in Android
You can listen incomming call intent by implementing broadcast receiver Intent.CALL_STATE_CHANGED to listen for incoming call, but answering incomming call automatically seems not feasible.coz android application dont have access to incomming call audio stream.

Send music control keys from my app in android

Is there a simple way to tell the default media player to change track back or forward?
I want the ability to send commands to the system media player (Music) to change track back and forward from within my app.
Is there a simple way? Code examples or descriptive explanation please, I have not developed for Android before.
Update: Is it just the HTC Music that isn't part of the SDK or even the stock one? Either player would be fine if I could manage way to change tracks.
The HTC Lock screen has some method of changing tracks in the music player. Is it possible I could get hold of this and use it?
Baksmali?
I want the ability to send commands to
the system media player (Music) to
change track back and forward from
within my app.
The Music application is not part of the Android SDK, so there are no documented and supported Intents for moving from track to track.
Sorry!
by ACTION_MEDIA_BUTTON using intent ??
http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON
Intent media_intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
media_intent.setPackage(DEFAULTPLAYER);
synchronized (this) {
media_intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keycode));
mContext.sendOrderedBroadcast(media_intent, null);
media_intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, keycode));
mContext.sendOrderedBroadcast(media_intent, null);
}
however DEFAULTPLAYER needs to be assigned...
:S :S :S

Receiving MP3 play actions in a BroadcastReceiver in Android

I am trying to build an Android Service that should get notified when the user starts playing an MP3. I checked LogCat when I start playing a song and saw that the following Intent is logged:
Intent { act=com.android.music.PLAYBACK_VIEWER flg=0x4000000 cmp=com.android.music/.MediaPlaybackActivity }
I couldn't figure out how to write an IntentFilter to let my Service know that this event has occurred and let me know the name of the song that will be played. I searched Android reference but could not find anything on PLAYBACK_VIEWER.
Thanks,
C
I would do neither. First, none of this is part of the SDK and so may change at any point. Second, this will only work for the built-in media player application, not any third-party or OEM-supplied media players, and I expect more people to gravitate to those.

Categories

Resources