M.A*_*han 17 audio android media-player audio-player http-live-streaming
我想从实时服务器播放音频.我不想下载这些音频文件.这些文件的格式是android java上的mp3.working.
dip*_*ali 31
try {
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://xty/MRESC/images/test/xy.mp3");
player.prepare();
player.start();
} catch (Exception e) {
// TODO: handle exception
}
Run Code Online (Sandbox Code Playgroud)
小智 9
试着这样做:
MediaPlayer mp = new MediaPlayer(/*Your-Context*/);
mp.setDataSource(/*MP3 file's Url*/);
mp.setOnPreparedListener(new OnPreparedListener(){
onPrepared(MediaPlayer mp)
{
mp.start();
}
});
mp.prepareAsync();
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您只想在默认音乐播放器中打开流(这样您就不必处理实现播放器按钮,继续在后台运行等),您可以使用Intent:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://example.com/file.mp3"), "audio/mp3");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
如果您在活动中,使用目前还不是getBaseContext().startActivity(intent),或别的东西,这样你可以调用startActivity()一个上Context对象.
| 归档时间: |
|
| 查看次数: |
32295 次 |
| 最近记录: |