Try this to get the path to the track file at the moment:
public Cursor query(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, int limit) { try { ContentResolver resolver = context.getContentResolver(); if (resolver == null) return null; if (limit > 0) uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build(); return resolver.query(uri, projection, selection, selectionArgs, sortOrder); } catch (UnsupportedOperationException ex) { return null; } } private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String path = intent.getStringExtra("track").replaceAll("'","''"); Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media.DATA }, MediaStore.Audio.Media.TITLE + "='" + path + "'", null, null, 0); try { if (c == null || c.getCount() == 0) return; int size = c.getCount(); if (size != 1) return; c.moveToNext(); // Here the song path String songPath = c.getString(0); Log.d("ROAST_APP", "" + songPath); } finally { if (c != null) c.close(); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_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); }
sources:
Track current music information
Needletagger
source share