Code example for MediaPlayer

Methods: getDurationpreparereleasesetDataSource

0
	 
	protected long getDuration(String file) {
		long duration = -2;
		if (!isPlaying & !isStreaming(file)) {
			try { 
				mPlayer = new MediaPlayer();
				mPlayer.setDataSource("/sdcard/" + file);
				mPlayer.prepare();
				duration = mPlayer.getDuration();
				mPlayer.release();
			} catch (Exception e) { e.printStackTrace(); return(-3); }
		} else 
		if (isPlaying & !isStreaming(file)) {
			duration = mPlayer.getDuration();
		} else  
		if (isPlaying & isStreaming(file)) {
			try { 
				duration = mPlayer.getDuration();
			} catch (Exception e) { e.printStackTrace(); return(-4); }
		}else { return -1; } 
		return duration;