播放与播放的MediaPlayer [英] Play playlist with MediaPlayer

查看:113
本文介绍了播放与播放的MediaPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个播放列表,我得到使用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.

这篇关于播放与播放的MediaPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆