我已经为此搜寻了很多,我发现了很多解决方案,但他们并没有为我工作。最后,我使用了所有现有解决方案的组合,它的工作。 你要添加的所有其他玩家在你的app.Then它将返回当前播放歌曲的标题(它会返回文件名,如果你的歌没有标题)为您:
intent.getStringExtra("track")
最后询问这个特定的歌曲,你可以访问有关这首歌的所有信息,当然这是我path.Let如果它适用于you.This工作对我来说:
public class GetMusic extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.get_music);
IntentFilter iF = new IntentFilter();
iF.addAction("com.android.music.playstatechanged");
iF.addAction("com.htc.music.playstatechanged");
iF.addAction("fm.last.android.playstatechanged");
iF.addAction("com.sec.android.app.music.playstatechanged");
iF.addAction("com.nullsoft.winamp.playstatechanged");
iF.addAction("com.amazon.mp3.playstatechanged");
iF.addAction("com.miui.player.playstatechanged");
iF.addAction("com.real.IMP.playstatechanged");
iF.addAction("com.sonyericsson.music.playstatechanged");
iF.addAction("com.rdio.android.playstatechanged");
iF.addAction("com.samsung.sec.android.MusicPlayer.playstatechanged");
iF.addAction("com.andrew.apollo.playstatechanged");
iF.addAction("gonemad.dashclock.music.playstatechanged");
iF.addAction("com.piratemedia.musicmod.playstatechanged");
iF.addAction("com.tbig.playerpro.playstatechanged");
iF.addAction("org.abrantix.rockon.rockonnggl.playstatechanged");
iF.addAction("com.maxmpz.audioplayer.playstatechanged");
iF.addAction("com.doubleTwist.androidPlayer.playstatechanged");
iF.addAction("com.lge.music.playstatechanged");
registerReceiver(mReceiver, iF);
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Uri mAudioUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.TITLE + " == \"" + intent.getStringExtra("track") + "\"";
String[] STAR = { "*" };
Cursor cursor = getContentResolver().query(mAudioUri,STAR, selection, null, null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
if (cursor.getColumnIndex(MediaStore.Audio.Media.TITLE) != -1) {
String fullpath = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DATA));
Toast.makeText(getApplicationContext(),"song path: " + fullpath,Toast.LENGTH_LONG).show();
}
}
}
};
}
有成千上万的音乐播放应用程序的机器人的。这些大约零点发布“当前播放曲目”信息。 – CommonsWare
那么为什么我会收到有关艺术家,专辑和曲目的信息?这怎么可能 ? – user1959425
嘿@commonsware,是不是应该在Google Play服务客户端库中包含这些内容? (顺便说一下,Google的“Play音乐”应用程序几乎是我国唯一可下载的音乐应用程序 - 潘多拉盒子等仅适用于美国) – Gabor