Example usage for android.media MediaPlayer reset

List of usage examples for android.media MediaPlayer reset

Introduction

In this page you can find the example usage for android.media MediaPlayer reset.

Prototype

public void reset() 

Source Link

Document

Resets the MediaPlayer to its uninitialized state.

Usage

From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java

private void finishListening(MediaPlayer mediaPlayer) {
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.stop();//from  w ww. j a  va 2s . c  om
    }
    mediaPlayer.reset();
    mediaPlayer.release();
    recordButton.setBackgroundResource(R.drawable.button_record_enabled);
    listenButton.setBackgroundResource(R.drawable.button_listen_enabled);
    recordingStatus = RecordingStatus.RECORDED;
}

From source file:bupt.tiantian.callrecorder.callrecorder.MainActivity.java

@Override
public void onCompletion(MediaPlayer mp) {
    mp.reset();
    mediaController.hide();
    mediaController.setEnabled(false);
}

From source file:hku.fyp14017.blencode.ui.controller.SoundController.java

public void startSound(SoundInfo soundInfo, MediaPlayer mediaPlayer) {
    if (!soundInfo.isPlaying) {
        try {/*from ww w.  j  av a2 s  .  co  m*/
            mediaPlayer.reset();
            mediaPlayer.setDataSource(soundInfo.getAbsolutePath());
            mediaPlayer.prepare();
            mediaPlayer.start();

            soundInfo.isPlaying = true;
        } catch (IOException ioException) {
            Log.e(TAG, "Cannot start sound.", ioException);
        }
    }
}

From source file:com.mylovemhz.simplay.MusicService.java

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    currentState = State.ERROR;/* w w  w  .  j av  a  2s . c  om*/
    mp.reset();
    currentState = State.IDLE;
    if (callbacks != null)
        callbacks.onError();
    return true;
}

From source file:com.bayapps.android.robophish.playback.LocalPlayback.java

/**
 * Called when media player is done playing current song.
 *
 * @see OnCompletionListener/*from w  w  w . ja  v  a2  s. c o  m*/
 */
@Override
public void onCompletion(MediaPlayer player) {
    LogHelper.d(TAG, "onCompletion from MediaPlayer");
    // The media player finished playing the current song, so we go ahead
    // and start the next.

    if (mMediaPlayersSwapping) {
        mCurrentPosition = 0;
        mCurrentMediaId = mNextMediaId;
        MediaPlayer old = mMediaPlayer;
        mMediaPlayer = nextMediaPlayer(); //we're now using the new media player
        mMediaPlayersSwapping = false;
        old.reset(); //required for the next time we swap
        mCallback.onPlaybackStatusChanged(mState);
    }

    if (mCallback != null) {
        mCallback.onCompletion();
    }

}

From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java

@Override
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
    if (mIsError)
        return false;

    mIsError = true;/*from  www.j a va 2  s.com*/

    Toast.makeText(this, getString(R.string.toast_preparing_track_msg_error), Toast.LENGTH_LONG).show();

    mediaPlayer.reset();
    mController.getTransportControls().pause();

    return true;
}

From source file:com.android.onemedia.playback.LocalRenderer.java

private void cleanUpPlayer() {
    if (DEBUG) {/* w  w w  .  ja  va2  s .c  o  m*/
        Log.d(TAG, mDebugId + ": Cleaning up current player");
    }
    synchronized (mErrorLock) {
        mError = null;
        if (mErrorRetriever != null) {
            mErrorRetriever.cancelRequestLocked(false);
            // Don't set to null as we may need to cancel again with true if
            // the object gets destroyed.
        }
    }
    mAudioManager.abandonAudioFocus(this);

    SurfaceHolder.Callback cb = mHolderCB;
    mHolderCB = null;
    SurfaceHolder holder = mHolder;
    mHolder = null;
    if (holder != null && cb != null) {
        holder.removeCallback(cb);
    }

    MediaPlayer player = mPlayer;
    mPlayer = null;
    if (player != null) {
        player.reset();
        player.release();
    }
}

From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java

@Override
public void onCompletion(MediaPlayer mediaPlayer) {

    // Inform UI that track completed playing.
    if (!mIsError && mListener != null)
        mListener.onTrackComplete();//  ww  w  . j  a  v  a  2s.c o m

    // Check if playback has reached the end of a track...
    if (!mIsError && mediaPlayer.getCurrentPosition() > 0) {
        mediaPlayer.reset();
        // ...if it reached than jump to the next one.
        playNext();
    }
}

From source file:ui.GalleryFileActivity.java

private void doPlay() {
    recordBtn.setText("?");
    if (!TextUtils.isEmpty(voicePath)) {
        try {//from ww  w .  j  av a2  s.c  o m
            if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                mMediaPlayer.stop();
                mMediaPlayer.reset();
                mHandler.sendEmptyMessage(2);
                return;
            }
            if (mMediaPlayer == null) {
                mMediaPlayer = new MediaPlayer();
            }
            mMediaPlayer.reset();
            mMediaPlayer.setDataSource(voicePath);
            mMediaPlayer.prepare();

        } catch (Exception e) {
            e.printStackTrace();
        }
        mMediaPlayer.start();
        mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                int time = mp.getDuration() / 1000;
                voice_file.setText(Util.formatLongToTimeStr(time));
                mHandler.post(updateThread);
            }
        });
        mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.stop();
                mp.reset();
                mHandler.sendEmptyMessage(2);

            }
        });

        mMediaPlayer.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int arg1, int arg2) {
                mp.stop();
                mp.reset();
                mHandler.sendEmptyMessage(2);
                return false;
            }
        });
    }

}

From source file:com.massivcode.androidmusicplayer.services.MusicService.java

@Override
public void onCompletion(MediaPlayer mp) {

    //   ?? ???  ? 

    mp.pause();//www.j ava2 s .c  o  m
    mp.reset();

    try {
        // ? ? ?? ?? .
        boolean isShuffle = DataBackupUtil.getInstance(getApplicationContext()).loadIsShuffle();
        //  ? ?.
        boolean isRepeat = DataBackupUtil.getInstance(getApplicationContext()).loadIsRepeat();
        Log.d(TAG, " ->  : " + isShuffle + "  : " + isRepeat);

        if (mCurrentPlaylist != null) {
            setNextMusicInfo(mp, isShuffle, isRepeat);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (mCurrentMusicInfo != null) {
            showNotification();
            sendMusicEvent();
        }
    }

}