本文介绍了Android的 - 获取当前播放歌曲的时间和经过时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到目前效力于音乐播放的歌曲的持续时间。
我使用的是code以下,能得到艺术家名称,曲目名称和其他一些细节,但找不到时间和经过时间。是否有任何其他的方式来找到它?

  @覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    IntentFilter的IF =新的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);    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);    iF.addAction(com.android.music.playstatechanged);
    iF.addAction(com.android.music.playbackcomplete);
    iF.addAction(com.android.music.metachanged);
    // HTC音乐
    iF.addAction(com.htc.music.playstatechanged);
    iF.addAction(com.htc.music.playbackcomplete);
    iF.addAction(com.htc.music.metachanged);
    // MIUI播放器
    iF.addAction(com.miui.player.playstatechanged);
    iF.addAction(com.miui.player.playbackcomplete);
    iF.addAction(com.miui.player.metachanged);
    //真实
    iF.addAction(com.real.IMP.playstatechanged);
    iF.addAction(com.real.IMP.playbackcomplete);
    iF.addAction(com.real.IMP.metachanged);
    // SEMC音乐播放器
    iF.addAction(com.sonyericsson.music.playbackcontrol.ACTION_TRACK_STARTED);
    iF.addAction(com.sonyericsson.music.playbackcontrol.ACTION_PAUSED);
    iF.addAction(com.sonyericsson.music.TRACK_COMPLETED);
    iF.addAction(com.sonyericsson.music.metachanged);
    iF.addAction(com.sonyericsson.music.playbackcomplete);
    iF.addAction(com.sonyericsson.music.playstatechanged);
    // RDIO
    iF.addAction(com.rdio.android.metachanged);
    iF.addAction(com.rdio.android.playstatechanged);
    //三星音乐播放器
    iF.addAction(com.samsung.sec.android.MusicPlayer.playstatechanged);
    iF.addAction(com.samsung.sec.android.MusicPlayer.playbackcomplete);
    iF.addAction(com.samsung.sec.android.MusicPlayer.metachanged);
    iF.addAction(com.sec.android.app.music.playstatechanged);
    iF.addAction(com.sec.android.app.music.playbackcomplete);
    iF.addAction(com.sec.android.app.music.metachanged);
    // Winamp的
    iF.addAction(com.nullsoft.winamp.playstatechanged);
    //亚马逊
    iF.addAction(com.amazon.mp3.playstatechanged);
    //狂想曲
    iF.addAction(com.rhapsody.playstatechanged);
    //后级
    iF.addAction(com.maxmpz.audioplayer.playstatechanged);
    //将添加任何....
    // scrobblers检测球员(后级为例)
    //Last.fm
    iF.addAction(fm.last.android.metachanged);
    iF.addAction(fm.last.android.playbackpaused);
    iF.addAction(fm.last.android.playbackcomplete);
    //一个简单的last.fm Scrobbler技术
    iF.addAction(com.adam.aslfms.notify.playstatechanged);
    // Scrobble的Droid
    iF.addAction(net.jjc1138.android.scrobbler.action.MUSIC_STATUS);    registerReceiver(mReceiver,1F);
}私人广播接收器mReceiver =新的广播接收器(){    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        捆绑额外= intent.getExtras();
        Log.v(贝纳,extra.toString());    }
};


解决方案

只为少数players.Please使用您将获得歌曲的持续时间如下intents.But是支持试试吧

 持续时间= intent.getLongExtra(MediaStore.Audio.AudioColumns.DURATION,0);
持续时间= intent.getLongExtra(时间,0);

I'm trying to get the duration of the song that currently playing in the music player.I'm using the code below, and able to get the artist name, track name and a few other details, but can't find the duration and elapsed time. Is there any other way to find it?

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

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

    iF.addAction("com.android.music.playstatechanged");
    iF.addAction("com.android.music.playbackcomplete");
    iF.addAction("com.android.music.metachanged");
    //HTC Music
    iF.addAction("com.htc.music.playstatechanged");
    iF.addAction("com.htc.music.playbackcomplete");
    iF.addAction("com.htc.music.metachanged");
    //MIUI Player
    iF.addAction("com.miui.player.playstatechanged");
    iF.addAction("com.miui.player.playbackcomplete");
    iF.addAction("com.miui.player.metachanged");
    //Real
    iF.addAction("com.real.IMP.playstatechanged");
    iF.addAction("com.real.IMP.playbackcomplete");
    iF.addAction("com.real.IMP.metachanged");
    //SEMC Music Player
    iF.addAction("com.sonyericsson.music.playbackcontrol.ACTION_TRACK_STARTED");
    iF.addAction("com.sonyericsson.music.playbackcontrol.ACTION_PAUSED");
    iF.addAction("com.sonyericsson.music.TRACK_COMPLETED");
    iF.addAction("com.sonyericsson.music.metachanged");
    iF.addAction("com.sonyericsson.music.playbackcomplete");
    iF.addAction("com.sonyericsson.music.playstatechanged");
    //rdio
    iF.addAction("com.rdio.android.metachanged");
    iF.addAction("com.rdio.android.playstatechanged");
    //Samsung Music Player
    iF.addAction("com.samsung.sec.android.MusicPlayer.playstatechanged");
    iF.addAction("com.samsung.sec.android.MusicPlayer.playbackcomplete");
    iF.addAction("com.samsung.sec.android.MusicPlayer.metachanged");
    iF.addAction("com.sec.android.app.music.playstatechanged");
    iF.addAction("com.sec.android.app.music.playbackcomplete");
    iF.addAction("com.sec.android.app.music.metachanged");
    //Winamp
    iF.addAction("com.nullsoft.winamp.playstatechanged");
    //Amazon
    iF.addAction("com.amazon.mp3.playstatechanged");
    //Rhapsody
    iF.addAction("com.rhapsody.playstatechanged");
    //PowerAmp
    iF.addAction("com.maxmpz.audioplayer.playstatechanged");
    //will be added any....
    //scrobblers detect for players (poweramp for example)
    //Last.fm
    iF.addAction("fm.last.android.metachanged");
    iF.addAction("fm.last.android.playbackpaused");
    iF.addAction("fm.last.android.playbackcomplete");
    //A simple last.fm scrobbler
    iF.addAction("com.adam.aslfms.notify.playstatechanged");
    //Scrobble Droid
    iF.addAction("net.jjc1138.android.scrobbler.action.MUSIC_STATUS");

    registerReceiver(mReceiver, iF);
}

private BroadcastReceiver mReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extra = intent.getExtras();
        Log.v("yossi", extra.toString());

    }
};
解决方案

You will get duration of song by using following intents.But is supports only for few players.Please try it

duration    =intent.getLongExtra(MediaStore.Audio.AudioColumns.DURATION, 0);
duration    =intent.getLongExtra("duration", 0);

这篇关于Android的 - 获取当前播放歌曲的时间和经过时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:29