How to pause and play android Native Music Player - android

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);

Related

Programmatically check which Music player is playing now

Is there a way we can check programmatically Which Music player is playing right now?
like Google Play, Samsung default Music Player, any 3rd party music player
Actually, we need to programmatically handle play/pause of music player. Google Play and Samsung Music works differently with code :
// Google Play do not play pause with this code
// it is using different package name i guess
CmdStop = "togglepause";
i = new Intent("com.android.music.musicservicecommand.togglepause");
i.putExtra(CmdName, CmdStop);
context.sendBroadcast(i);
Any help is appriciated
Thank you
you don't need a broadcast receiver for this - AudioManager is your friend:
AudioManager.isMusicActive() does the job you want, have a closer look here for details: AudioManager
AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
if(manager.isMusicActive())
{
// do something - or do it not
}
stackoverflow answer

Android: Launch music player service from application

I know that it is possible to launch the music player using an intent using either of the follow:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
or
Intent intent = new Intent(MediaStore.CATEGORY_APP_MUSIC);
startActivity(intent);
However is it possible to start the default music player as a SERVICE rather than an activity? Moreover, is it possible to send actions to that service once it has been created?
However is it possible to start the default music player as a SERVICE rather than an activity?
No, in part because there is no requirement for the user's chosen music player to even have a service. Moreover, the ACTION_VIEW Intent action is only generally supported by activities.
Moreover, is it possible to send actions to that service once it has been created?
Not generally.
There thousands of "music player" apps for Android, any of which can be the "default" for a given user and device. You are welcome to ask each and every one of them if they offer some sort of command-based interaction with some sort of music-playing Service to allow third-party apps to control their player. Some might. Most won't.

Controlling android music player by my own application

I want to write some application to control android music player :)
For example when i shake phone -> player should change music next one. Is it possible without rooting my phone?
I think it is possible, here is a snippet for a performing playback through Intent.
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
or
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Source: Android launching music player using intent
You have to check if there are more Intents you can use by googleing (loading a playlist, etc.).
To control any 3rd party application it first have to be willing to let you to. It is usually done by exposing public API of any sort, so other app would know how to do that. If music player of your choice offers that, then "yes" is the answer. If it does not, then usually it means "no", and rooting is not necessarily a magical solution either. If there's no API or any other communication channel exposed (even non publicly) then achieving your goal would be tricky.

How to intercept broadcast mediaplayer event in 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!

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