public AbsControlPanel getCurrentControlPanel() { VideoView currentVideoView = getCurrentVideoView(); if (currentVideoView == null) return null; return currentVideoView.getControlPanel(); }
/** * 拦截返回键 */ public boolean backPress() { Log.i(TAG, "backPress"); try { VideoView currentVideoView = getCurrentVideoView(); if (currentVideoView != null && currentVideoView.getWindowType() == VideoView.WindowType.FULLSCREEN) {//退出全屏 currentVideoView.exitFullscreen(); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
@Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) { if (getCurrentVideoView() == null) return; Log.i(TAG, "onSurfaceTextureAvailable [" + "] "); if (this.surfaceTexture == null) { this.surfaceTexture = surfaceTexture; prepare(); } else { textureView.setSurfaceTexture(this.surfaceTexture); } }
private void OpenVolume() { try { if (mediaPlayer != null) { VideoView currentFloor = MediaPlayerManager.instance().getCurrentVideoView(); if (currentFloor == null) return; Context context = currentFloor.getContext(); if (context == null) return; AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE); if (audioManager == null) return; float streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = streamVolume * 1.000f / maxVolume; mediaPlayer.setVolume(volume, volume); } } catch (Exception e) { e.printStackTrace(); } }
private void OpenVolume() { try { if (mediaPlayer != null) { VideoView currentFloor = MediaPlayerManager.instance().getCurrentVideoView(); if (currentFloor == null) return; Context context = currentFloor.getContext(); if (context == null) return; AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE); if (audioManager == null) return; float streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = streamVolume * 1.000f / maxVolume; mediaPlayer.setVolume(volume); } } catch (Exception e) { e.printStackTrace(); } }
private void OpenVolume() { try { if (mediaPlayer != null) { VideoView currentFloor = MediaPlayerManager.instance().getCurrentVideoView(); if (currentFloor == null) return; Context context = currentFloor.getContext(); if (context == null) return; AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE); if (audioManager == null) return; float streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = streamVolume * 1.000f / maxVolume; mediaPlayer.setVolume(volume, volume); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { if (MediaPlayerManager.instance().getCurrentVideoView() == mTarget && MediaPlayerManager.instance().isPlaying()) { hideUI(layout_bottom, layout_top, start); } } };
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mDetachedListener != null) { if (isCurrentPlaying() && this == MediaPlayerManager.instance().getCurrentVideoView()) { mDetachedListener.onDetached(this); } } }
/** * 竖屏 */ private void onOrientationPortrait() { VideoView videoView = MediaPlayerManager.instance().getCurrentVideoView(); if (videoView != null) { if (currentOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { return; } if ((currentOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || currentOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) && !(videoView.getWindowType() == VideoView.WindowType.FULLSCREEN)) { currentOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; return; } currentOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; if (mOrientationChangeListener != null) { mOrientationChangeListener.onOrientationPortrait(videoView); } } }
@Override public void run() { if (mPlayerState == PlayerState.PLAYING || mPlayerState == PlayerState.PAUSED) { long position = getCurrentPositionWhenPlaying(); long duration = getDuration(); int progress = (int) (position * 100 / (duration == 0 ? 1 : duration)); VideoView currentVideoView = getCurrentVideoView(); if (currentVideoView == null) return; AbsControlPanel controlPanel = currentVideoView.getControlPanel(); if (controlPanel != null) { controlPanel.onProgressUpdate(progress, position, duration); } } } }
/** * 反向横屏(屏幕右边朝上) */ private void onOrientationReverseLandscape() { VideoView videoView = MediaPlayerManager.instance().getCurrentVideoView(); if (videoView != null) { if (currentOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) return; if (currentOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && (videoView.getWindowType() == VideoView.WindowType.FULLSCREEN)) { currentOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; return; } currentOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; if (videoView.getWindowType() != VideoView.WindowType.FULLSCREEN) { if (mOrientationChangeListener != null) { mOrientationChangeListener.onOrientationReverseLandscape(videoView); } } } }
/** * 横屏(屏幕左边朝上) */ private void onOrientationLandscape() { VideoView videoView = MediaPlayerManager.instance().getCurrentVideoView(); if (videoView != null) { if (currentOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) return; if (currentOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && (videoView.getWindowType() == VideoView.WindowType.FULLSCREEN)) { currentOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; return; } currentOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; if (videoView.getWindowType() != VideoView.WindowType.FULLSCREEN) { if (mOrientationChangeListener != null) { mOrientationChangeListener.onOrientationLandscape(videoView); } } } }
public void updateState(PlayerState playerState) { Log.i(TAG, "updateState [" + playerState.name() + "] "); mPlayerState = playerState; switch (mPlayerState) { case PLAYING: case PAUSED: startProgressTimer(); break; case ERROR: case IDLE: case PLAYBACK_COMPLETED: cancelProgressTimer(); break; } VideoView currentFloor = getCurrentVideoView(); if (currentFloor != null && currentFloor.isCurrentPlaying()) { AbsControlPanel controlPanel = currentFloor.getControlPanel(); if (controlPanel != null) { controlPanel.notifyStateChange();//通知当前的控制面板改变布局 } } }
@Override public void onDetached(VideoView videoView) { if (videoView.isCurrentPlaying() && videoView == MediaPlayerManager.instance().getCurrentVideoView()) { //开启小窗 VideoView tinyVideoView = new VideoView(videoView.getContext()); //set url and data tinyVideoView.setUp(videoView.getDataSourceObject(), VideoView.WindowType.TINY, videoView.getData()); //set control panel ControlPanel controlPanel = new ControlPanel(videoView.getContext()); tinyVideoView.setControlPanel(controlPanel); //set cover ImageView coverView = controlPanel.findViewById(R.id.video_cover); Glide.with(controlPanel.getContext()).load(((VideoBean) videoView.getData()).getImage()).into(coverView); //set parent tinyVideoView.setParentVideoView(videoView); //set LayoutParams FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(16 * 45, 9 * 45); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; layoutParams.setMargins(0, 0, 30, 100); //start tiny window tinyVideoView.startTinyWindow(layoutParams); } } });
VideoView currentVideoView = MediaPlayerManager.instance().getCurrentVideoView(); if (currentVideoView != null && currentVideoView != this) { if (getWindowType() != VideoView.WindowType.TINY) {
return; VideoView currentVideoView = MediaPlayerManager.instance().getCurrentVideoView(); if (isCurrentPlaying()) {