3

Android 媒体播放器:我可以从 URL 播放 .mp3 文件。在玩 .pls 时会变得很糟糕。

代码:

try{
String url=".pls url";
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
}catch(Exception 
System.out.println("@@ Exception while playing: "+e);
mediaPlayer .release();
mediaPlayer = null;
}

错误:

09-12 12:44:04.026: E/MediaPlayer(704): error (1, -2147483648)
09-12 12:44:04.026: I/System.out(704): @@ Exception while playing: java.io.IOException: Prepare failed.: status=0x1
4

3 回答 3

1

如果pls您的意思是播放列表信息文件,则媒体播放器无法处理pls文件。

.pls 文件不是媒体文件。所以你不能播放 .pls 文件。通常 .pls 由应用程序处理,应用程序从 pls 文件中提取信息并播放 pls 指向的音乐文件。

于 2012-09-12T08:10:05.427 回答
0
String musicUlrPath;
LinkedList<String> streamingUrlList;

        streamingUrlList=new LinkedList<String>();

    ExecuteArrayList executeArrayList=new ExecuteArrayList();
                    executeArrayList.execute("blank");



class ExecuteArrayList extends AsyncTask<String, String, String>

        {

            @Override
            protected String doInBackground(String... params) {
                // TODO Auto-generated method stub
                try {

                streamingUrlList=getStreamingUrl(pathFromJson);//you are geting path during json response 

                } catch (Exception e) {
                        e.printStackTrace();

                       }
                return null;

            }


            @Override
            protected void onPostExecute(String result) {
                // TODO Auto-generated method stub


                musicUlrPath=(streamingUrlList.get(0));


            }

        }



    public LinkedList<String> getStreamingUrl(String url) {

        Log.i(LOGTAG, "get streaming url");
        final BufferedReader br;
        String murl = null;
        LinkedList<String> murls = null;
        try {
            URLConnection mUrl = new URL(url).openConnection();
            br = new BufferedReader(
                    new InputStreamReader(mUrl.getInputStream()));
            murls = new LinkedList<String>();
            while (true) {
                try {
                    String line = br.readLine();

                    if (line == null) {
                        break;
                    }
                    murl = parseLine(line);
                    if (murl != null && !murl.equals("")) {
                        murls.add(murl);

                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.i(LOGTAG, "url to stream :" + murl);
        return murls;
    }

    private String parseLine(String line) {
        if (line == null) {
            return null;
        }
        String trimmed = line.trim();
        if (trimmed.indexOf("http") >= 0) {
            return trimmed.substring(trimmed.indexOf("http"));
        }
        return "";
    }

现在设置提取的路径

mediaPlayer.setDataSource(musicUlrPath);
于 2016-10-20T14:42:28.550 回答
-1
Extract pls file in notepad , It will show like this
playlist]
File1=Alternative\everclear -URL
Title1=Everclear - So Much For The Afterglow
Length1=233    
File2=Comedy\Weird Al - Everything You Know Is Wrong.mp3   
.
.   
NumberOfEntries=5    
Version=2.

Use that URL in Media player.It will work.
于 2013-03-28T07:47:13.207 回答