Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
看一下这两个教程,在这些教程中,.mp3 文件是通过 web url 播放的,
使用 Android MediaPlayer 类从 URL 流式传输 mp3 媒体文件的示例
从 Url 播放 Mp3 文件
另外,如果您想在后台播放 .mp3 文件,我认为您必须使用 Service 和 AIDL,
查看基本的 Android 音乐播放器演示 MusicDroid - 音频播放器第二部分描述了如何为您的音频播放器使用Service和AIDl。
谢谢..
Look at these two tutorials, In these the .mp3 files are playing through web url,
Example of streaming mp3 mediafile from URL with Android MediaPlayer class
Play Mp3 file from a Url
Also if you want to play .mp3 file in background I think you have to use Service and AIDL for it,
Look at basic Android-Music Player demo MusicDroid - Audio Player Part II it describe how to use Service and AIDl for your Audio Player.
Thanks..
执行此操作的简单方法::
MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepare(); mp.start();
simple method to do this ::
public class PlayAudioManager { private static MediaPlayer mediaPlayer; public static void playAudio(final Context context, final String url) throws Exception { if (mediaPlayer == null) { mediaPlayer = MediaPlayer.create(context, Uri.parse(url)); } mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { killMediaPlayer(); } }); mediaPlayer.start(); } private static void killMediaPlayer() { if (mediaPlayer != null) { try { mediaPlayer.reset(); mediaPlayer.release(); mediaPlayer = null; } catch (Exception e) { e.printStackTrace(); } } } }
在您的活动中,例如,只需调用PlayAudioManager.playAudio(上下文,http://dict.youdao.com/dictvoice?audio=good&type=1)
PlayAudioManager.playAudio(上下文,http://dict.youdao.com/dictvoice?audio=good&type=1)
In your Activity,example,just callPlayAudioManager.playAudio(context, http://dict.youdao.com/dictvoice?audio=good&type=1)
PlayAudioManager.playAudio(context, http://dict.youdao.com/dictvoice?audio=good&type=1)
您可以使用MediaPlayer.create(上下文, uri);传递上下文(this)和您想要播放歌曲的 uri
You can useMediaPlayer.create(context, uri);pass the context(this) and the uri from where you want to play the song
if (!isPlaying) { isPlaying = true; mp = new MediaPlayer(); try { mp.reset(); // new one mp.setDataSource(AudioPlayer.this, myUri); //mp.prepareAsync(); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.prepare(); // don't use prepareAsync for mp3 playback mp.start(); // String songTitle = songsList.get(songIndex).get("songTitle"); // songTitleLabel.setText(songTitle); songProgressBar.setProgress(0); songProgressBar.setMax(100); // Updating progress bar updateProgressBar(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { isPlaying = false; mp.release();// stop Playing //mp = null; }
我已经在我的 MediaPlayer 中使用它了,它正在工作..无需下载它..
I have use it in my MediaPlayer it is working .. there is no need to download it..
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(5)
看一下这两个教程,在这些教程中,.mp3 文件是通过 web url 播放的,
使用 Android MediaPlayer 类从 URL 流式传输 mp3 媒体文件的示例
从 Url 播放 Mp3 文件
另外,如果您想在后台播放 .mp3 文件,我认为您必须使用 Service 和 AIDL,
查看基本的 Android 音乐播放器演示 MusicDroid - 音频播放器第二部分描述了如何为您的音频播放器使用Service和AIDl。
谢谢..
Look at these two tutorials, In these the .mp3 files are playing through web url,
Example of streaming mp3 mediafile from URL with Android MediaPlayer class
Play Mp3 file from a Url
Also if you want to play .mp3 file in background I think you have to use Service and AIDL for it,
Look at basic Android-Music Player demo MusicDroid - Audio Player Part II it describe how to use Service and AIDl for your Audio Player.
Thanks..
执行此操作的简单方法::
simple method to do this ::
在您的活动中,例如,只需调用
PlayAudioManager.playAudio(上下文,http://dict.youdao.com/dictvoice?audio=good&type=1)
In your Activity,example,just call
PlayAudioManager.playAudio(context, http://dict.youdao.com/dictvoice?audio=good&type=1)
您可以使用
MediaPlayer.create(上下文, uri);
传递上下文(this)和您想要播放歌曲的 uri
You can use
MediaPlayer.create(context, uri);
pass the context(this) and the uri from where you want to play the song
我已经在我的 MediaPlayer 中使用它了,它正在工作..无需下载它..
I have use it in my MediaPlayer it is working .. there is no need to download it..