播放与播放的MediaPlayerMediaPlayer

2023-09-06 02:02:43 作者:七度空间里住着个吸血鬼

我想打一个播放列表,我得到使用MediaStore提供商。但是,当我尝试播放播放列表什么也没发生。一个可以玩的MediaPlayer播放列表(m3u文件),做我需要设置第一首曲目进行播放?

I'm trying to play a playlist I get using the MediaStore provider. However, when I try playing a playlist nothing happens. Can a MediaPlayer play a playlist (m3u file) and do I need to set the first track to play ?

这是我的测试code在OnCreate()方法:

This is my test code in the onCreate() method:

        Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
    if(uri == null) {
        Log.e("Uri = null");
    }
    String[] projection = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists.DATA };
    Cursor c = managedQuery(uri, projection, null, null, null);
    if(c == null) {
        Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_error, Toast.LENGTH_LONG).show();
        return;
    }
    if(!c.moveToFirst()) {
        c.close();
        Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_no_music, Toast.LENGTH_LONG).show();
        return;
    }
    c.moveToFirst();
    try {
        MediaPlayer player = new MediaPlayer();
        player.setDataSource(c.getString(2));
        player.start();
    } catch(Exception e) {
        e.printStackTrace();
    }

我已经打开每个卷流。

I have turned on every volume stream.

谢谢你,

Kaloer

推荐答案

我不认为媒体播放器可以播放播放列表。我认为它只会播放曲目。你将不得不继续从播放列表中的曲目的曲目,并将其传递给媒体播放器。它可以帮助你检查出的Andr​​oid源$ C ​​$下的音乐播放器,以及如何处理它。

I don't think media player can play a playlist. I think it will only play a track. You will have to keep track of the tracks from the playlist and pass them to the media player. It might help you to check out the android source code for the music player and how it handles it.

 
精彩推荐
图片推荐