5
我目前有一個媒體播放器,正在流媒體文件。當該文件完成後,代碼是什麼,以便它進入下一個url/mp3?媒體播放器流url,然後播放下一個url
此外,是否有代碼來獲取文件的名稱並顯示它?我會怎麼做呢?
感謝
編輯
見下面我的代碼:
package com.example.m3uplayer;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.media.MediaPlayer.OnCompletionListener;
public class m3uPlayer extends Activity implements MediaPlayer.OnCompletionListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
//http://dl.dropbox.com/u/24535120/AfroJack-UMF11-clip2.mp3
//http://dl.dropbox.com/u/24535120/Avicii%20clip%201.mp3
Uri myUri = Uri.parse("http://dl.dropbox.com/u/24535120/AfroJack-UMF11-clip2.mp3");
MediaPlayer sdrPlayer = new MediaPlayer();
try {
sdrPlayer.setDataSource(this, myUri);//"http://mp1.somafm.com:8032");
sdrPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
sdrPlayer.prepare(); //don't use prepareAsync for mp3 playback
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sdrPlayer.start();
}
@Override
public void onCompletion(MediaPlayer sdrPlayer) {
Uri myUri5 = Uri.parse("http://dl.dropbox.com/u/24535120/Avicii%20clip%201.mp3");
try {
sdrPlayer.setDataSource(this, myUri5);
sdrPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
sdrPlayer.prepare(); //don't use prepareAsync for mp3 playback
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sdrPlayer.start();
}
}
感謝您的幫助特德。那麼當該歌曲從URL播放時,沒有辦法讓歌曲的標題出現? – Splitusa 2011-06-14 16:07:14
另外,一種隨機問題......是否有可能創建一個包含多個URL的數組,並讓媒體播放器播放數組?如果可能的話,我還需要設置完成監聽器嗎?謝謝 – Splitusa 2011-06-14 16:10:15
看到我上面的代碼 – Splitusa 2011-06-14 16:43:43