kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix video playback after editing clip boundaries.
rodzic
915d56ac15
commit
12ec0ca84c
|
@ -30,6 +30,9 @@ import com.google.android.exoplayer2.MediaItem;
|
||||||
import com.google.android.exoplayer2.PlaybackException;
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||||
|
import com.google.android.exoplayer2.source.ClippingMediaSource;
|
||||||
|
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
import com.google.android.exoplayer2.ui.PlayerControlView;
|
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||||
import com.google.android.exoplayer2.ui.PlayerView;
|
import com.google.android.exoplayer2.ui.PlayerView;
|
||||||
|
@ -49,6 +52,7 @@ public class VideoPlayer extends FrameLayout {
|
||||||
|
|
||||||
private final PlayerView exoView;
|
private final PlayerView exoView;
|
||||||
private final PlayerControlView exoControls;
|
private final PlayerControlView exoControls;
|
||||||
|
private final DefaultMediaSourceFactory mediaSourceFactory;
|
||||||
|
|
||||||
private SimpleExoPlayer exoPlayer;
|
private SimpleExoPlayer exoPlayer;
|
||||||
private Window window;
|
private Window window;
|
||||||
|
@ -73,6 +77,8 @@ public class VideoPlayer extends FrameLayout {
|
||||||
|
|
||||||
inflate(context, R.layout.video_player, this);
|
inflate(context, R.layout.video_player, this);
|
||||||
|
|
||||||
|
this.mediaSourceFactory = new DefaultMediaSourceFactory(context);
|
||||||
|
|
||||||
this.exoView = findViewById(R.id.video_view);
|
this.exoView = findViewById(R.id.video_view);
|
||||||
this.exoControls = new PlayerControlView(getContext());
|
this.exoControls = new PlayerControlView(getContext());
|
||||||
this.exoControls.setShowTimeoutMs(-1);
|
this.exoControls.setShowTimeoutMs(-1);
|
||||||
|
@ -213,11 +219,10 @@ public class VideoPlayer extends FrameLayout {
|
||||||
|
|
||||||
public void clip(long fromUs, long toUs, boolean playWhenReady) {
|
public void clip(long fromUs, long toUs, boolean playWhenReady) {
|
||||||
if (this.exoPlayer != null && mediaItem != null) {
|
if (this.exoPlayer != null && mediaItem != null) {
|
||||||
MediaItem clippedMediaItem = mediaItem.buildUpon()
|
MediaSource mediaItemSource = mediaSourceFactory.createMediaSource(mediaItem);
|
||||||
.setClipStartPositionMs(TimeUnit.MICROSECONDS.toMillis(fromUs))
|
ClippingMediaSource clippedSource = new ClippingMediaSource(mediaItemSource, fromUs, toUs);
|
||||||
.setClipEndPositionMs(TimeUnit.MICROSECONDS.toMillis(toUs))
|
|
||||||
.build();
|
exoPlayer.setMediaSource(clippedSource);
|
||||||
exoPlayer.setMediaItem(clippedMediaItem);
|
|
||||||
exoPlayer.prepare();
|
exoPlayer.prepare();
|
||||||
exoPlayer.setPlayWhenReady(playWhenReady);
|
exoPlayer.setPlayWhenReady(playWhenReady);
|
||||||
clipped = true;
|
clipped = true;
|
||||||
|
|
Ładowanie…
Reference in New Issue