MediaPlayer seekTo - 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 seekTo method.

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; 
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(){ 
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 
				} 
			} 
		} 
	} 
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");
			}			 
		} 
	} 
7
CodeRank
This code example shows how to use the following methods:seekTo
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // When the beep has finished playing, rewind to queue up another one. 
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
      @Override 
      public void onCompletion(MediaPlayer player) {
        player.seekTo(0);
      } 
    }); 
 
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(RHelper.getRaw("beep"));
    try { 
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
      file.close();
      mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
      mediaPlayer.prepare();
    } catch (IOException ioe) {
      Log.w(TAG, ioe);
      mediaPlayer = null;
    } 
    return mediaPlayer;
6
CodeRank
This code example shows how to use the following methods:isPlaying, pause, seekTo
    	pauseMusic(); 
    	drumbassPlaying = false;
    	cScore = 0;
    	andrModAmt = 10;
    	if (drumbass!=null) drumbass.seekTo(0);
    	if (androidpad!=null) androidpad.seekTo(0);
    } 
     
    static void playSound(int soundKey, float volume, float pitch) {
    	if (soundEnabled && mSoundPoolMap!=null) {
    		Integer soundID = mSoundPoolMap.get(soundKey);
    		if (soundID!=null) {
        		mSoundPool.play(soundID, volume, volume, 1, 0, pitch);
    		} 
    	} 
    } 
 
    public static void playScore() { 
    	//prevent repeated dings 
    	while (currentDing == prevDing) {

6
CodeRank
This code example shows how to use the following methods:seekTo
	// =========================================================== 
	// Methods 
	// =========================================================== 
 
	public void seekTo(final int pMilliseconds) {
		this.mMediaPlayer.seekTo(pMilliseconds);
	} 
 
	public void setOnCompletionListener(final OnCompletionListener pOnCompletionListener) {
		this.mMediaPlayer.setOnCompletionListener(pOnCompletionListener);
	} 
 
	// =========================================================== 
	// Inner and Anonymous Classes 
	// =========================================================== 
} 
7
CodeRank
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
This code example shows how to use the following methods:seekTo
		mediaPlayer.start();
	} 
 
	@Override 
	public void seekTo(long pos) {
		mediaPlayer.seekTo((int) pos);
	} 
 
	@Override 
	public void pause() { 
		mediaPlayer.pause();
	} 
 
	@Override 
	public boolean isPlaying() { 
		return mediaPlayer.isPlaying();
	} 
 
	@Override 
	public long getDuration() { 
6
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: