Best code examples for MediaPlayer seekTo method (android.media.MediaPlayer.seekTo)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer seekTo method.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

MediaPlayer seekTo examples from Open Source projects
This code example shows how to use the following methods: seekTo
	void setPosition(float pct){
		if(stream && player!=null) player.seekTo((int) (player.getDuration()*pct)); // 0 = start, 1 = end;
	} 
	 
	void setPositionMS(int ms){
		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; 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: isLooping, isPlaying, pause, seekTo, setLooping
		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 )
		{ 

9
CodeRank
This code example shows how to use the following methods: prepare, seekTo, start, stop
		} 
	} 
	 
	public void rewindBackgroundMusic(){		 
		if (mBackgroundMediaPlayer != null){
			mBackgroundMediaPlayer.stop();			
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "rewindBackgroundMusic: error state");
			}			 
		} 
	} 
	 
	public boolean isBackgroundMusicPlaying(){ 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: isPlaying, prepare, seekTo, stop
	 
	public static void stopMusic() 
	{ 
		if(mPlayer != null)
		{ 
			if(mPlayer.isPlaying())
			{ 
				mPlayer.stop();
				try 
				{ 
					mPlayer.prepare();
					mPlayer.seekTo(0);
				} 
				catch (IOException e)
				{ 
					// do nothing here FIXME 
				} 
			} 
		} 
	} 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, seekTo, setLooping, start, stop
		 
		if (mBackgroundMediaPlayer == null){
			Log.e(TAG, "playBackgroundMusic: background media player is null");
		} else {		 
			// if the music is playing or paused, stop it 
			mBackgroundMediaPlayer.stop();			
			 
			mBackgroundMediaPlayer.setLooping(isLoop);
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "playBackgroundMusic: error state");
			}			 
		} 
	} 
Full Snippet Info
7
CodeRank
Related MediaPlayer seekTo Questions & Answers:
Other MediaPlayer seekTo Examples
119:						// forward song
120:						mp.seekTo(currentPosition + seekForwardTime);
121:					}else{
122:						// forward to end position
123:						mp.seekTo(mp.getDuration());
-
122:						// forward to end position
123:						mp.seekTo(mp.getDuration());
124:					}
125:				}
126:			});
-
318:				   // Displaying Total Duration time
319:				   songTotalDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration));
320:				   // Displaying time completed playing
321:				   songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));
322:

Read More

seekTo Method Overview
Seeks to specified time position.
See Code Examples for other Android MediaPlayer Methods: