2
A
回答
1
你可以看到下面的代碼從URL流式音頻
private void playVideo() {
try {
final String path = "http://www.a1freesoundeffects.com/animals12557/catmeow.wav";
// If the path has not changed, just start the media player
if (path.equals(current) && mp != null) {
mp.start();
return;
}
current = path;
// Create a new media player and set the listeners
mp = new MediaPlayer();
mp.setDataSource(path);
mp.prepare();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
if (mp != null) {
mp.stop();
mp.release();
}
}
}
1
你可以試試這種方式。
class Mp3Filter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3"));
}
}
public class AudioPlayer extends ListActivity implements OnClickListener{
private static final String MEDIA_PATH = new String("/sdcard/backup/songs");
private List<String> songs = new ArrayList<String>();
private MediaPlayer mp = new MediaPlayer();
private int currentPosition = 0;
private static final String TAG = "Audio Player Demo ";
private static final String isPlaying = "Media is Playing";
private static final String notPlaying = "Media has stopped Playing";
Button playerButton;
public void onClick(View v) {
if (v.getId() == R.id.play) {
playPause();
}
}
@Override
public void onCreate(Bundle icicle) {
try {
super.onCreate(icicle);
setContentView(R.layout.songlist);
playerButton = (Button) this.findViewById(R.id.play);
playerButton.setText(R.string.stop_label);
playerButton.setOnClickListener(this);
updateSongList();
//demoPlay();
} catch (NullPointerException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
public void updateSongList() {
File home = new File(MEDIA_PATH);
if (home.listFiles(new Mp3Filter()).length > 0) {
for (File file : home.listFiles(new Mp3Filter())) {
songs.add(file.getName());
}
ArrayAdapter<String> songList = new ArrayAdapter<String>(this,R.layout.song_item,songs);
setListAdapter(songList);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
currentPosition = position;
playSong(MEDIA_PATH + songs.get(position));
}
private void playSong(String songPath) {
try {
mp.reset();
mp.setDataSource(songPath);
mp.prepare();
mp.start();
// Setup listener so next song starts automatically
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
nextSong();}
});
} catch(IOException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
private void nextSong() {
if (++currentPosition >= songs.size()) {
// Last song, just reset currentPosition
currentPosition = 0;
// playSong(MEDIA_PATH + songs.get(currentPosition));
} else {
// Play next song
playSong(MEDIA_PATH + songs.get(currentPosition));
}
}
private void demoPause(){
mp.pause();
playerButton.setText(R.string.play_label);
Toast.makeText(this, notPlaying, Toast.LENGTH_LONG).show();
Log.d(TAG, notPlaying);
}
// Initiate playing the media player
private void demoPlay(){
mp.start();
playerButton.setText(R.string.stop_label);
Toast.makeText(this, isPlaying, Toast.LENGTH_LONG).show();
Log.d(TAG, isPlaying);
}
// Toggle between the play and pause
private void playPause() {
if(mp.isPlaying()) {
demoPause();
} else {
demoPlay();
}
}
}
+0
@ Krunal:感謝烏拉圭回合的答案...我想知道,如果我想補充對此,我應該能夠從互聯網流媒體比我怎麼能做到這一點?任何想法???再次感謝您 – 2010-09-14 06:21:35
+0
我在下面添加了答案,您還可以參考此鏈接獲取更多信息http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video .html – 2010-09-14 07:03:04
相關問題
- 1. Android媒體播放器流媒體
- 2. 在Android中使用java媒體框架
- 3. 使用Android圖庫顯示媒體RSS
- 4. Android使用媒體播放流m3uPlayer
- 5. 使用線程的Android媒體錄製
- 6. RTSP使用Android MediaPlayer流媒體視頻
- 7. 使用adb刷新Android媒體庫
- 8. 使用Android MediaStore管理媒體
- 9. 使用媒體庫
- 10. Android媒體支持
- 11. Android MediaRecorder流媒體
- 12. Android的HTTP流媒體播放器的URL使用媒體播放器
- 13. 如何使用android媒體服務將該媒體返回到我的活動?
- 14. 使用CSS媒體查詢
- 15. 媒體使用Compact Framework的
- 16. 使用媒體查詢
- 17. 從/媒體/使用nginx
- 18. 使用媒體查詢
- 19. 使用媒體查詢
- 20. 如何使用ffmpeg android使用硬件解碼媒體文件?
- 21. Android上的PHP媒體流
- 22. RTSP Android媒體播放器
- 23. Android媒體控制器
- 24. Android中的流媒體.asx
- 25. Android VideoView流媒體問題
- 26. Android媒體記錄器
- 27. Android媒體播放器setdatasource
- 28. Android中的媒體格式?
- 29. 從Android流媒體到VLC
- 30. android:更新媒體存儲
感謝krunal爲你的努力..好的 – 2010-09-14 11:14:51
如果你有任何想法,我如何從我的Android應用程序找到DLNA設備列表?所以我可以將媒體轉移到該設備上 – 2010-09-14 11:15:53