Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track info of currently playing music

Tags:

android

I am implementing an application related to getting current music track information.

I am using the following code to get that:

public class CurrentMusicTrackInfoActivity extends Activity {      public static final String SERVICECMD = "com.android.music.musicservicecommand";      @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          IntentFilter iF = new IntentFilter();         iF.addAction("com.android.music.metachanged");         iF.addAction("com.android.music.playstatechanged");         iF.addAction("com.android.music.playbackcomplete");         iF.addAction("com.android.music.queuechanged");          registerReceiver(mReceiver, iF);     }      private BroadcastReceiver mReceiver = new BroadcastReceiver() {          @Override         public void onReceive(Context context, Intent intent) {             String action = intent.getAction();             String cmd = intent.getStringExtra("command");             Log.v("tag ", action + " / " + cmd);             String artist = intent.getStringExtra("artist");             String album = intent.getStringExtra("album");             String track = intent.getStringExtra("track");             Log.v("tag", artist + ":" + album + ":" + track);             Toast.makeText(CurrentMusicTrackInfoActivity.this, track, Toast.LENGTH_SHORT).show();         }     };  } 

It is working fine for some mobiles only. I want to implement code to get current music track info in all Android devices (e.g. HTC and Samsung devices).

Is there any way of doing this?

like image 711
kiran Avatar asked May 09 '12 05:05

kiran


People also ask

What song is currently playing?

To identify songs, open Control Center, then tap the Shazam button . Shazam can identify songs playing on your device even when you're using headphones. To find songs you've identified, touch and hold the Shazam button in Control Center to open your History View.

What is the song playing on my screen?

Shazam, the Apple-owned app that helps users identify songs playing around them, can now recognize songs you're listening to through your headphones when using an Android phone or tablet.

How do I find out what song is playing on my phone?

On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.


2 Answers

Check this this is what am used in my app working well

    iF.addAction("com.android.music.metachanged");      iF.addAction("com.htc.music.metachanged");      iF.addAction("fm.last.android.metachanged");     iF.addAction("com.sec.android.app.music.metachanged");     iF.addAction("com.nullsoft.winamp.metachanged");     iF.addAction("com.amazon.mp3.metachanged");          iF.addAction("com.miui.player.metachanged");             iF.addAction("com.real.IMP.metachanged");     iF.addAction("com.sonyericsson.music.metachanged");     iF.addAction("com.rdio.android.metachanged");     iF.addAction("com.samsung.sec.android.MusicPlayer.metachanged");     iF.addAction("com.andrew.apollo.metachanged"); 
like image 97
hderanga Avatar answered Oct 09 '22 03:10

hderanga


This might help. I use this to get metadata on audio files in one of my apps:

String scheme = mAudioUri.getScheme(); String title = ""; String artist = ""; if(scheme.equals("content")) {     String[] proj = {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST};     Cursor cursor = this.getContentResolver().query(mAudioUri, proj, null, null, null);     if(cursor != null && cursor.getCount() > 0) {         cursor.moveToFirst();         if(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE) != -1) {               title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));             artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));         }     } } 

There are lots of columns in the MediaStore.Audio.Media class which you can use to find what you're looking for I think.

like image 40
JMRboosties Avatar answered Oct 09 '22 03:10

JMRboosties