Java Code Examples for android.media.MediaPlayer#seekTo()

The following examples show how to use android.media.MediaPlayer#seekTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicService.java    From RhymeMusic with Apache License 2.0 6 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp)
{
    Log.d(TAG, SUB + "onPrepared");

    mp.start();

    if ( application.isOnline() )
    {
        Toast.makeText(getBaseContext(), "音乐开始播放了", Toast.LENGTH_SHORT).show();
    }

    mp.seekTo(application.getCurrentPosition());

    sendMessage(UPDATE_PLAY_STATUS);
    sendMessage(UPDATE_DURATION);
    sendMessage(UPDATE_CURRENT_MUSIC);
    sendMessage(UPDATE_PROGRESS);
}
 
Example 2
Source File: PlaybackFragment.java    From SoundRecorder with GNU General Public License v3.0 6 votes vote down vote up
private void prepareMediaPlayerFromPoint(int progress) {
    //set mediaPlayer to start from middle of the audio file

    mMediaPlayer = new MediaPlayer();

    try {
        mMediaPlayer.setDataSource(item.getFilePath());
        mMediaPlayer.prepare();
        mSeekBar.setMax(mMediaPlayer.getDuration());
        mMediaPlayer.seekTo(progress);

        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                stopPlaying();
            }
        });

    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }

    //keep screen on while playing audio
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
 
Example 3
Source File: MoreOptionFragment.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.button_one)
void ButtonOneClick() {
    if(getContext()!=null) {
        ArrayList<Song> songs = SongLoader.getAllSongs(getContext());
        MediaPlayer mediaPlayer = new MediaPlayer();
        try {
            mediaPlayer.setDataSource(songs.get(new Random().nextInt(songs.size())).data);
            mediaPlayer.prepare();
            mediaPlayer.seekTo(1000*25);
            mRoot.postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        mediaPlayer.release();
                    } catch (Exception ignored) {}
                }
            },20*1000);
            mediaPlayer.start();
        } catch (Exception e) {
            e.printStackTrace();
            Toasty.error(getContext(),"Couldn't play songs").show();
        }
    }
}
 
Example 4
Source File: SampleVideoPlayerActivity.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
/**
 * If we are being restarted from a paused state, don't start playing.
 */
public void onPrepared(MediaPlayer mp) {
    mp.start();
    if (!mStartVideoOnCreate) {
        mp.pause();
    }
    if (-1 != mSavedPosition) {
        mp.seekTo(mSavedPosition);
        mSavedPosition = -1;
    }
    hideSystemUi();
}
 
Example 5
Source File: MediaServiceBinder.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void seekTo(int pos) {
    Log_OC.d(TAG, "Seeking " + pos + " through binder...");
    MediaPlayer currentPlayer = mService.getPlayer();
    MediaService.State currentState = mService.getState();
    if (currentPlayer != null && currentState != State.PREPARING && currentState != State.STOPPED) {
        currentPlayer.seekTo(pos);
    }
}
 
Example 6
Source File: AudioNoteHelper.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp)
{
	Log.d(App.Home.LOG, "FINISHED PLAYING MEDIA FILE");

	progress.pause();
	mp.seekTo(0);

	setState(RecorderState.IS_IDLE);
}
 
Example 7
Source File: CaptureActivity.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}
 
Example 8
Source File: CaptureActivity.java    From QrCodeLib with MIT License 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}
 
Example 9
Source File: CaptureActivity.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer)
{
    mediaPlayer.seekTo(0);
}
 
Example 10
Source File: BeepManager.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
    // When the beep has finished playing, rewind to queue up another one.
    mp.seekTo(0);
}
 
Example 11
Source File: SweepActivity.java    From letv with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}
 
Example 12
Source File: CaptureActivity.java    From MaterialHome with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}
 
Example 13
Source File: CaptureNewActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
	mediaPlayer.seekTo(0);
}
 
Example 14
Source File: BeepManager.java    From AirFree-Client with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
    // When the beep has finished playing, rewind to queue up another one.
    mp.seekTo(0);
}
 
Example 15
Source File: ZxingScanActivity.java    From Roid-Library with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}
 
Example 16
Source File: BeepManager.java    From myapplication with Apache License 2.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
    // When the beep has finished playing, rewind to queue up another one.
    mp.seekTo(0);
}
 
Example 17
Source File: CaptureActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
	mediaPlayer.seekTo(0);
}
 
Example 18
Source File: BeepManager.java    From moVirt with Apache License 2.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
    // When the beep has finished playing, rewind to queue up another one.
    mp.seekTo(0);
}
 
Example 19
Source File: StandupTimer.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private void playSound(MediaPlayer mp) {
    mp.seekTo(0);
    mp.start();
}
 
Example 20
Source File: CaptureActivity.java    From vmqApk with MIT License 4 votes vote down vote up
public void onCompletion(MediaPlayer mediaPlayer) {
    mediaPlayer.seekTo(0);
}