mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Fix playback position indicator for trimmed video clips.
This commit is contained in:
committed by
mtang-signal
parent
1d6917476e
commit
4af6e0480a
@@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.video.videoconverter.VideoThumbnailsRangeSelec
|
||||
import org.thoughtcrime.securesms.video.videoconverter.VideoThumbnailsRangeSelectorView.PositionDragListener
|
||||
import java.io.IOException
|
||||
import kotlin.time.Duration.Companion.microseconds
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
class VideoEditorFragment : Fragment(), PositionDragListener, MediaSendPageFragment {
|
||||
private val sharedViewModel: MediaSelectionViewModel by viewModels(ownerProducer = { requireActivity() })
|
||||
@@ -46,9 +47,9 @@ class VideoEditorFragment : Fragment(), PositionDragListener, MediaSendPageFragm
|
||||
private val updatePosition = object : Runnable {
|
||||
override fun run() {
|
||||
if (MediaConstraints.isVideoTranscodeAvailable()) {
|
||||
val playbackPositionUs = player.playbackPositionUs
|
||||
if (playbackPositionUs >= 0) {
|
||||
videoTimeLine.setActualPosition(playbackPositionUs)
|
||||
val playbackPosition = player.truePlaybackPosition
|
||||
if (playbackPosition >= 0) {
|
||||
videoTimeLine.setActualPosition(playbackPosition.milliseconds.inWholeMicroseconds)
|
||||
handler.postDelayed(this, 100)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,9 +288,15 @@ public class VideoPlayer extends FrameLayout {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getPlaybackPositionUs() {
|
||||
/**
|
||||
* After calling {@link #setPlaybackPosition}, the underlying {@link Player} resets the current position to 0.
|
||||
* We manually store the offset of where we clipped to, and add that here.
|
||||
*
|
||||
* @return the current playback position, rounded to the nearest millisecond
|
||||
*/
|
||||
public long getTruePlaybackPosition() {
|
||||
if (this.exoPlayer != null) {
|
||||
return TimeUnit.MILLISECONDS.toMicros(this.exoPlayer.getCurrentPosition());
|
||||
return this.exoPlayer.getCurrentPosition() + Math.round(clippedStartUs / 1000.0);
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user