Android如何显示歌曲内部歌词

时间:2013-06-06 18:25:21

标签: android android-mediaplayer

我正在尝试创建一个Android应用程序,可以显示歌曲内部歌词,因为音乐播放器正在播放歌曲。我不想使用.lrc文件。有没有人有其他选择来显示歌曲内部歌词?

下面的代码:当音乐播放器播放歌曲时读取操作。我把它放在onCreate()。

    IntentFilter filter = new IntentFilter();

    // Read action when music player changed current song
    // I just try it with stock music player form android

    //Google Android player
    filter.addAction("com.android.music.playstatechanged");
    filter.addAction("com.android.music.playbackcomplete");
    filter.addAction("com.android.music.metachanged");        
    //HTC Music
    filter.addAction("com.htc.music.playstatechanged");
    filter.addAction("com.htc.music.playbackcomplete");
    filter.addAction("com.htc.music.metachanged");      
    //MIUI Player
    filter.addAction("com.miui.player.playstatechanged");
    filter.addAction("com.miui.player.playbackcomplete");
    filter.addAction("com.miui.player.metachanged");        
    //Real
    filter.addAction("com.real.IMP.playstatechanged");
    filter.addAction("com.real.IMP.playbackcomplete");
    filter.addAction("com.real.IMP.metachanged");
    //SEMC Music Player
    filter.addAction("com.sonyericsson.music.playbackcontrol.ACTION_TRACK_STARTED");
    filter.addAction("com.sonyericsson.music.playbackcontrol.ACTION_PAUSED");
    filter.addAction("com.sonyericsson.music.TRACK_COMPLETED");
    filter.addAction("com.sonyericsson.music.metachanged");       
    //rdio
    filter.addAction("com.rdio.android.metachanged");
    filter.addAction("com.rdio.android.playstatechanged");     
    //Samsung Music Player
    filter.addAction("com.samsung.sec.android.MusicPlayer.playstatechanged");
    filter.addAction("com.samsung.sec.android.MusicPlayer.playbackcomplete");
    filter.addAction("com.samsung.sec.android.MusicPlayer.metachanged");
    filter.addAction("com.sec.android.app.music.playstatechanged");
    filter.addAction("com.sec.android.app.music.playbackcomplete");
    filter.addAction("com.sec.android.app.music.metachanged");        
    //Winamp
    filter.addAction("com.nullsoft.winamp.playstatechanged");
    filter.addAction("com.nullsoft.winamp.metachanged");
    //Amazon
    filter.addAction("com.amazon.mp3.playstatechanged");
    filter.addAction("com.amazon.mp3.metachanged"); 
    //Rhapsody
    filter.addAction("com.rhapsody.playstatechanged");
    filter.addAction("com.rhapsody.metachanged");
    //PowerAmp
    filter.addAction("com.maxmpz.audioplayer.playstatechanged");
    filter.addAction("com.maxmpz.audioplayer.metachanged");
    // MyTouch4G
    filter.addAction("com.real.IMP.metachanged");
    //appollo
    filter.addAction("com.andrew.apollo.metachanged");
    //will be added any....

    //scrobblers detect for players (poweramp for example)
    //Last.fm
    filter.addAction("fm.last.android.metachanged");
    filter.addAction("fm.last.android.playbackpaused");
    filter.addAction("fm.last.android.playbackcomplete");
    //A simple last.fm scrobbler
    filter.addAction("com.adam.aslfms.notify.playstatechanged");
    //Scrobble Droid
    filter.addAction("net.jjc1138.android.scrobbler.action.MUSIC_STATUS");


    registerReceiver(mReceiver, filter);
    //scrobbling finished

这是获取音乐信息(mReceiver)功能

private BroadcastReceiver mReceiver = new BroadcastReceiver() {

       @Override
        public void onReceive(Context context, Intent intent)
        {
        String action = intent.getAction();
        String cmd = intent.getStringExtra("command");
        Log.d("mIntentReceiver.onReceive ", action + " / " + cmd);
        String lyric = intent.getStringExtra("lyric");
        String artist1 = intent.getStringExtra(MediaStore.Audio.AudioColumns.ARTIST);
        String album1 = intent.getStringExtra(MediaStore.Audio.AlbumColumns.ALBUM);
        String track1 = intent.getStringExtra(MediaStore.Audio.AudioColumns.TITLE_KEY);
        Toast.makeText(context, "Command : "+cmd+"\n Artist : "+artist1+"\n Album :"+album1+"\n Track : "+track1+"\n Lyric : "+lyric , Toast.LENGTH_SHORT).show();
        }
};

但是这段代码中的歌词显示为null。有人有任何解决方案吗?

1 个答案:

答案 0 :(得分:1)

这可能无法完全回答这个问题,但我希望它可以帮助您稍微改善一下您的问题。歌词是像缩略图这样的元数据,如果要显示歌曲,歌曲应该添加歌词元数据。确保它在那里。