Update remaining DataSource's with new addTransferListener method.

The new method allows to add TransferListeners after the DataSource
has been created. Most implementations just forward to their wrapped
upstream DataSource. Implementation which directly read data implement
BaseDataSource instead.

Also removes the temporary default no-op implementation in DataSource.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=206289986
This commit is contained in:
tonihei 2018-07-27 02:19:53 -07:00 committed by Oliver Woodman
parent 3b61a400c5
commit d3c2cb2aa4
3 changed files with 12 additions and 5 deletions

View file

@ -44,9 +44,7 @@ public interface DataSource {
*
* @param transferListener A {@link TransferListener}.
*/
default void addTransferListener(TransferListener transferListener) {
// TODO: Make non-default once all DataSources implement this method.
}
void addTransferListener(TransferListener transferListener);
/**
* Opens the source to read the specified data.

View file

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.upstream;
import android.net.Uri;
import android.support.annotation.Nullable;
import java.io.IOException;
/**
@ -35,6 +36,11 @@ public final class DummyDataSource implements DataSource {
private DummyDataSource() {}
@Override
public void addTransferListener(TransferListener transferListener) {
// Do nothing.
}
@Override
public long open(DataSpec dataSpec) throws IOException {
throw new IOException("Dummy source");
@ -46,7 +52,7 @@ public final class DummyDataSource implements DataSource {
}
@Override
public Uri getUri() {
public @Nullable Uri getUri() {
return null;
}
@ -54,5 +60,4 @@ public final class DummyDataSource implements DataSource {
public void close() throws IOException {
// do nothing.
}
}

View file

@ -21,6 +21,7 @@ import android.net.Uri;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -76,6 +77,9 @@ public class Aes128DataSourceTest {
public boolean opened;
public boolean closedCalled;
@Override
public void addTransferListener(TransferListener transferListener) {}
@Override
public long open(DataSpec dataSpec) throws IOException {
opened = true;