kopia lustrzana https://github.com/ryukoposting/Signal-Android
Do not autoplay in video editor.
rodzic
731683ae09
commit
62f9f19540
|
@ -45,6 +45,8 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
private VideoPlayer player;
|
private VideoPlayer player;
|
||||||
@Nullable private VideoEditorHud hud;
|
@Nullable private VideoEditorHud hud;
|
||||||
private Runnable updatePosition;
|
private Runnable updatePosition;
|
||||||
|
private boolean isInEdit;
|
||||||
|
private boolean wasPlayingBeforeEdit;
|
||||||
|
|
||||||
public static VideoEditorFragment newInstance(@NonNull Uri uri, long maxCompressedVideoSize, long maxAttachmentSize, boolean isVideoGif) {
|
public static VideoEditorFragment newInstance(@NonNull Uri uri, long maxCompressedVideoSize, long maxAttachmentSize, boolean isVideoGif) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
@ -88,9 +90,10 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
long maxOutput = requireArguments().getLong(KEY_MAX_OUTPUT);
|
long maxOutput = requireArguments().getLong(KEY_MAX_OUTPUT);
|
||||||
long maxSend = requireArguments().getLong(KEY_MAX_SEND);
|
long maxSend = requireArguments().getLong(KEY_MAX_SEND);
|
||||||
VideoSlide slide = new VideoSlide(requireContext(), uri, 0, isVideoGif);
|
VideoSlide slide = new VideoSlide(requireContext(), uri, 0, isVideoGif);
|
||||||
|
boolean autoplay = isVideoGif;
|
||||||
|
|
||||||
player.setWindow(requireActivity().getWindow());
|
player.setWindow(requireActivity().getWindow());
|
||||||
player.setVideoSource(slide, true);
|
player.setVideoSource(slide, autoplay);
|
||||||
|
|
||||||
if (slide.isVideoGif()) {
|
if (slide.isVideoGif()) {
|
||||||
player.setPlayerCallback(new VideoPlayer.PlayerCallback() {
|
player.setPlayerCallback(new VideoPlayer.PlayerCallback() {
|
||||||
|
@ -116,7 +119,7 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
hud.setEventListener(this);
|
hud.setEventListener(this);
|
||||||
updateHud(data);
|
updateHud(data);
|
||||||
if (data.durationEdited) {
|
if (data.durationEdited) {
|
||||||
player.clip(data.startTimeUs, data.endTimeUs, true);
|
player.clip(data.startTimeUs, data.endTimeUs, autoplay);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
hud.setVideoSource(slide, new VideoBitRateCalculator(maxOutput), maxSend);
|
hud.setVideoSource(slide, new VideoBitRateCalculator(maxOutput), maxSend);
|
||||||
|
@ -134,8 +137,12 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
player.setPlayerCallback(new VideoPlayer.PlayerCallback() {
|
player.setPlayerCallback(new VideoPlayer.PlayerCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaying() {
|
public void onReady() {
|
||||||
controller.onPlayerReady();
|
controller.onPlayerReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaying() {
|
||||||
hud.fadePlayButton();
|
hud.fadePlayButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +286,11 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
data.endTimeUs = endTimeUs;
|
data.endTimeUs = endTimeUs;
|
||||||
|
|
||||||
if (editingComplete) {
|
if (editingComplete) {
|
||||||
|
isInEdit = false;
|
||||||
videoScanThrottle.clear();
|
videoScanThrottle.clear();
|
||||||
|
} else if (!isInEdit) {
|
||||||
|
isInEdit = true;
|
||||||
|
wasPlayingBeforeEdit = player.isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
videoScanThrottle.publish(() -> {
|
videoScanThrottle.publish(() -> {
|
||||||
|
@ -290,9 +301,13 @@ public class VideoEditorFragment extends Fragment implements VideoEditorHud.Even
|
||||||
player.setPlaybackPosition(fromEdited || editingComplete ? clampedStartTime / 1000 : endTimeUs / 1000);
|
player.setPlaybackPosition(fromEdited || editingComplete ? clampedStartTime / 1000 : endTimeUs / 1000);
|
||||||
if (editingComplete) {
|
if (editingComplete) {
|
||||||
if (durationEdited) {
|
if (durationEdited) {
|
||||||
player.clip(clampedStartTime, endTimeUs, true);
|
player.clip(clampedStartTime, endTimeUs, wasPlayingBeforeEdit);
|
||||||
} else {
|
} else {
|
||||||
player.removeClip(true);
|
player.removeClip(wasPlayingBeforeEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wasPlayingBeforeEdit) {
|
||||||
|
hud.showPlayButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,6 +93,7 @@ public class VideoPlayer extends FrameLayout {
|
||||||
if (playerCallback != null) {
|
if (playerCallback != null) {
|
||||||
switch (playbackState) {
|
switch (playbackState) {
|
||||||
case Player.STATE_READY:
|
case Player.STATE_READY:
|
||||||
|
playerCallback.onReady();
|
||||||
if (playWhenReady) playerCallback.onPlaying();
|
if (playWhenReady) playerCallback.onPlaying();
|
||||||
break;
|
break;
|
||||||
case Player.STATE_ENDED:
|
case Player.STATE_ENDED:
|
||||||
|
@ -137,6 +138,14 @@ public class VideoPlayer extends FrameLayout {
|
||||||
exoView.setResizeMode(resizeMode);
|
exoView.setResizeMode(resizeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPlaying() {
|
||||||
|
if (this.exoPlayer != null) {
|
||||||
|
return this.exoPlayer.isPlaying();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (this.exoPlayer != null) {
|
if (this.exoPlayer != null) {
|
||||||
this.exoPlayer.setPlayWhenReady(false);
|
this.exoPlayer.setPlayWhenReady(false);
|
||||||
|
@ -332,6 +341,8 @@ public class VideoPlayer extends FrameLayout {
|
||||||
|
|
||||||
public interface PlayerCallback {
|
public interface PlayerCallback {
|
||||||
|
|
||||||
|
default void onReady() {}
|
||||||
|
|
||||||
void onPlaying();
|
void onPlaying();
|
||||||
|
|
||||||
void onStopped();
|
void onStopped();
|
||||||
|
|
Ładowanie…
Reference in New Issue