在Android中获取当前歌曲在媒体播放器中播放的详细信息

时间:2012-08-09 19:47:00

标签: android android-intent audio-player android-music-player

我目前正在使用类似于下面的方法来检索信息,但我不确定如何获得该类型。有没有人知道什么字符串额外被称为流派或是否有一个额外的?感谢。

Track info of currently playing music

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



com.sec.android.app.music.player.service.CorePlayerService

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

}

1 个答案:

答案 0 :(得分:2)

事实证明,没有任何类型的额外传递,只有上面的3和id。我能够使用以下代码看到附加内容:

Bundle b = intent.getExtras();
        Set<String> set = b.keySet();
        Iterator it = set.iterator();
        while(it.hasNext()==true){
            Toast.makeText(getApplicationContext(),""+it.next(), Toast.LENGTH_SHORT).show();
        }