### Switch Player Cores Globally (Java) Source: https://context7.com/doikki/dkvideoplayer/llms.txt This Java snippet illustrates how to perform a global switch of the player core by configuring the VideoViewManager within the Application class. This change affects all VideoView instances unless overridden individually. The example shows setting ExoPlayer as the default player factory. ```java // Global switch (in Application class) VideoViewManager.setConfig(VideoViewConfig.newBuilder() .setPlayerFactory(ExoMediaPlayerFactory.create()) .build()); ``` -------------------------------- ### Basic Video Playback Controls in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt This snippet demonstrates fundamental video playback operations using the VideoView class. It covers starting, pausing, resuming, replaying, and releasing the player. It also includes methods for controlling playback progress and looping. ```java VideoView videoView = findViewById(R.id.player); // Basic playback controls videoView.start(); // Start/resume playback videoView.pause(); // Pause playback videoView.resume(); // Resume from pause videoView.replay(true); // Replay video (true = from beginning) videoView.release(); // Release player resources // Loop playback videoView.setLooping(true); ``` -------------------------------- ### Switch Player Cores for Individual VideoView (Java) Source: https://context7.com/doikki/dkvideoplayer/llms.txt This Java snippet shows how to temporarily switch the player core for a specific VideoView instance before starting playback. It overrides the global configuration by setting a new player factory directly on the VideoView object. The available options include IjkPlayer, ExoPlayer, and the default Android MediaPlayer. ```java // Temporary switch for a specific VideoView (must call before start()) VideoView videoView = findViewById(R.id.player); // Use IjkPlayer decoder videoView.setPlayerFactory(IjkPlayerFactory.create()); // Use ExoPlayer decoder // videoView.setPlayerFactory(ExoMediaPlayerFactory.create()); // Use Android MediaPlayer decoder (default) // videoView.setPlayerFactory(AndroidMediaPlayerFactory.create()); videoView.setUrl("https://example.com/video.mp4"); videoView.start(); ``` -------------------------------- ### Basic Video Playback with VideoView in Android Source: https://context7.com/doikki/dkvideoplayer/llms.txt This Java code demonstrates basic video playback using DKVideoPlayer's VideoView. It shows how to set a video URL, configure a standard controller with a title, start playback, and handle lifecycle events like pause, resume, and release to prevent memory leaks. It also includes handling the back button for fullscreen exit. ```java // Layout XML (activity_player.xml) // public class PlayerActivity extends AppCompatActivity { private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); videoView = findViewById(R.id.player); // Set video URL videoView.setUrl("https://example.com/video.mp4"); // Optional: Set URL with custom headers // Map headers = new HashMap<>(); // headers.put("User-Agent", "CustomUserAgent"); // videoView.setUrl("https://example.com/video.mp4", headers); // Create and configure standard controller StandardVideoController controller = new StandardVideoController(this); controller.addDefaultControlComponent("Video Title", false); // false = VOD, true = Live videoView.setVideoController(controller); // Start playback videoView.start(); } @Override protected void onPause() { super.onPause(); videoView.pause(); } @Override protected void onResume() { super.onResume(); videoView.resume(); } @Override protected void onDestroy() { super.onDestroy(); videoView.release(); // Must call to prevent memory leaks } @Override public void onBackPressed() { // Handle fullscreen exit before activity exit if (!videoView.onBackPressed()) { super.onBackPressed(); } } } ``` -------------------------------- ### Playing Videos from Various Sources in Android Source: https://context7.com/doikki/dkvideoplayer/llms.txt Demonstrates how to play videos from different sources like URLs, local file paths, assets, raw resources, and content URIs using the VideoView component. It covers setting URLs, AssetFileDescriptors, and raw resource URIs, along with starting playback. Requires Android SDK and the DKVideoPlayer library. ```java VideoView videoView = findViewById(R.id.player); // Play from URL videoView.setUrl("https://example.com/video.mp4"); // Play from local file path videoView.setUrl("file:///sdcard/Movies/video.mp4"); // or videoView.setUrl("/sdcard/Movies/video.mp4"); // Play from assets folder try { AssetFileDescriptor afd = getAssets().openFd("video.mp4"); videoView.setAssetFileDescriptor(afd); } catch (IOException e) { e.printStackTrace(); } // Play from raw resources String rawUri = "android.resource://" + getPackageName() + "/" + R.raw.video; videoView.setUrl(rawUri); // Play from content URI (e.g., from file picker) Uri contentUri = data.getData(); // From onActivityResult videoView.setUrl(contentUri.toString()); videoView.start(); ``` -------------------------------- ### Fullscreen and Picture-in-Picture (PiP) Control in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Manage fullscreen and picture-in-picture modes for video playback. This includes starting and stopping both modes, and checking their current status. The PiP mode allows for optional size configuration. ```java VideoView videoView = findViewById(R.id.player); // Fullscreen videoView.startFullScreen(); videoView.stopFullScreen(); boolean isFullscreen = videoView.isFullScreen(); // Picture-in-picture (tiny screen) videoView.setTinyScreenSize(new int[]{400, 225}); // Optional: set size videoView.startTinyScreen(); videoView.stopTinyScreen(); boolean isTiny = videoView.isTinyScreen(); ``` -------------------------------- ### Video Screenshot and Skip Position in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Capture a screenshot of the current video frame and set a specific starting position for playback. Note that screenshot functionality is limited to TextureView, not SurfaceView. ```java VideoView videoView = findViewById(R.id.player); // Screenshot (only works with TextureView, not SurfaceView) Bitmap screenshot = videoView.doScreenShot(); // Skip to position when starting playback videoView.skipPositionWhenPlay(10000); // Start at 10 seconds ``` -------------------------------- ### Playback Controls API Source: https://context7.com/doikki/dkvideoplayer/llms.txt This API provides methods to control video playback, such as starting, pausing, seeking, adjusting volume, changing playback speed, managing screen modes (fullscreen, PiP), and querying playback status. ```APIDOC ## Playback Controls API ### Description Control video playback with various methods including seeking, speed control, volume, and screen modes. ### Methods #### Basic Playback - `start()`: Start or resume playback. - `pause()`: Pause playback. - `resume()`: Resume playback from a paused state. - `replay(boolean fromBeginning)`: Replay the video. Set `fromBeginning` to `true` to restart from the start. - `release()`: Release player resources. #### Progress Control - `getDuration()`: Returns the total duration of the video in milliseconds. - `getCurrentPosition()`: Returns the current playback position in milliseconds. - `getBufferedPercentage()`: Returns the buffer percentage (0-100). - `seekTo(long position)`: Seeks to a specific position in milliseconds. #### Playback Speed - `setSpeed(float speed)`: Sets the playback speed (e.g., 1.5f for 1.5x speed). Requires API 23+ for MediaPlayer, always works with Ijk/Exo. - `getSpeed()`: Returns the current playback speed. #### Volume Control - `setMute(boolean mute)`: Mutes or unmutes the audio. Set `mute` to `true` to mute. - `isMute()`: Returns `true` if the audio is muted, `false` otherwise. - `setVolume(float leftVolume, float rightVolume)`: Sets the volume for the left and right audio channels (values between 0.0 and 1.0). #### Loop Playback - `setLooping(boolean looping)`: Enables or disables loop playback. Set `looping` to `true` to enable. #### Screen Scale Types - `setScreenScaleType(int scaleType)`: Sets the screen scaling type. Supported types include: - `VideoView.SCREEN_SCALE_DEFAULT`: Fit with aspect ratio. - `VideoView.SCREEN_SCALE_16_9`: 16:9 aspect ratio (may distort). - `VideoView.SCREEN_SCALE_4_3`: 4:3 aspect ratio (may distort). - `VideoView.SCREEN_SCALE_MATCH_PARENT`: Fill the container (may distort). - `VideoView.SCREEN_SCALE_ORIGINAL`: Original video size (may crop). - `VideoView.SCREEN_SCALE_CENTER_CROP`: Center crop (may crop). #### Fullscreen Mode - `startFullScreen()`: Enters fullscreen mode. - `stopFullScreen()`: Exits fullscreen mode. - `isFullScreen()`: Returns `true` if the player is in fullscreen mode, `false` otherwise. #### Picture-in-Picture (PiP) Mode - `setTinyScreenSize(int[] size)`: Optionally sets the size for the PiP window (e.g., `new int[]{400, 225}`). - `startTinyScreen()`: Enters PiP mode. - `stopTinyScreen()`: Exits PiP mode. - `isTinyScreen()`: Returns `true` if the player is in PiP mode, `false` otherwise. #### Video Rotation and Mirroring - `setRotation(int rotation)`: Rotates the video by the specified degrees (e.g., 90). - `setMirrorRotation(boolean mirror)`: Mirrors the video horizontally if `mirror` is `true`. #### Screenshot - `doScreenShot()`: Captures a screenshot of the current video frame. Only works with `TextureView`, not `SurfaceView`. Returns a `Bitmap`. #### Skip Position - `skipPositionWhenPlay(long position)`: Sets a position in milliseconds to skip to when playback starts. #### Status Queries - `isPlaying()`: Returns `true` if the video is currently playing, `false` otherwise. - `getCurrentPlayerState()`: Returns the current player state (e.g., `PLAYER_NORMAL`, `PLAYER_FULL_SCREEN`). - `getCurrentPlayState()`: Returns the current playback state (e.g., `STATE_IDLE`, `STATE_PLAYING`). - `getTcpSpeed()`: Returns the network speed in bytes per second. ### Request Example ```java VideoView videoView = findViewById(R.id.player); // Basic playback controls videoView.start(); // Start/resume playback videoView.pause(); // Pause playback videoView.resume(); // Resume from pause videoView.replay(true); // Replay video (true = from beginning) videoView.release(); // Release player resources // Progress control long duration = videoView.getDuration(); // Get total duration in ms long position = videoView.getCurrentPosition(); // Get current position in ms int buffered = videoView.getBufferedPercentage(); // Get buffer percentage (0-100) videoView.seekTo(30000); // Seek to 30 seconds // Playback speed (requires API 23+ for MediaPlayer, always works with Ijk/Exo) videoView.setSpeed(1.5f); // 1.5x speed float speed = videoView.getSpeed(); // Get current speed // Volume control videoView.setMute(true); // Mute audio boolean muted = videoView.isMute(); // Check if muted videoView.setVolume(0.5f, 0.5f); // Set left/right channel volume (0.0-1.0) // Loop playback videoView.setLooping(true); // Screen scale types videoView.setScreenScaleType(VideoView.SCREEN_SCALE_DEFAULT); // Default (fit with aspect ratio) videoView.setScreenScaleType(VideoView.SCREEN_SCALE_16_9); // 16:9 (may distort) videoView.setScreenScaleType(VideoView.SCREEN_SCALE_4_3); // 4:3 (may distort) videoView.setScreenScaleType(VideoView.SCREEN_SCALE_MATCH_PARENT); // Fill container (may distort) videoView.setScreenScaleType(VideoView.SCREEN_SCALE_ORIGINAL); // Original size (may crop) videoView.setScreenScaleType(VideoView.SCREEN_SCALE_CENTER_CROP); // Center crop (may crop) // Fullscreen videoView.startFullScreen(); videoView.stopFullScreen(); boolean isFullscreen = videoView.isFullScreen(); // Picture-in-picture (tiny screen) videoView.setTinyScreenSize(new int[]{400, 225}); // Optional: set size videoView.startTinyScreen(); videoView.stopTinyScreen(); boolean isTiny = videoView.isTinyScreen(); // Video rotation and mirroring videoView.setRotation(90); // Rotate video 90 degrees videoView.setMirrorRotation(true); // Mirror horizontally // Screenshot (only works with TextureView, not SurfaceView) Bitmap screenshot = videoView.doScreenShot(); // Skip to position when starting playback videoView.skipPositionWhenPlay(10000); // Start at 10 seconds // Status queries boolean isPlaying = videoView.isPlaying(); int playerState = videoView.getCurrentPlayerState(); // PLAYER_NORMAL, PLAYER_FULL_SCREEN, etc. int playState = videoView.getCurrentPlayState(); // STATE_IDLE, STATE_PLAYING, etc. long tcpSpeed = videoView.getTcpSpeed(); // Network speed in bytes/s ``` ``` -------------------------------- ### Implement Custom Video Controller with Components in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt This Java code snippet shows how to create a custom video controller for DKVideoPlayer by adding various UI components. It demonstrates setting up a VideoView, configuring a StandardVideoController, and adding components like PrepareView, CompleteView, ErrorView, TitleView, ControlView (VOD/Live), and GestureView. It also includes configuration for gesture controls and playback behavior. ```java public class CustomPlayerActivity extends AppCompatActivity { private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); videoView = findViewById(R.id.player); // Create controller with gesture support StandardVideoController controller = new StandardVideoController(this); // Enable auto-rotation based on device orientation controller.setEnableOrientation(true); // Add individual components PrepareView prepareView = new PrepareView(this); prepareView.setClickStart(); // Click thumbnail to start playback ImageView thumb = prepareView.findViewById(R.id.thumb); Glide.with(this).load("https://example.com/thumbnail.jpg").into(thumb); controller.addControlComponent(prepareView); // Add completion view (shown when video ends) controller.addControlComponent(new CompleteView(this)); // Add error view (shown on playback error) controller.addControlComponent(new ErrorView(this)); // Add title bar TitleView titleView = new TitleView(this); titleView.setTitle("My Video"); controller.addControlComponent(titleView); // Add control bar (VOD or Live) boolean isLive = false; if (isLive) { controller.addControlComponent(new LiveControlView(this)); } else { VodControlView vodControlView = new VodControlView(this); // vodControlView.showBottomProgress(false); // Hide bottom progress bar controller.addControlComponent(vodControlView); } // Add gesture control view (brightness/volume/progress) controller.addControlComponent(new GestureView(this)); // Configure gesture settings controller.setCanChangePosition(!isLive); // Disable seek for live streams controller.setGestureEnabled(true); // Enable gesture controls controller.setEnableInNormal(false); // Disable gestures in portrait mode controller.setDoubleTapTogglePlayEnabled(true); // Double-tap to play/pause // Set auto-hide timeout (default: 4000ms) controller.setDismissTimeout(5000); videoView.setVideoController(controller); videoView.setUrl("https://example.com/video.mp4"); videoView.start(); } } ``` -------------------------------- ### Implement Custom Control Component in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Create custom UI components for DKVideoPlayer by implementing the IControlComponent interface. This allows components to respond to player state changes and manage their visibility and progress updates. It requires a Context and inflates a custom layout. ```java public class CustomControlComponent extends FrameLayout implements IControlComponent { private ControlWrapper controlWrapper; private TextView statusText; private ProgressBar progressBar; public CustomControlComponent(@NonNull Context context) { super(context); init(); } private void init() { LayoutInflater.from(getContext()).inflate(R.layout.custom_component, this); statusText = findViewById(R.id.status_text); progressBar = findViewById(R.id.progress); } @Override public void attach(@NonNull ControlWrapper controlWrapper) { this.controlWrapper = controlWrapper; } @Nullable @Override public View getView() { return this; // Return this since component is a View } @Override public void onVisibilityChanged(boolean isVisible, Animation anim) { // Called when controller visibility changes (show/hide) if (isVisible) { setVisibility(VISIBLE); if (anim != null) startAnimation(anim); } else { setVisibility(GONE); if (anim != null) startAnimation(anim); } } @Override public void onPlayStateChanged(int playState) { switch (playState) { case VideoView.STATE_PLAYING: statusText.setText("Playing"); progressBar.setVisibility(GONE); break; case VideoView.STATE_PAUSED: statusText.setText("Paused"); break; case VideoView.STATE_BUFFERING: statusText.setText("Buffering..."); progressBar.setVisibility(VISIBLE); break; case VideoView.STATE_ERROR: statusText.setText("Error"); break; } } @Override public void onPlayerStateChanged(int playerState) { // Handle fullscreen/normal/tiny screen state changes if (playerState == VideoView.PLAYER_FULL_SCREEN) { // Adjust layout for fullscreen } } @Override public void setProgress(int duration, int position) { // Called every second with current progress String time = String.format("%02d:%02d / %02d:%02d", position / 60000, (position / 1000) % 60, duration / 60000, (duration / 1000) % 60); statusText.setText(time); } @Override public void onLockStateChanged(boolean isLocked) { // Called when screen is locked/unlocked } } // Usage: StandardVideoController controller = new StandardVideoController(this); controller.addControlComponent(new CustomControlComponent(this)); // Add as a "dissociate" component (independent of controller, useful for list items) // CustomControlComponent component = new CustomControlComponent(this); // controller.addControlComponent(component, true); // true = dissociate ``` -------------------------------- ### Video Progress and Buffering Control in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Manage video playback progress and buffering status. This includes retrieving the total duration, current playback position, and buffered percentage. It also shows how to seek to a specific position in the video. ```java VideoView videoView = findViewById(R.id.player); // Progress control long duration = videoView.getDuration(); // Get total duration in ms long position = videoView.getCurrentPosition(); // Get current position in ms int buffered = videoView.getBufferedPercentage(); // Get buffer percentage (0-100) videoView.seekTo(30000); // Seek to 30 seconds ``` -------------------------------- ### Add DKVideoPlayer Dependencies to Gradle Source: https://context7.com/doikki/dkvideoplayer/llms.txt This snippet shows how to add the necessary DKVideoPlayer dependencies to your project's build.gradle file. It includes core libraries, UI components, and optional decoder support for ExoPlayer and IjkPlayer, as well as a video caching module. ```gradle repositories { mavenCentral() } dependencies { // Required: Core player library with default Android MediaPlayer implementation 'xyz.doikki.android.dkplayer:dkplayer-java:3.3.7' // Optional: Standard video controller UI components implementation 'xyz.doikki.android.dkplayer:dkplayer-ui:3.3.7' // Optional: ExoPlayer decoder support implementation 'xyz.doikki.android.dkplayer:player-exo:3.3.7' // Optional: IjkPlayer decoder support implementation 'xyz.doikki.android.dkplayer:player-ijk:3.3.7' // Optional: Video caching and TikTok-style preloading implementation 'xyz.doikki.android.dkplayer:videocache:3.3.7' } ``` -------------------------------- ### Video Rotation and Mirroring in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Apply transformations to the video display, such as rotation and mirroring. This allows for adjusting the video orientation by degrees or flipping it horizontally. ```java VideoView videoView = findViewById(R.id.player); // Video rotation and mirroring videoView.setRotation(90); // Rotate video 90 degrees videoView.setMirrorRotation(true); // Mirror horizontally ``` -------------------------------- ### AndroidManifest Configuration for Video Player Activity Source: https://context7.com/doikki/dkvideoplayer/llms.txt Configuration for an Android Activity to properly handle configuration changes, such as screen orientation and size, ensuring smooth fullscreen video playback. Includes an optional permission for floating window functionality. ```xml ``` -------------------------------- ### Video Screen Scale Types in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Configure how the video is scaled within its container. Various scale types are available, including default fitting, aspect ratio preservation (16:9, 4:3), filling the parent, original size, and center cropping. ```java VideoView videoView = findViewById(R.id.player); // Screen scale types videoView.setScreenScaleType(VideoView.SCREEN_SCALE_DEFAULT); videoView.setScreenScaleType(VideoView.SCREEN_SCALE_16_9); videoView.setScreenScaleType(VideoView.SCREEN_SCALE_4_3); videoView.setScreenScaleType(VideoView.SCREEN_SCALE_MATCH_PARENT); videoView.setScreenScaleType(VideoView.SCREEN_SCALE_ORIGINAL); videoView.setScreenScaleType(VideoView.SCREEN_SCALE_CENTER_CROP); ``` -------------------------------- ### Monitor Player and Playback States with OnStateChangeListener in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt This Java code snippet demonstrates how to use the OnStateChangeListener interface to monitor both player state changes (like screen mode) and playback state changes (like playing, paused, or error). It logs the current state and retrieves video dimensions when playing. It also shows an alternative using SimpleOnStateChangeListener for specific event handling and mentions methods for listener management. ```java VideoView videoView = findViewById(R.id.player); videoView.addOnStateChangeListener(new VideoView.OnStateChangeListener() { @Override public void onPlayerStateChanged(int playerState) { switch (playerState) { case VideoView.PLAYER_NORMAL: Log.d("Player", "Normal mode (portrait)"); break; case VideoView.PLAYER_FULL_SCREEN: Log.d("Player", "Fullscreen mode"); break; case VideoView.PLAYER_TINY_SCREEN: Log.d("Player", "Picture-in-picture mode"); break; } } @Override public void onPlayStateChanged(int playState) { switch (playState) { case VideoView.STATE_IDLE: Log.d("Player", "Idle - Player not initialized"); break; case VideoView.STATE_PREPARING: Log.d("Player", "Preparing - Loading video"); break; case VideoView.STATE_PREPARED: Log.d("Player", "Prepared - Ready to play"); break; case VideoView.STATE_PLAYING: Log.d("Player", "Playing"); // Get video dimensions int[] videoSize = videoView.getVideoSize(); Log.d("Player", "Video size: " + videoSize[0] + "x" + videoSize[1]); break; case VideoView.STATE_PAUSED: Log.d("Player", "Paused"); break; case VideoView.STATE_BUFFERING: Log.d("Player", "Buffering..."); break; case VideoView.STATE_BUFFERED: Log.d("Player", "Buffering complete"); break; case VideoView.STATE_PLAYBACK_COMPLETED: Log.d("Player", "Playback completed"); break; case VideoView.STATE_ERROR: Log.d("Player", "Error occurred"); break; case VideoView.STATE_START_ABORT: Log.d("Player", "Playback aborted (e.g., mobile network warning)"); break; } } }); // Alternative: Use SimpleOnStateChangeListener to override only needed methods videoView.addOnStateChangeListener(new VideoView.SimpleOnStateChangeListener() { @Override public void onPlayStateChanged(int playState) { if (playState == VideoView.STATE_ERROR) { Toast.makeText(context, "Playback error", Toast.LENGTH_SHORT).show(); } } }); // Remove specific listener // videoView.removeOnStateChangeListener(listener); // Remove all listeners // videoView.clearOnStateChangeListeners(); ``` -------------------------------- ### Video Player Status Queries in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Query the current state and status of the video player. This includes checking if the video is playing, retrieving detailed player states, playback states, and network speed. ```java VideoView videoView = findViewById(R.id.player); // Status queries boolean isPlaying = videoView.isPlaying(); int playerState = videoView.getCurrentPlayerState(); // PLAYER_NORMAL, PLAYER_FULL_SCREEN, etc. int playState = videoView.getCurrentPlayState(); // STATE_IDLE, STATE_PLAYING, etc. long tcpSpeed = videoView.getTcpSpeed(); // Network speed in bytes/s ``` -------------------------------- ### Configure Global Player Settings in Application Class (Java) Source: https://context7.com/doikki/dkvideoplayer/llms.txt This snippet demonstrates how to configure global player settings for the VideoViewManager within your Android Application class. It allows setting the default player factory, enabling orientation detection, audio focus, mobile network playback, screen scale type, debug logging, notch screen adaptation, and custom progress or render view factories. ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); VideoViewManager.setConfig(VideoViewConfig.newBuilder() // Set default player factory (IjkPlayer, ExoPlayer, or AndroidMediaPlayer) .setPlayerFactory(IjkPlayerFactory.create()) // .setPlayerFactory(ExoMediaPlayerFactory.create()) // .setPlayerFactory(AndroidMediaPlayerFactory.create()) // Enable device orientation detection for auto fullscreen .setEnableOrientation(true) // Enable AudioFocus monitoring (default: true) .setEnableAudioFocus(true) // Allow playback on mobile network (default: true) .setPlayOnMobileNetwork(true) // Set default screen scale type .setScreenScaleType(VideoView.SCREEN_SCALE_DEFAULT) // Enable debug logging .setLogEnabled(BuildConfig.DEBUG) // Adapt to notch screens (default: true) .setAdaptCutout(true) // Set custom progress manager for resuming playback .setProgressManager(new MyProgressManager()) // Set custom render view factory // .setRenderViewFactory(SurfaceRenderViewFactory.create()) .build()); } } // Custom ProgressManager implementation public class MyProgressManager extends ProgressManager { private SharedPreferences sp; public MyProgressManager() { sp = PreferenceManager.getDefaultSharedPreferences(App.getContext()); } @Override public void saveProgress(String url, long progress) { sp.edit().putLong(url.hashCode() + "", progress).apply(); } @Override public long getSavedProgress(String url) { return sp.getLong(url.hashCode() + "", 0); } } ``` -------------------------------- ### ProGuard Rules for DKVideoPlayer Source: https://context7.com/doikki/dkvideoplayer/llms.txt Essential ProGuard rules to include in your proguard-rules.pro file for DKVideoPlayer to function correctly in release builds. These rules prevent code stripping and obfuscation of the player's core classes and optional dependencies like IjkPlayer or ExoPlayer. ```proguard # DKVideoPlayer core -keep class xyz.doikki.videoplayer.** { *; } -dontwarn xyz.doikki.videoplayer.** # IjkPlayer (if using player-ijk) -keep class tv.danmaku.ijk.** { *; } -dontwarn tv.danmaku.ijk.** # ExoPlayer (if using player-exo) -keep class com.google.android.exoplayer2.** { *; } -dontwarn com.google.android.exoplayer2.** ``` -------------------------------- ### Video Volume Control in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Control the audio volume for video playback. This includes muting and unmuting the audio, checking the mute status, and setting specific volume levels for the left and right audio channels. ```java VideoView videoView = findViewById(R.id.player); // Volume control videoView.setMute(true); // Mute audio boolean muted = videoView.isMute(); // Check if muted videoView.setVolume(0.5f, 0.5f); // Set left/right channel volume (0.0-1.0) ``` -------------------------------- ### Manage Multiple Video Players with VideoViewManager in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Utilize VideoViewManager to handle multiple VideoView instances, essential for scenarios like list playback where players persist across activities. It supports adding, retrieving, releasing, and removing players by tag, and managing mobile network playback settings. Use Application Context to prevent memory leaks. ```java // Add a VideoView to the manager (use Application Context to avoid leaks) VideoView videoView = new VideoView(getApplicationContext()); videoView.setUrl("https://example.com/video.mp4"); VideoViewManager.instance().add(videoView, "player1"); // Retrieve a VideoView by tag VideoView player = VideoViewManager.instance().get("player1"); if (player != null) { player.start(); } // Handle back press for a managed player if (VideoViewManager.instance().onBackPress("player1")) { return; // Back press was handled (e.g., exit fullscreen) } // Release and remove a player VideoViewManager.instance().releaseByTag("player1"); // Release without removing (for reuse) VideoViewManager.instance().releaseByTag("player1", false); // Remove from manager without releasing VideoViewManager.instance().remove("player1"); // Remove all managed players VideoViewManager.instance().removeAll(); // Mobile network settings VideoViewManager.instance().setPlayOnMobileNetwork(true); boolean playOnMobile = VideoViewManager.instance().playOnMobileNetwork(); ``` -------------------------------- ### Video Playback Speed Control in Java Source: https://context7.com/doikki/dkvideoplayer/llms.txt Adjust and retrieve the playback speed of the video. This functionality requires API 23+ for MediaPlayer, but works universally with Ijk/Exo players. It allows setting custom playback speeds and checking the current speed. ```java VideoView videoView = findViewById(R.id.player); // Playback speed (requires API 23+ for MediaPlayer, always works with Ijk/Exo) videoView.setSpeed(1.5f); // 1.5x speed float speed = videoView.getSpeed(); // Get current speed ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.