Add fixes for streamable videos.

This commit is contained in:
Michelle Tang
2025-04-24 15:48:51 -04:00
committed by Cody Henthorne
parent 3aefd3bdc6
commit 7043558657
5 changed files with 218 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.video;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
@@ -55,6 +56,7 @@ public class VideoPlayer extends FrameLayout {
private static final String TAG = Log.tag(VideoPlayer.class);
private final PlayerView exoView;
private final View progressBar;
private final DefaultMediaSourceFactory mediaSourceFactory;
private ExoPlayer exoPlayer;
@@ -89,6 +91,7 @@ public class VideoPlayer extends FrameLayout {
this.mediaSourceFactory = new DefaultMediaSourceFactory(context);
this.exoView = findViewById(R.id.video_view);
this.progressBar = findViewById(R.id.progress_bar);
this.exoControls = createPlayerControls(getContext());
this.exoPlayerListener = new ExoPlayerListener();
@@ -113,6 +116,13 @@ public class VideoPlayer extends FrameLayout {
}
private void onPlaybackStateChanged(boolean playWhenReady, int playbackState) {
if (progressBar != null) {
if (playbackState == Player.STATE_BUFFERING) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
}
}
if (playerCallback != null) {
switch (playbackState) {
case Player.STATE_READY:

View File

@@ -14,22 +14,22 @@ import androidx.media3.datasource.TransferListener;
import org.signal.core.util.logging.Log;
import org.signal.libsignal.protocol.InvalidMessageException;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
import org.thoughtcrime.securesms.backup.v2.BackupRepository;
import org.thoughtcrime.securesms.backup.v2.DatabaseAttachmentArchiveUtil;
import org.thoughtcrime.securesms.database.AttachmentTable;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.mms.PartUriParser;
import org.signal.core.util.Base64;
import org.whispersystems.signalservice.api.backup.MediaId;
import org.whispersystems.signalservice.api.backup.MediaName;
import org.whispersystems.signalservice.api.backup.MediaRootBackupKey;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherStreamUtil;
import org.signal.core.util.stream.TailerInputStream;
import org.whispersystems.signalservice.internal.crypto.PaddingInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
@@ -88,14 +88,16 @@ class PartDataSource implements DataSource {
} else {
final File transferFile = attachmentDatabase.getOrCreateTransferFile(attachment.attachmentId);
try {
this.inputStream = AttachmentCipherInputStream.createForAttachment(transferFile, attachment.size, decode, attachment.remoteDigest, attachment.getIncrementalDigest(), attachment.incrementalMacChunkSize);
long streamLength = AttachmentCipherStreamUtil.getCiphertextLength(PaddingInputStream.getPaddedSize(attachment.size));
AttachmentCipherInputStream.StreamSupplier streamSupplier = () -> new TailerInputStream(() -> new FileInputStream(transferFile), streamLength);
this.inputStream = AttachmentCipherInputStream.createForAttachment(streamSupplier, streamLength, attachment.size, decode, attachment.remoteDigest, attachment.getIncrementalDigest(), attachment.incrementalMacChunkSize, false);
} catch (InvalidMessageException e) {
throw new IOException("Error decrypting attachment stream!", e);
}
}
long skipped = 0;
while (skipped < dataSpec.position) {
skipped += this.inputStream.read();
skipped += this.inputStream.skip(dataSpec.position - skipped);
}
Log.d(TAG, "Successfully loaded partial attachment file.");