MediaPlayer getCurrentPosition - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer getCurrentPosition method.

This code example shows how to use the following methods:getCurrentPosition
    }  
	 
	protected long getCurrentPosition() { 
		if (isPlaying) 
		{ 
			return(mPlayer.getCurrentPosition());
		} else { return(-1); } 
	} 
	 
	private boolean isStreaming(String file) 
	{ 
		if (file.contains("http://")) {
			return true; 
		} else { 
			return false; 
		} 
	} 
	 
	protected long getDuration(String file) {
		long duration = -2;
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, getDuration
		if(stream && player!=null) player.seekTo(ms); // 0 = start, 1 = end;
	} 
	 
	float getPosition(){ 
		if(stream && player!=null)
			return ((float)player.getCurrentPosition())/(float)player.getDuration();
		else 
			return 0; 
	} 
	 
	int getPositionMS(){ 
		if(stream && player!=null)
			return player.getCurrentPosition();
		else 
			return 0; 
	} 
	 
	boolean getIsPlaying(){ 
		if(stream)
			return player!=null && player.isPlaying();
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition
    public int progress() { 
        if (mState == RECORDING_STATE) {
            return (int) ((System.currentTimeMillis() - mSampleStart) / 1000);
        } else if (mState == PLAYING_STATE || mState == PLAYING_PAUSED_STATE) {
            if (mPlayer != null) {
                return (int) (mPlayer.getCurrentPosition() / 1000);
            } 
        } 
 
        return 0; 
    } 
 
    public float playProgress() { 
        if (mPlayer != null) {
            return ((float) mPlayer.getCurrentPosition()) / mPlayer.getDuration();
        } 
        return 0.0f; 
    } 
 
    public int sampleLength() { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, getDuration, isPlaying, pause, seekTo
			return true; 
		} 
 
		if ((keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent.KEYCODE_MEDIA_NEXT)
				&& isMediaPlayerStateValid()) { 
			int skipOffset = 10000 + mediaPlayer.getCurrentPosition();
			int duration = mediaPlayer.getDuration();
			if (skipOffset > duration) {
				skipOffset = duration - 1;
			} 
			if (!mediaController.isShowing()) {
				mediaController.show(CONTROLLER_DELAY);
			} 
			mediaPlayer.seekTo(skipOffset);
			return true; 
		} 
 
		if ((keyCode == KeyEvent.KEYCODE_MEDIA_REWIND || keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS)
				&& isMediaPlayerStateValid()) { 
			int skipOffset = mediaPlayer.getCurrentPosition() - 10000;

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition
		return -1; 
	} 
 
	public int getCurrentPosition() { 
		if (mp != null)
			return mp.getCurrentPosition();
		return -1; 
	} 
	 
	public boolean isPlaying() { 
		if (mp != null)
			return mp.isPlaying();
		return false; 
	} 
	 
	public void pause() { 
		if (mp != null)
			mp.pause();
	} 
	 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, stop
	@Override 
	public void onDestroy() { 
		//Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); 
		Log.d(TAG, "onDestroy");
		// TODO should be used in something like pauseService(); 
		mSharedPreferences.edit().putInt("music_location", player.getCurrentPosition()).commit();
		player.stop();
	} 
	 
	@Override 
	public void onStart(Intent intent, int startid) {
		//Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); 
		Log.d(TAG, "onStart");
		player.seekTo(mSharedPreferences.getInt("music_location", 0));
		player.start();
	} 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, prepareAsync, reset, setDataSource, stop
    public void setDataSource(String path) {
        Log.w(TAG, "Set data source: " + path);
        setDataSource = true;
        isPrepared = false;
        try { 
            player.setDataSource(path);
            Log.w(TAG, "Set data source: " + path);
        } catch (IOException ex) {
            Log.w(TAG, "error set data source", ex);
        } catch (IllegalArgumentException ex) {
            Log.w(TAG, "error set data source", ex);
        } catch (IllegalStateException ex) {
            Log.w(TAG, "error set data source", ex);
        } 
    } 
 
    public void prepare() { 
        try { 
            player.prepareAsync();
        } catch (IllegalStateException e) {

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition
	public boolean isPlaying() { 
		return mediaPlayer.isPlaying();
	} 
 
	public long getCurrentPositionInMedia() { 
		return mediaPlayer.getCurrentPosition();
	} 
 
	public long getMediaDuration() { 
		return mediaPlayer.getDuration();
	} 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition, prepare, reset, seekTo, setDataSource
 
		videoPlayer.setOnErrorListener(new OnErrorListener() {
			@Override 
			public boolean onError(MediaPlayer mp, int what, int extra) {
				// #1 
				int pos = mp.getCurrentPosition();
				mp.reset();
				try { 
					mp.setDataSource(ctx, video);
					mp.prepare();
				    mp.start();
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (SecurityException e) {
					e.printStackTrace();
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getCurrentPosition
		return mediaPlayer.getDuration();
	} 
 
	@Override 
	public long getCurrentPosition() { 
		return mediaPlayer.getCurrentPosition();
	} 
 
	@Override 
	public int getBufferPercentage() { 
		return 0; 
	} 
 
	@Override 
	public boolean canSeekForward() { 
		return true; 
	} 
 
	@Override 
	public boolean canSeekBackward() { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related MediaPlayer getCurrentPosition Questions & Answers:

Other MediaPlayer getCurrentPosition Examples

115:					// get current song position
116:					int currentPosition = mp.getCurrentPosition();
117:					// check if seekForward time is lesser than song duration
118:					if(currentPosition + seekForwardTime <= mp.getDuration()){
119:						// forward song

Read More

getCurrentPosition Method Overview
Gets the current playback position.
See Code Examples for other Android MediaPlayer Methods: