Merge pull request #4916 from element-hq/feature/bma/zoomVideo2
Add ability to zoom on video.
This commit is contained in:
commit
d524c23b8d
1 changed files with 27 additions and 9 deletions
|
|
@ -25,6 +25,7 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalInspectionMode
|
import androidx.compose.ui.platform.LocalInspectionMode
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
|
@ -33,6 +34,7 @@ import androidx.media3.common.MediaItem
|
||||||
import androidx.media3.common.Player
|
import androidx.media3.common.Player
|
||||||
import androidx.media3.common.Player.STATE_READY
|
import androidx.media3.common.Player.STATE_READY
|
||||||
import androidx.media3.common.Timeline
|
import androidx.media3.common.Timeline
|
||||||
|
import androidx.media3.common.VideoSize
|
||||||
import androidx.media3.exoplayer.ExoPlayer
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
import androidx.media3.ui.AspectRatioFrameLayout
|
import androidx.media3.ui.AspectRatioFrameLayout
|
||||||
import androidx.media3.ui.PlayerView
|
import androidx.media3.ui.PlayerView
|
||||||
|
|
@ -54,6 +56,8 @@ import io.element.android.libraries.mediaviewer.impl.local.player.seekToEnsurePl
|
||||||
import io.element.android.libraries.mediaviewer.impl.local.player.togglePlay
|
import io.element.android.libraries.mediaviewer.impl.local.player.togglePlay
|
||||||
import io.element.android.libraries.mediaviewer.impl.local.rememberLocalMediaViewState
|
import io.element.android.libraries.mediaviewer.impl.local.rememberLocalMediaViewState
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import me.saket.telephoto.zoomable.ZoomableContentLocation
|
||||||
|
import me.saket.telephoto.zoomable.zoomable
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
@SuppressLint("UnsafeOptInUsageError")
|
@SuppressLint("UnsafeOptInUsageError")
|
||||||
|
|
@ -150,6 +154,18 @@ private fun ExoPlayerMediaVideoView(
|
||||||
isReady = playbackState == STATE_READY,
|
isReady = playbackState == STATE_READY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onVideoSizeChanged(videoSize: VideoSize) {
|
||||||
|
// Ensure that the user cannot zoom/move outside of the video bounds
|
||||||
|
localMediaViewState.zoomableState.setContentLocation(
|
||||||
|
ZoomableContentLocation.scaledInsideAndCenterAligned(
|
||||||
|
Size(
|
||||||
|
videoSize.width.toFloat(),
|
||||||
|
videoSize.height.toFloat(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,24 +232,26 @@ private fun ExoPlayerMediaVideoView(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier
|
||||||
factory = {
|
.fillMaxSize()
|
||||||
PlayerView(context).apply {
|
.zoomable(
|
||||||
player = exoPlayer
|
state = localMediaViewState.zoomableState,
|
||||||
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
onClick = {
|
||||||
layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
|
||||||
setOnClickListener {
|
|
||||||
autoHideController++
|
autoHideController++
|
||||||
mediaPlayerControllerState = mediaPlayerControllerState.copy(
|
mediaPlayerControllerState = mediaPlayerControllerState.copy(
|
||||||
isVisible = !mediaPlayerControllerState.isVisible,
|
isVisible = !mediaPlayerControllerState.isVisible,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
factory = {
|
||||||
|
PlayerView(context).apply {
|
||||||
|
player = exoPlayer
|
||||||
|
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
||||||
|
layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||||
useController = false
|
useController = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRelease = { playerView ->
|
onRelease = { playerView ->
|
||||||
playerView.setOnClickListener(null)
|
|
||||||
playerView.setControllerVisibilityListener(null as PlayerView.ControllerVisibilityListener?)
|
|
||||||
playerView.player = null
|
playerView.player = null
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue