Migration to Media3

This commit is contained in:
ThomasSession 2024-08-12 13:17:20 +10:00
parent 5b34a09ff9
commit c55c55d775
9 changed files with 47 additions and 34 deletions

View File

@ -267,8 +267,8 @@ dependencies {
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
}
if (project.hasProperty('huawei')) huaweiImplementation 'com.huawei.hms:push:6.7.0.300'
implementation 'com.google.android.exoplayer:exoplayer-core:2.19.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.19.1'
implementation 'androidx.media3:media3-exoplayer:1.1.1'
implementation 'androidx.media3:media3-ui:1.1.1'
implementation 'org.conscrypt:conscrypt-android:2.5.2'
implementation 'org.signal:aesgcmprovider:0.0.3'
implementation 'org.webrtc:google-webrtc:1.0.32006'

View File

@ -16,13 +16,13 @@ import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.audio.AudioAttributes;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.AudioAttributes;
import androidx.media3.exoplayer.ExoPlayer;
import org.jetbrains.annotations.NotNull;
import org.session.libsession.utilities.ServiceUtil;
@ -356,7 +356,7 @@ public class AudioSlidePlayer implements SensorEventListener {
mediaPlayer.getAudioAttributes().contentType != streamType &&
System.currentTimeMillis() - startTime > 500)
{
if (wakeLock != null) wakeLock.release();
if (wakeLock != null && wakeLock.isHeld()) wakeLock.release();
stop();
notifyOnStop();
}

View File

@ -4,7 +4,10 @@ import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.fragment.app.Fragment;
import androidx.media3.common.util.UnstableApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -16,6 +19,7 @@ import org.thoughtcrime.securesms.video.VideoPlayer;
import java.io.IOException;
@OptIn(markerClass = UnstableApi.class)
public class MediaSendVideoFragment extends Fragment implements MediaSendPageFragment {
private static final String TAG = MediaSendVideoFragment.class.getSimpleName();

View File

@ -29,12 +29,14 @@ import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Player;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.ui.LegacyPlayerControlView;
import androidx.media3.ui.PlayerView;
import org.session.libsession.utilities.ViewUtil;
import org.session.libsignal.utilities.Log;
@ -46,6 +48,7 @@ import java.io.IOException;
import network.loki.messenger.R;
@UnstableApi
public class VideoPlayer extends FrameLayout {
private static final String TAG = VideoPlayer.class.getSimpleName();
@ -54,7 +57,7 @@ public class VideoPlayer extends FrameLayout {
@Nullable private final PlayerView exoView;
@Nullable private ExoPlayer exoPlayer;
@Nullable private PlayerControlView exoControls;
@Nullable private LegacyPlayerControlView exoControls;
@Nullable private AttachmentServer attachmentServer;
@Nullable private Window window;
@ -73,7 +76,7 @@ public class VideoPlayer extends FrameLayout {
this.exoView = ViewUtil.findById(this, R.id.video_view);
this.videoView = null;
this.exoControls = new PlayerControlView(getContext());
this.exoControls = new LegacyPlayerControlView(getContext());
this.exoControls.setShowTimeoutMs(-1);
}

View File

@ -3,10 +3,12 @@ package org.thoughtcrime.securesms.video.exo;
import android.net.Uri;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.datasource.TransferListener;
import org.thoughtcrime.securesms.mms.PartAuthority;
@ -15,6 +17,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
@UnstableApi
public class AttachmentDataSource implements DataSource {
private final DefaultDataSource defaultDataSource;

View File

@ -4,11 +4,13 @@ package org.thoughtcrime.securesms.video.exo;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSourceFactory;
import androidx.media3.datasource.TransferListener;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.TransferListener;
@UnstableApi
public class AttachmentDataSourceFactory implements DataSource.Factory {
private final Context context;

View File

@ -6,10 +6,10 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.TransferListener;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
@UnstableApi
public class PartDataSource implements DataSource {
private final @NonNull Context context;

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
<androidx.media3.ui.AspectRatioFrameLayout
android:id="@+id/exo_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.PlayerView
<androidx.media3.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"