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

The following examples show how to use android.media.MediaPlayer#pause() . 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: BottomBarManager.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    int clickedId = intent.getIntExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, -1);
    Toast.makeText(context, "Current URL " + intent.getDataString() + "\nClicked id "
            + clickedId, Toast.LENGTH_SHORT).show();

    CustomTabsSession session = SessionHelper.getCurrentSession();
    if (session == null) return;

    if (clickedId == R.id.play_pause) {
        MediaPlayer player = sMediaPlayerWeakRef.get();
        if (player != null) {
            boolean isPlaying = player.isPlaying();
            if (isPlaying) player.pause();
            else player.start();
            // Update the play/stop icon to respect the current state.
            session.setSecondaryToolbarViews(createRemoteViews(context, isPlaying), getClickableIDs(),
                    getOnClickPendingIntent(context));
        }
    } else if (clickedId == R.id.cover) {
        // Clicking on the cover image will dismiss the bottom bar.
        session.setSecondaryToolbarViews(null, null, null);
    }
}
 
Example 2
Source File: RNSoundModule.java    From react-native-sound with MIT License 6 votes vote down vote up
@ReactMethod
public void stop(final Double key, final Callback callback) {
  MediaPlayer player = this.playerPool.get(key);
  if (player != null && player.isPlaying()) {
    player.pause();
    player.seekTo(0);
  }

  // Release audio focus in Android system
  if (!this.mixWithOthers && key == this.focusedPlayerKey) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.abandonAudioFocus(this);
  }

  callback.invoke();
}
 
Example 3
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 4
Source File: MNViderPlayer.java    From MNVideoPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPrepared(final MediaPlayer mediaPlayer) {

    mediaPlayer.start(); // 开始播放
    //是否开始播放
    if (!isPlaying) {
        mediaPlayer.pause();
        mn_iv_play_pause.setImageResource(R.drawable.mn_player_play);
    } else {
        mn_iv_play_pause.setImageResource(R.drawable.mn_player_pause);
    }
    isPrepare = true;
    // 把得到的总长度和进度条的匹配
    mn_seekBar.setMax(mediaPlayer.getDuration());
    mn_tv_time.setText(PlayerUtils.converLongTimeToStr(mediaPlayer.getCurrentPosition()) + "/" + PlayerUtils.converLongTimeToStr(mediaPlayer.getDuration()));
    //延时:避免出现上一个视频的画面闪屏
    myHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            initBottomMenuState();
            mn_player_rl_progress.setVisibility(View.GONE);

            //跳转指定位置
            if (video_position > 0) {
                Log.i(TAG, "onPrepared---video_position:" + video_position);
                MNViderPlayer.this.mediaPlayer.seekTo(video_position);
                video_position = 0;
            }
        }
    }, 500);
    //适配大小
    fitVideoSize();

    //恢复显示,隐藏列缩图
    mn_palyer_surfaceView.setAlpha(1);
    iv_video_thumbnail.setVisibility(View.GONE);

}
 
Example 5
Source File: RNSoundModule.java    From react-native-sound with MIT License 5 votes vote down vote up
@ReactMethod
public void pause(final Double key, final Callback callback) {
  MediaPlayer player = this.playerPool.get(key);
  if (player != null && player.isPlaying()) {
    player.pause();
  }

  if (callback != null) {
    callback.invoke();
  }
}
 
Example 6
Source File: SoundManager.java    From Camdroid with Apache License 2.0 5 votes vote down vote up
private void stop(final MediaPlayer mp) {
	if (mp == null)
		return;

	final Handler handler = new Handler();
	final float currentVolume = SoundManager.this.currentVolume();

	synchronized (mp) {
		Runnable mute = new Runnable() {
			float volume = currentVolume;

			@Override
			public void run() {
				boolean playing = false;
				try {
					playing = mp.isPlaying();
				} catch (IllegalStateException e) {
					return;
				}
				if (playing) {
					if (this.volume > 0.0f) {
						this.volume -= .25f;
						Log.d(TAG, "mp: " + mp.getAudioSessionId()
								+ " mute to: " + this.volume);
						mp.setVolume(this.volume, this.volume);
						handler.postDelayed(this, 250);
					} else {
						Log.d(TAG, "mp: " + mp.getAudioSessionId()
								+ " pause");
						mp.pause();
						mp.seekTo(0);
					}
				}
			}
		};

		handler.post(mute);
	}
}