This library is a video player component available in Android Jetpack Compose.
Based on Google ExoPlayer.
In addition to the basic functions of Exoplayer, it supports full screen, PIP, ChromeCast, and more. All formats supported by ExoPlayer are playable, and DRM content is also supported.
The easiest way to get started using VideoPlayer component is to add it as a gradle dependency in the build.gradle file of your app module.
implementation 'io.sanghun:compose-video:1.1.1'
implementation 'com.google.android.exoplayer:exoplayer:2.18.2' // ExoPlayer dependency
implementation 'com.google.android.exoplayer:extension-mediasession:2.18.2' // MediaSession Extension dependency
or if your project using build.gradle.kts
implementation("io.sanghun:compose-video:1.1.1")
implementation("com.google.android.exoplayer:exoplayer:2.18.2") // ExoPlayer dependency
implementation("com.google.android.exoplayer:extension-mediasession:2.18.2") // MediaSession Extension dependency
VideoPlayer | Full Screen | PIP |
VideoPlayer(
mediaItems = listOf(
VideoPlayerMediaItem.RawResourceMediaItem(
resourceId = R.raw.movie1,
),
VideoPlayerMediaItem.AssetFileMediaItem(
assetPath = "videos/test.mp4"
),
VideoPlayerMediaItem.StorageMediaItem(
storageUri = "content://xxxxx"
),
VideoPlayerMediaItem.NetworkMediaItem(
url = "https://storage.googleapis.com/wvmedia/cbcs/h264/tears/tears_aes_cbcs.mpd",
mediaMetadata = MediaMetadata.Builder().setTitle("Widevine DASH cbcs: Tears").build(),
mimeType = MimeTypes.APPLICATION_MPD,
drmConfiguration = MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID)
.setLicenseUri("https://proxy.uat.widevine.com/proxy?provider=widevine_test")
.build(),
)
),
handleLifecycle = true,
autoPlay = true,
usePlayerController = true,
enablePip = true,
handleAudioFocus = true,
controllerConfig = VideoPlayerControllerConfig(
showSpeedAndPitchOverlay = false,
showSubtitleButton = false,
showCurrentTimeAndTotalTime = true,
showBufferingProgress = false,
showForwardIncrementButton = true,
showBackwardIncrementButton = true,
showBackTrackButton = true,
showNextTrackButton = true,
showRepeatModeButton = true,
controllerShowTimeMilliSeconds = 5_000,
controllerAutoShow = true,
),
volume = 0.5f, // volume 0.0f to 1.0f
repeatMode = RepeatMode.NONE, // or RepeatMode.ALL, RepeatMode.ONE
onCurrentTimeChanged = { // long type, current player time (millisec)
Log.e("CurrentTime", it.toString())
},
playerInstance = { // ExoPlayer instance (Experimental)
addAnalyticsListener(
object : AnalyticsListener {
// player logger
}
)
},
modifier = Modifier
.fillMaxSize()
.align(Alignment.Center),
)
By default, the LRU cache is used. To set up a cache for video player common use, call the method below only once when the app starts.
VideoPlayerCacheManager.initialize(context, 1024 * 1024 * 1024) // 1GB
- Local video play (ex. assets, storage)
- Network video play (ex. HLS, DASH)
- Video Player Controller (Default)
- Video Player Custom Controller (using Jetpack Compose)
- Audio Focus
- Full Screen (With rotate)
- Repeat
- Volume Control
- Select Audio Track
- Select Video Track
- SubTitle
- Chromecast
- Buffering config
- PIP (Picture In Picture)
- DRM
- Custom Headers
- Background Play
- Rate
- Resize Mode
- Video Caching
The contribution of new features or bug fixes is always welcome.
Please submit new issue or pull request anytime.
Licensed under the Apache 2.0 license. See LICENSE for details.