如何从android中的url播放音频文件 [英] how to play audio file from url in android
本文介绍了如何从android中的url播放音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的应用程序中播放来自远程服务器的音频文件.当我使用 localhost 服务器(使用 WAMP)进行测试时,我可以玩.当服务器提供的相同文件不起作用时..文件无扩展名,内容为MP3
I need to play audio file from remote server in my app. I could play when I tested with localhost server (using WAMP). When the same file supplied from the server it is not working.. The file has no extension and the content is MP3
String fileUrl = "http://192.168.1.131/myproject/songs/xyz";
String url = "http://myserver/songs/xyz"; //(myserver -> A remote server)
mVideoView.setVideoURI(Uri.parse(fileUrl));
mVideoView.requestFocus();
此外,我还需要更好地控制玩家.
请帮忙...
Also I need to have a better control over player.
Please help...
推荐答案
public void onRadioClick(View v) {
if (!isPLAYING) {
isPLAYING = true;
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(getString(R.string.audio_stream));
mp.prepare();
mp.start();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
} else {
isPLAYING = false;
stopPlaying();
}
}
private void stopPlaying() {
mp.release();
mp = null;
}
这篇关于如何从android中的url播放音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文