Ensure screen does not turn off when playing a video (#1519)
This commit is contained in:
parent
12ece41317
commit
a71fb431d3
4 changed files with 44 additions and 0 deletions
1
changelog.d/1519.bugfix
Normal file
1
changelog.d/1519.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Ensure screen does not turn off when playing a video
|
||||||
|
|
@ -66,6 +66,7 @@ import io.element.android.libraries.core.mimetype.MimeTypes.isMimeTypeVideo
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.utils.CommonDrawables
|
import io.element.android.libraries.designsystem.utils.CommonDrawables
|
||||||
|
import io.element.android.libraries.designsystem.utils.KeepScreenOn
|
||||||
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
|
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
|
||||||
import io.element.android.libraries.theme.ElementTheme
|
import io.element.android.libraries.theme.ElementTheme
|
||||||
import me.saket.telephoto.zoomable.ZoomSpec
|
import me.saket.telephoto.zoomable.ZoomSpec
|
||||||
|
|
@ -152,6 +153,10 @@ private fun MediaVideoView(
|
||||||
override fun onRenderedFirstFrame() {
|
override fun onRenderedFirstFrame() {
|
||||||
localMediaViewState.isReady = true
|
localMediaViewState.isReady = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||||
|
localMediaViewState.isPlaying = isPlaying
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val exoPlayer = remember {
|
val exoPlayer = remember {
|
||||||
ExoPlayerWrapper.create(context)
|
ExoPlayerWrapper.create(context)
|
||||||
|
|
@ -168,6 +173,7 @@ private fun MediaVideoView(
|
||||||
} else {
|
} else {
|
||||||
exoPlayer.setMediaItems(emptyList())
|
exoPlayer.setMediaItems(emptyList())
|
||||||
}
|
}
|
||||||
|
KeepScreenOn(localMediaViewState.isPlaying)
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = {
|
factory = {
|
||||||
PlayerView(context).apply {
|
PlayerView(context).apply {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import androidx.compose.runtime.setValue
|
||||||
@Stable
|
@Stable
|
||||||
class LocalMediaViewState {
|
class LocalMediaViewState {
|
||||||
var isReady: Boolean by mutableStateOf(false)
|
var isReady: Boolean by mutableStateOf(false)
|
||||||
|
var isPlaying: Boolean by mutableStateOf(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.designsystem.utils
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun KeepScreenOn(
|
||||||
|
keepScreenOn: Boolean = true
|
||||||
|
) {
|
||||||
|
if (keepScreenOn) {
|
||||||
|
val currentView = LocalView.current
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
currentView.keepScreenOn = true
|
||||||
|
onDispose {
|
||||||
|
currentView.keepScreenOn = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue