Code example for MediaPlayer: Playing audio and video

Methods: prepareresetsetDataSourcestart

0
	 
	public MediaPlayer mediaPlayer;
	 
	public void playSong(String songUri){
		try{ 
			mediaPlayer.reset();
			mediaPlayer.setDataSource(songUri);
			Log.i(TAG,"songUri: '" + songUri +"'");
			mediaPlayer.prepare();
			mediaPlayer.start();
			setNotificationMessage("now playing: " +  extractFileName(songUri));
			Toast.makeText(getApplicationContext(), "starting: " + songUri, Toast.LENGTH_SHORT);
		}catch (IOException e) {
			Log.e("yaamPlayerService", e.getMessage());
		}catch (IllegalStateException ex){
			Log.e("yaamPlayerService", "illegalStateEx");
		}catch (Exception e){
			Log.e("yaamPlayerService", "exception");
		} 
	}