private void setupVideoView() { listenerMux = new EMListenerMux(new MuxNotifier()); videoView.setOnCompletionListener(listenerMux); videoView.setOnPreparedListener(listenerMux); videoView.setOnErrorListener(listenerMux); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { videoView.setOnInfoListener(listenerMux); } }
/** * Returns if a video is currently in playback * * @return True if a video is playing */ public boolean isPlaying() { if (!useExo) { return videoView.isPlaying(); } return emExoPlayer.getPlayWhenReady(); }
/** * Moves the current video progress to the specified location. * * @param milliSeconds The time to move the playback to */ public void seekTo(int milliSeconds) { if (!useExo) { videoView.seekTo(milliSeconds); } else { emExoPlayer.seekTo(milliSeconds); } }
/** * Retrieves the current buffer percent of the video. If a video is not currently prepared or * buffering the value will be 0. This should only be called after the video is prepared (see * {@link #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)}) * * @return The integer percent that is buffered [0, 100] inclusive */ public int getBufferPercentage() { if (!useExo) { return videoView.getBufferPercentage(); } return emExoPlayer.getBufferedPercentage(); }
/** * Retrieves the current position of the audio playback. If an audio item is not currently in * playback then the value will be 0. This should only be called after the item is prepared (see * {@link #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)}) * * @return The millisecond value for the current position */ public long getCurrentPosition() { if (overridePosition) { return positionOffset + overriddenPositionStopWatch.getTime(); } if (!listenerMux.isPrepared()) { return 0; } if (!useExo) { return positionOffset + videoView.getCurrentPosition(); } return positionOffset + emExoPlayer.getCurrentPosition(); }
/** * Retrieves the duration of the current audio item. This should only be called after the item is * prepared (see {@link #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)}). If * {@link #overrideDuration(int)} is set then that value will be returned. * * @return The millisecond duration of the video */ public long getDuration() { if (overriddenDuration >= 0) { return overriddenDuration; } if (!listenerMux.isPrepared()) { return 0; } if (!useExo) { return videoView.getDuration(); } return emExoPlayer.getDuration(); }
/** * If a video is currently in playback then the playback will be suspended and and the * progressPoll will be stopped (see {@link #startProgressPoll()}) */ public void suspend() { if (!useExo) { videoView.suspend(); } else { emExoPlayer.release(); } if (defaultControls != null) { defaultControls.updatePlayPauseImage(false); defaultControls.show(); } playRequested = false; stopProgressPoll(); }
/** * If a video is currently in playback then the playback will be stopped and the progressPoll will * be stopped (see {@link #startProgressPoll()}) */ public void stopPlayback() { if (!useExo) { videoView.stopPlayback(); } else { emExoPlayer.setPlayWhenReady(false); } if (defaultControls != null) { defaultControls.updatePlayPauseImage(false); defaultControls.show(); } playRequested = false; stopProgressPoll(); }
/** * Starts the playback for the video specified in {@link #setVideoURI(android.net.Uri)} or {@link * #setVideoPath(String)}. This should be called after the VideoView is correctly prepared (see * {@link #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)}) */ public void start() { if (!useExo) { videoView.start(); } else { emExoPlayer.setPlayWhenReady(true); } if (defaultControls != null) { defaultControls.updatePlayPauseImage(true); defaultControls.hideDelayed(DefaultControls.DEFAULT_CONTROL_HIDE_DELAY); } playRequested = true; startProgressPoll(); }
@Override public void setOnTouchListener(OnTouchListener listener) { if (exoVideoSurfaceView != null) { exoVideoSurfaceView.setOnTouchListener(listener); } if (videoView != null) { videoView.setOnTouchListener(listener); } // Sets the onTouch listener for the shutters shutterLeft.setOnTouchListener(listener); shutterRight.setOnTouchListener(listener); shutterTop.setOnTouchListener(listener); shutterBottom.setOnTouchListener(listener); super.setOnTouchListener(listener); }
/** * Sets the Uri location for the video to play * * @param uri The video's Uri * @param defaultMediaType The MediaType to use when auto-detection fails */ public void setVideoURI(Uri uri, MediaUtil.MediaType defaultMediaType) { videoUri = uri; if (!useExo) { videoView.setVideoURI(uri); } else { if (uri == null) { emExoPlayer.replaceRenderBuilder(null); } else { emExoPlayer.replaceRenderBuilder( getRendererBuilder(VideoType.get(uri), uri, defaultMediaType)); listenerMux.setNotifiedCompleted(false); } // Makes sure the listeners get the onPrepared callback listenerMux.setNotifiedPrepared(false); emExoPlayer.seekTo(0); } if (defaultControls != null) { defaultControls.restartLoading(); } }