Code example for MediaPlayer: Playing audio and video

Methods: isLoopingisPlayingpauseseekTosetLoopingstart

2
		invokePlay( false ); 
	} 
	 
	private void invokePlay( Boolean loop )
	{ 
		Boolean playing = ( mp.isLooping() || mp.isPlaying() );
		if ( playing )
		{ 
			mp.pause();
			mp.setLooping(loop);
			mp.seekTo(0);
			mp.start();
		} 
		if ( !playing && state == PREPARED )
		{ 
			state = PENDING_LOOP;
			onPrepared( mp );
		} 
		else if ( !playing )
		{ 
			state = PENDING_LOOP;
			mp.setLooping(loop);
			mp.start();
		} 
	} 
	 
	public void stop() throws IOException 
	{ 
		if ( mp.isLooping() || mp.isPlaying() )
		{ 
			state = INVALID;
			mp.pause();
			mp.seekTo(0);
		} 
	} 
	 
	public void loop() throws IOException 
	{ 
		invokePlay( true ); 
	} 
	 
	public void unload() throws IOException 
	{ 
		this.stop();
		mp.release();
	} 
	 
	public void onPrepared(MediaPlayer mPlayer) 
	{ 
		if (state == PENDING_PLAY) 
		{ 
			mp.setLooping(false);
			mp.seekTo(0);
			mp.start();
			state = PLAYING;
		} 
		else if ( state == PENDING_LOOP )
		{ 
			mp.setLooping(true);
			mp.seekTo(0);
			mp.start();
			state = LOOPING;
		} 
		else 
		{ 
			state = PREPARED;
			mp.seekTo(0);
		} 
	} 
	 
	public void onCompletion(MediaPlayer mPlayer)
	{