I'm fairly new to Java and have been developing an app to stream live audio from the Inteet. I've got everything working except for the pause button. All it does for now is scramble the audio for a short period. I'm guessing it has something to do with where mediaPlayer.pause() is called, but I may be wrong. Thank you for your time and response.
package com.example.jacob.wutk;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import java.io.IOException;
public class radio extends AppCompatActivity {
/** Called when the user touches the button */
public void playPauseMusic (View playPause) throws IOException {
String url = "http://streamer.cci.utk.edu:8000/wutk-vorbis"; // your URL here
final MediaPlayer mediaPlayer = new MediaPlayer();
ImageButton imb = (ImageButton) findViewById(R.id.playPause);
if (mediaPlayer.isPlaying()) {
imb.setImageResource(R.drawable.play1);
mediaPlayer.pause();
retu;
} else {
imb.setImageResource(R.drawable.pause1);
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer){
mediaPlayer.start();
}
});
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio);
}
}
