如何获取当前播放的音乐详细信息?

时间:2018-11-07 12:35:34

标签: android android-mediaplayer

我引用了此link,但我无法获取曲目详细信息...如何在android中获取当前的播放曲目详细信息?有什么方法可以获取当前的音乐信息?

我使用了此代码,但无法获取跟踪信息:

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

}

0 个答案:

没有答案