Refactoring of unused elements in VideoView
This commit is contained in:
@@ -189,7 +189,7 @@ fun VideoViewInner(
|
|||||||
if (!automaticallyStartPlayback.value) {
|
if (!automaticallyStartPlayback.value) {
|
||||||
ImageUrlWithDownloadButton(url = videoUri, showImage = automaticallyStartPlayback)
|
ImageUrlWithDownloadButton(url = videoUri, showImage = automaticallyStartPlayback)
|
||||||
} else {
|
} else {
|
||||||
VideoPlayerMutex(videoUri) { activeOnScreen ->
|
VideoPlayerActiveMutex(videoUri) { activeOnScreen ->
|
||||||
val mediaItem = remember(videoUri) {
|
val mediaItem = remember(videoUri) {
|
||||||
MediaItem.Builder()
|
MediaItem.Builder()
|
||||||
.setMediaId(videoUri)
|
.setMediaId(videoUri)
|
||||||
@@ -410,7 +410,7 @@ class VisibilityData() {
|
|||||||
* the screen wins the mutex.
|
* the screen wins the mutex.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun VideoPlayerMutex(videoUri: String, inner: @Composable (MutableState<Boolean>) -> Unit) {
|
fun VideoPlayerActiveMutex(videoUri: String, inner: @Composable (MutableState<Boolean>) -> Unit) {
|
||||||
val myCache = remember(videoUri) {
|
val myCache = remember(videoUri) {
|
||||||
VisibilityData()
|
VisibilityData()
|
||||||
}
|
}
|
||||||
@@ -607,38 +607,6 @@ fun ControlWhenPlayerIsActive(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Modifier.onVisibilityChanges(onVisibilityChanges: (Boolean) -> Unit): Modifier = composed {
|
|
||||||
val view = LocalView.current
|
|
||||||
var isVisible: Boolean? by remember { mutableStateOf(null) }
|
|
||||||
|
|
||||||
onGloballyPositioned { coordinates ->
|
|
||||||
val newIsVisible = coordinates.isCompletelyVisible(view)
|
|
||||||
if (isVisible != newIsVisible) {
|
|
||||||
isVisible = newIsVisible
|
|
||||||
onVisibilityChanges(isVisible == true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun LayoutCoordinates.isCompletelyVisible(view: View): Boolean {
|
|
||||||
if (!isAttached) return false
|
|
||||||
// Window relative bounds of our compose root view that are visible on the screen
|
|
||||||
val globalRootRect = Rect()
|
|
||||||
if (!view.getGlobalVisibleRect(globalRootRect)) {
|
|
||||||
// we aren't visible at all.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
val bounds = boundsInWindow()
|
|
||||||
|
|
||||||
if (bounds.isEmpty) return false
|
|
||||||
|
|
||||||
// Make sure we are completely in bounds.
|
|
||||||
return bounds.top >= globalRootRect.top &&
|
|
||||||
bounds.left >= globalRootRect.left &&
|
|
||||||
bounds.right <= globalRootRect.right &&
|
|
||||||
bounds.bottom <= globalRootRect.bottom
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Modifier.onVisiblePositionChanges(onVisiblePosition: (Float?) -> Unit): Modifier = composed {
|
fun Modifier.onVisiblePositionChanges(onVisiblePosition: (Float?) -> Unit): Modifier = composed {
|
||||||
val view = LocalView.current
|
val view = LocalView.current
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user