Remove audio player usage of AttachmentServer.
Now that we use ExoPlayer, it's no longer needed.
This commit is contained in:
parent
d8a75d599d
commit
a5368b7ea9
1 changed files with 17 additions and 26 deletions
|
@ -27,18 +27,18 @@ import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||||
|
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
|
||||||
import com.google.android.exoplayer2.source.ExtractorMediaSource;
|
import com.google.android.exoplayer2.source.ExtractorMediaSource;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.BuildConfig;
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.attachments.AttachmentServer;
|
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
import org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -60,7 +60,6 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
|
|
||||||
private @NonNull WeakReference<Listener> listener;
|
private @NonNull WeakReference<Listener> listener;
|
||||||
private @Nullable SimpleExoPlayer mediaPlayer;
|
private @Nullable SimpleExoPlayer mediaPlayer;
|
||||||
private @Nullable AttachmentServer audioAttachmentServer;
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
public synchronized static AudioSlidePlayer createFor(@NonNull Context context,
|
public synchronized static AudioSlidePlayer createFor(@NonNull Context context,
|
||||||
|
@ -99,16 +98,19 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void play(final double progress, boolean earpiece) throws IOException {
|
private void play(final double progress, boolean earpiece) throws IOException {
|
||||||
if (this.mediaPlayer != null) return;
|
if (this.mediaPlayer != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slide.getUri() == null) {
|
||||||
|
throw new IOException("Slide has no URI!");
|
||||||
|
}
|
||||||
|
|
||||||
LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
|
LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
|
||||||
this.mediaPlayer = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
|
this.mediaPlayer = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
|
||||||
this.audioAttachmentServer = new AttachmentServer(context, slide.asAttachment());
|
|
||||||
this.startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
audioAttachmentServer.start();
|
mediaPlayer.prepare(createMediaSource(slide.getUri()));
|
||||||
|
|
||||||
mediaPlayer.prepare(createMediaSource(audioAttachmentServer.getUri()));
|
|
||||||
mediaPlayer.setPlayWhenReady(true);
|
mediaPlayer.setPlayWhenReady(true);
|
||||||
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder()
|
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder()
|
||||||
.setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC)
|
.setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC)
|
||||||
|
@ -152,11 +154,6 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
synchronized (AudioSlidePlayer.this) {
|
synchronized (AudioSlidePlayer.this) {
|
||||||
mediaPlayer = null;
|
mediaPlayer = null;
|
||||||
|
|
||||||
if (audioAttachmentServer != null) {
|
|
||||||
audioAttachmentServer.stop();
|
|
||||||
audioAttachmentServer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
||||||
|
|
||||||
if (wakeLock != null && wakeLock.isHeld()) {
|
if (wakeLock != null && wakeLock.isHeld()) {
|
||||||
|
@ -180,11 +177,6 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
synchronized (AudioSlidePlayer.this) {
|
synchronized (AudioSlidePlayer.this) {
|
||||||
mediaPlayer = null;
|
mediaPlayer = null;
|
||||||
|
|
||||||
if (audioAttachmentServer != null) {
|
|
||||||
audioAttachmentServer.stop();
|
|
||||||
audioAttachmentServer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
||||||
|
|
||||||
if (wakeLock != null && wakeLock.isHeld()) {
|
if (wakeLock != null && wakeLock.isHeld()) {
|
||||||
|
@ -201,8 +193,12 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaSource createMediaSource(@NonNull Uri uri) {
|
private MediaSource createMediaSource(@NonNull Uri uri) {
|
||||||
return new ExtractorMediaSource.Factory(new DefaultDataSourceFactory(context, BuildConfig.USER_AGENT))
|
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "GenericUserAgent", null);
|
||||||
.setExtractorsFactory(new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true))
|
AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null);
|
||||||
|
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);
|
||||||
|
|
||||||
|
return new ExtractorMediaSource.Factory(attachmentDataSourceFactory)
|
||||||
|
.setExtractorsFactory(extractorsFactory)
|
||||||
.createMediaSource(uri);
|
.createMediaSource(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,14 +212,9 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||||
this.mediaPlayer.release();
|
this.mediaPlayer.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.audioAttachmentServer != null) {
|
|
||||||
this.audioAttachmentServer.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
sensorManager.unregisterListener(AudioSlidePlayer.this);
|
||||||
|
|
||||||
this.mediaPlayer = null;
|
this.mediaPlayer = null;
|
||||||
this.audioAttachmentServer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void stopAll() {
|
public synchronized static void stopAll() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue