how to play audio file from url in android

前端 未结 4 1841
有刺的猬
有刺的猬 2021-01-03 04:26

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

4条回答
  •  孤街浪徒
    2021-01-03 05:03

    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;
    }
    

提交回复
热议问题