Migrate exoplayer to media3
parent
fb937ee292
commit
d82c5b6a1b
@ -1,61 +0,0 @@
|
|||||||
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 org.thoughtcrime.securesms.mms.PartAuthority;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AttachmentDataSource implements DataSource {
|
|
||||||
|
|
||||||
private final DefaultDataSource defaultDataSource;
|
|
||||||
private final PartDataSource partDataSource;
|
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
|
|
||||||
public AttachmentDataSource(DefaultDataSource defaultDataSource, PartDataSource partDataSource) {
|
|
||||||
this.defaultDataSource = defaultDataSource;
|
|
||||||
this.partDataSource = partDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTransferListener(TransferListener transferListener) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long open(DataSpec dataSpec) throws IOException {
|
|
||||||
if (PartAuthority.isLocalUri(dataSpec.uri)) dataSource = partDataSource;
|
|
||||||
else dataSource = defaultDataSource;
|
|
||||||
|
|
||||||
return dataSource.open(dataSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(byte[] buffer, int offset, int readLength) throws IOException {
|
|
||||||
return dataSource.read(buffer, offset, readLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Uri getUri() {
|
|
||||||
return dataSource.getUri();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, List<String>> getResponseHeaders() {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
dataSource.close();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.video.exo;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
|
||||||
|
|
||||||
public class AttachmentDataSourceFactory implements DataSource.Factory {
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
|
|
||||||
private final DefaultDataSourceFactory defaultDataSourceFactory;
|
|
||||||
private final TransferListener listener;
|
|
||||||
|
|
||||||
public AttachmentDataSourceFactory(@NonNull Context context,
|
|
||||||
@NonNull DefaultDataSourceFactory defaultDataSourceFactory,
|
|
||||||
@Nullable TransferListener listener)
|
|
||||||
{
|
|
||||||
this.context = context;
|
|
||||||
this.defaultDataSourceFactory = defaultDataSourceFactory;
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AttachmentDataSource createDataSource() {
|
|
||||||
return new AttachmentDataSource(defaultDataSourceFactory.createDataSource(),
|
|
||||||
new PartDataSource(context, listener));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.video.exo;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
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 org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
|
||||||
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
|
||||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
|
|
||||||
import org.thoughtcrime.securesms.mms.PartUriParser;
|
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PartDataSource implements DataSource {
|
|
||||||
|
|
||||||
private final @NonNull Context context;
|
|
||||||
private final @Nullable TransferListener listener;
|
|
||||||
|
|
||||||
private Uri uri;
|
|
||||||
private InputStream inputSteam;
|
|
||||||
|
|
||||||
PartDataSource(@NonNull Context context, @Nullable TransferListener listener) {
|
|
||||||
this.context = context.getApplicationContext();
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTransferListener(TransferListener transferListener) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long open(DataSpec dataSpec) throws IOException {
|
|
||||||
this.uri = dataSpec.uri;
|
|
||||||
|
|
||||||
AttachmentDatabase attachmentDatabase = DatabaseComponent.get(context).attachmentDatabase();
|
|
||||||
PartUriParser partUri = new PartUriParser(uri);
|
|
||||||
Attachment attachment = attachmentDatabase.getAttachment(partUri.getPartId());
|
|
||||||
|
|
||||||
if (attachment == null) throw new IOException("Attachment not found");
|
|
||||||
|
|
||||||
this.inputSteam = attachmentDatabase.getAttachmentStream(partUri.getPartId(), dataSpec.position);
|
|
||||||
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onTransferStart(this, dataSpec, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attachment.getSize() - dataSpec.position <= 0) throw new EOFException("No more data");
|
|
||||||
|
|
||||||
return attachment.getSize() - dataSpec.position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(byte[] buffer, int offset, int readLength) throws IOException {
|
|
||||||
int read = inputSteam.read(buffer, offset, readLength);
|
|
||||||
|
|
||||||
if (read > 0 && listener != null) {
|
|
||||||
listener.onBytesTransferred(this, null, false, read);
|
|
||||||
}
|
|
||||||
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Uri getUri() {
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, List<String>> getResponseHeaders() {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
inputSteam.close();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue