List of usage examples for android.media MediaPlayer seekTo
public void seekTo(int msec) throws IllegalStateException
From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java
private void stopMediaPlayers() { if (mContent == null) return;//from w w w . j a va 2 s . c o m final int numChildern = mContent.getChildCount(); for (int i = 0; i < numChildern; i++) { ImageView iv = (ImageView) mContent.getChildAt(i).findViewById(R.id.btn_play_pause); if (iv != null) { iv.setImageResource(android.R.drawable.ic_media_play); MediaPlayer mp = (MediaPlayer) iv.getTag(); if (mp != null && mp.isPlaying()) { mp.pause(); mp.seekTo(0); } } } }
From source file:edu.cmu.android.restaurant.MapFragment.java
/** * //ww w .j a v a 2s.c o m * Shaking: - User shake the mobile to find the coupon of the restaurant in * the detail fragment page - After shaking, the mobile vibrates for 500 ms * * */ @Override public void onSensorChanged(SensorEvent event) { int sensorType = event.sensor.getType(); float[] values = event.values; if (sensorType == Sensor.TYPE_ACCELEROMETER) { if ((Math.abs(values[0]) > 15 || Math.abs(values[1]) > 15 || Math.abs(values[2]) > 15)) { Log.d("sensor ", "X- values[0] = " + values[0]); Log.d("sensor ", "Y- values[1] = " + values[1]); Log.d("sensor ", "Z- values[2] = " + values[2]); findDeal(); dealDisplay(); /* audio play */ MediaPlayer mp = MediaPlayer.create(getActivity(), R.raw.coupon_audio); mp.seekTo(0); mp.start(); } } }
From source file:edu.cmu.android.restaurant.MapFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { /* menu : camera */ case Menu.FIRST + 1: try {/*from ww w.j av a2 s . c o m*/ Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(i, Activity.DEFAULT_KEYS_DIALER); } catch (Exception e) { Log.d("Detail", "Cemara onClick error."); } finally { if (getActivity().getResources() .getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT) { getActivity().setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); } } break; /* menu : coupon */ case Menu.FIRST + 2: /* display the deal in a dialog */ findDeal(); dealDisplay(); /* audio play */ MediaPlayer mp = MediaPlayer.create(getActivity(), R.raw.coupon_audio); mp.seekTo(0); mp.start(); break; /* Menu : about */ case Menu.FIRST + 3: Builder builder3 = new AlertDialog.Builder(getActivity()); builder3.setTitle("About US"); builder3.setMessage(ABOUT_CONTENT); builder3.setPositiveButton("Return", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); break; } return false; }
From source file:org.dharmaseed.android.PlayTalkActivity.java
@Override public void onStopTrackingTouch(SeekBar seekBar) { userDraggingSeekBar = false;/*from www . ja v a 2 s . c om*/ talkPlayerFragment.setUserSeekBarPosition(userSeekBarPosition); MediaPlayer mediaPlayer = talkPlayerFragment.getMediaPlayer(); try { mediaPlayer.seekTo(userSeekBarPosition); } catch (IllegalStateException e) { } }
From source file:com.shahenlibrary.VideoPlayer.VideoPlayerView.java
@Override public void onCompletion(MediaPlayer mp) { if (mp == null) { return;/*from ww w . j av a 2 s . c o m*/ } Log.d(LOG_TAG, "onCompletion: isLooping " + mp.isLooping()); if (mLooping) { Log.d(LOG_TAG, "onCompletion: seek to start at : " + videoStartAt); mp.seekTo(videoStartAt); } }
From source file:org.dharmaseed.android.PlayTalkActivity.java
public void rewindButtonClicked(View view) { MediaPlayer mediaPlayer = talkPlayerFragment.getMediaPlayer(); int currentPosition = mediaPlayer.getCurrentPosition(); int newPosition = Math.max(currentPosition - 15000, 0); mediaPlayer.seekTo(newPosition); }
From source file:org.dharmaseed.android.PlayTalkActivity.java
public void fastForwardButtonClicked(View view) { MediaPlayer mediaPlayer = talkPlayerFragment.getMediaPlayer(); int currentPosition = mediaPlayer.getCurrentPosition(); int newPosition = Math.min(currentPosition + 15000, mediaPlayer.getDuration()); mediaPlayer.seekTo(newPosition); }
From source file:com.owncloud.android.media.MediaService.java
/** * Called when media player is done preparing. * * Time to start./*from ww w . j a v a 2s .c om*/ */ public void onPrepared(MediaPlayer player) { mState = State.PLAYING; updateNotification(String.format(getString(R.string.media_state_playing), mFile.getFileName())); if (mMediaController != null) { mMediaController.setEnabled(true); } player.seekTo(mStartPosition); configAndStartMediaPlayer(); if (!mPlayOnPrepared) { processPauseRequest(); } if (mMediaController != null) { mMediaController.updatePausePlay(); } }
From source file:com.owncloud.android.media.MediaService.java
/** Called when media player is done playing current song. */ public void onCompletion(MediaPlayer player) { Toast.makeText(this, String.format(getString(R.string.media_event_done, mFile.getFileName())), Toast.LENGTH_LONG).show();//from w ww . j a v a 2 s . com if (mMediaController != null) { // somebody is still bound to the service player.seekTo(0); processPauseRequest(); mMediaController.updatePausePlay(); } else { // nobody is bound processStopRequest(true); } return; }
From source file:com.android.onemedia.playback.LocalRenderer.java
/** * Seek to a given position in the media. If the seek succeeded or will be * performed when loading is complete returns true. If the position is not * in range or the player will never be ready returns false. * * @param position The position to seek to in milliseconds * @return true if playback was moved or will be moved when ready *///from www. ja va2 s . c o m @Override public boolean onSeekTo(int position) { MediaPlayer player = mPlayer; if (player != null && (mState & CAN_SEEK) != 0) { if (position < 0 || position >= getDuration()) { return false; } else { if (mState == STATE_ENDED) { player.start(); player.pause(); setState(STATE_PAUSED); } player.seekTo(position); } } else if ((mState & CAN_READY_SEEK) != 0) { mSeekOnReady = position; } else { return false; } return true; }