Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to play audio file from url in android

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...

like image 361
subair_a Avatar asked May 12 '11 06:05

subair_a


1 Answers

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;
}
like image 106
Hades Avatar answered Oct 26 '22 05:10

Hades