-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
previous video not stop ,when scrolling to next! #1
Comments
Issue not generated on the current version. After scrolling to the next, previous video will stop, and new video plays. Can you provide more details about your issue along with device details |
i load a video source from url ,not from local asset , Is this what caused it? my video_list is blowval videoLIst = listOf<String>(
"https://app-test.obs.cn-east-2.myhuaweicloud.com/_d14ccf24-0409-4450-8316-620024279f16_1234.mp4",
"https://app-test.obs.cn-east-2.myhuaweicloud.com/_67cb0c70-645e-4e42-942b-230159ed7aa0_%E4%B8%BD%E6%B1%9F.mp4") my video compose copied from your code ,only diff is load video from url:@OptIn(ExperimentalFoundationApi::class)
@Composable
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
fun VideoPlayer(
url: String,
state: PagerState,
pageIndex: Int,
onSingleTap: (exoPlayer: ExoPlayer) -> Unit,
onDoubleTap: (exoPlayer: ExoPlayer) -> Unit
) {
var ctx = LocalContext.current
if (pageIndex == state.settledPage) {
var exoPlayer = remember(ctx) {
ExoPlayer.Builder(ctx).build().apply {
videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT;
repeatMode = Player.REPEAT_MODE_ONE
val mediaItem = MediaItem.fromUri(url)
setMediaItem(mediaItem)
playWhenReady = true;
prepare()
addListener(object : Player.Listener {
override fun onRenderedFirstFrame() {
super.onRenderedFirstFrame()
}
})
}
}
var playerView = remember {
PlayerView(ctx).apply {
player = exoPlayer
useController = false
}
}
val lifecycleOwner by rememberUpdatedState(LocalLifecycleOwner.current)
DisposableEffect(key1 = lifecycleOwner) {
val lifecycleObserver = LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_STOP -> {
exoPlayer.pause()
}
Lifecycle.Event.ON_START -> exoPlayer.play()
else -> {}
}
}
lifecycleOwner.lifecycle.addObserver(lifecycleObserver)
onDispose {
lifecycleOwner.lifecycle.removeObserver(lifecycleObserver)
}
}
DisposableEffect(key1 = AndroidView(factory = {
playerView
}, modifier = Modifier.pointerInput(Unit) {
detectTapGestures(onTap = {
onSingleTap(exoPlayer)
}, onDoubleTap = {
onDoubleTap(exoPlayer)
})
}), effect = {
onDispose {
exoPlayer.release()
}
})
}
} |
fix it by adding AsyncImage() at last in my VideoPleyer |
|
No description provided.
The text was updated successfully, but these errors were encountered: