Code example for MediaPlayer

Methods: prepareAsyncsetDataSourcesetLoopingsetOnPreparedListener

0
	@Override 
	public void onCreate() { 
		Log.d(TAG, "onCreate");
		try { 
			String audioFile = "http://zlz-stream11.streamserver.ch/2/drs3/mp3_128";
			mediaPlayer = new MediaPlayer();	
			mediaPlayer.setDataSource(audioFile);
			mediaPlayer.prepareAsync();
			mediaPlayer.setOnPreparedListener(this);
			mediaPlayer.setLooping(false); // Set looping
		} catch (Exception e) {
			Log.e(TAG, e.toString(), e);
		} 
	} 
 
	@Override 
	public void onDestroy() { 
		Toast.makeText(this, TAG + " Stopped", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onDestroy");
		mediaPlayer.stop();
		isRunning = false;