Use lamdas everywhere
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=209162373
This commit is contained in:
parent
0831f6cab3
commit
bd8a956d53
@ -30,8 +30,6 @@ import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
@ -145,13 +143,9 @@ public class MainActivity extends AppCompatActivity implements OnClickListener,
|
||||
ListView sampleList = dialogList.findViewById(R.id.sample_list);
|
||||
sampleList.setAdapter(new SampleListAdapter(this));
|
||||
sampleList.setOnItemClickListener(
|
||||
new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
playerManager.addItem(DemoUtil.SAMPLES.get(position));
|
||||
mediaQueueListAdapter.notifyItemInserted(playerManager.getMediaQueueSize() - 1);
|
||||
}
|
||||
(parent, view, position, id) -> {
|
||||
playerManager.addItem(DemoUtil.SAMPLES.get(position));
|
||||
mediaQueueListAdapter.notifyItemInserted(playerManager.getMediaQueueSize() - 1);
|
||||
});
|
||||
return dialogList;
|
||||
}
|
||||
|
@ -175,14 +175,11 @@ public class DownloadTracker implements DownloadManager.Listener {
|
||||
}
|
||||
final DownloadAction[] actions = trackedDownloadStates.values().toArray(new DownloadAction[0]);
|
||||
actionFileWriteHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
actionFile.store(actions);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to store tracked actions", e);
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
actionFile.store(actions);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to store tracked actions", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.ShadowSystemClock;
|
||||
|
||||
@ -170,16 +168,13 @@ public final class CronetDataSourceTest {
|
||||
final UrlRequest mockUrlRequest2 = mock(UrlRequest.class);
|
||||
when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest2);
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
// Invoke the callback for the previous request.
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest, testUrlResponseInfo, mockNetworkException);
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest2, testUrlResponseInfo);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
// Invoke the callback for the previous request.
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest, testUrlResponseInfo, mockNetworkException);
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest2, testUrlResponseInfo);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest2)
|
||||
.start();
|
||||
@ -900,14 +895,11 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockStatusResponse() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
UrlRequest.StatusListener statusListener =
|
||||
(UrlRequest.StatusListener) invocation.getArguments()[0];
|
||||
statusListener.onStatus(TEST_CONNECTION_STATUS);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
UrlRequest.StatusListener statusListener =
|
||||
(UrlRequest.StatusListener) invocation.getArguments()[0];
|
||||
statusListener.onStatus(TEST_CONNECTION_STATUS);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.getStatus(any(UrlRequest.StatusListener.class));
|
||||
@ -915,13 +907,10 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockResponseStartSuccess() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.start();
|
||||
@ -929,15 +918,12 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockResponseStartRedirect() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
dataSourceUnderTest.urlRequestCallback.onRedirectReceived(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(307), // statusCode
|
||||
"http://redirect.location.com");
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
dataSourceUnderTest.urlRequestCallback.onRedirectReceived(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(307), // statusCode
|
||||
"http://redirect.location.com");
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.start();
|
||||
@ -945,21 +931,18 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockSingleRedirectSuccess() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!redirectCalled) {
|
||||
redirectCalled = true;
|
||||
dataSourceUnderTest.urlRequestCallback.onRedirectReceived(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfoWithUrl("http://example.com/video", 300),
|
||||
"http://example.com/video/redirect");
|
||||
} else {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
}
|
||||
return null;
|
||||
invocation -> {
|
||||
if (!redirectCalled) {
|
||||
redirectCalled = true;
|
||||
dataSourceUnderTest.urlRequestCallback.onRedirectReceived(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfoWithUrl("http://example.com/video", 300),
|
||||
"http://example.com/video/redirect");
|
||||
} else {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.start();
|
||||
@ -967,13 +950,10 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockFollowRedirectSuccess() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
dataSourceUnderTest.urlRequestCallback.onResponseStarted(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.followRedirect();
|
||||
@ -981,15 +961,12 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockResponseStartFailure() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(500), // statusCode
|
||||
mockNetworkException);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(500), // statusCode
|
||||
mockNetworkException);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.start();
|
||||
@ -998,23 +975,20 @@ public final class CronetDataSourceTest {
|
||||
private void mockReadSuccess(int position, int length) {
|
||||
final int[] positionAndRemaining = new int[] {position, length};
|
||||
doAnswer(
|
||||
new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (positionAndRemaining[1] == 0) {
|
||||
dataSourceUnderTest.urlRequestCallback.onSucceeded(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
} else {
|
||||
ByteBuffer inputBuffer = (ByteBuffer) invocation.getArguments()[0];
|
||||
int readLength = Math.min(positionAndRemaining[1], inputBuffer.remaining());
|
||||
inputBuffer.put(buildTestDataBuffer(positionAndRemaining[0], readLength));
|
||||
positionAndRemaining[0] += readLength;
|
||||
positionAndRemaining[1] -= readLength;
|
||||
dataSourceUnderTest.urlRequestCallback.onReadCompleted(
|
||||
mockUrlRequest, testUrlResponseInfo, inputBuffer);
|
||||
}
|
||||
return null;
|
||||
invocation -> {
|
||||
if (positionAndRemaining[1] == 0) {
|
||||
dataSourceUnderTest.urlRequestCallback.onSucceeded(
|
||||
mockUrlRequest, testUrlResponseInfo);
|
||||
} else {
|
||||
ByteBuffer inputBuffer = (ByteBuffer) invocation.getArguments()[0];
|
||||
int readLength = Math.min(positionAndRemaining[1], inputBuffer.remaining());
|
||||
inputBuffer.put(buildTestDataBuffer(positionAndRemaining[0], readLength));
|
||||
positionAndRemaining[0] += readLength;
|
||||
positionAndRemaining[1] -= readLength;
|
||||
dataSourceUnderTest.urlRequestCallback.onReadCompleted(
|
||||
mockUrlRequest, testUrlResponseInfo, inputBuffer);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.read(any(ByteBuffer.class));
|
||||
@ -1022,15 +996,12 @@ public final class CronetDataSourceTest {
|
||||
|
||||
private void mockReadFailure() {
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(500), // statusCode
|
||||
mockNetworkException);
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
dataSourceUnderTest.urlRequestCallback.onFailed(
|
||||
mockUrlRequest,
|
||||
createUrlResponseInfo(500), // statusCode
|
||||
mockNetworkException);
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.read(any(ByteBuffer.class));
|
||||
@ -1039,12 +1010,9 @@ public final class CronetDataSourceTest {
|
||||
private ConditionVariable buildReadStartedCondition() {
|
||||
final ConditionVariable startedCondition = new ConditionVariable();
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
startedCondition.open();
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
startedCondition.open();
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.read(any(ByteBuffer.class));
|
||||
@ -1054,12 +1022,9 @@ public final class CronetDataSourceTest {
|
||||
private ConditionVariable buildUrlRequestStartedCondition() {
|
||||
final ConditionVariable startedCondition = new ConditionVariable();
|
||||
doAnswer(
|
||||
new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
startedCondition.open();
|
||||
return null;
|
||||
}
|
||||
invocation -> {
|
||||
startedCondition.open();
|
||||
return null;
|
||||
})
|
||||
.when(mockUrlRequest)
|
||||
.start();
|
||||
|
@ -16,9 +16,7 @@
|
||||
package com.google.android.exoplayer2.ext.flac;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
|
||||
/**
|
||||
* Unit test for {@link FlacExtractor}.
|
||||
@ -35,25 +33,11 @@ public class FlacExtractorTest extends InstrumentationTestCase {
|
||||
|
||||
public void testExtractFlacSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new FlacExtractor();
|
||||
}
|
||||
},
|
||||
"bear.flac",
|
||||
getInstrumentation().getContext());
|
||||
FlacExtractor::new, "bear.flac", getInstrumentation().getContext());
|
||||
}
|
||||
|
||||
public void testExtractFlacSampleWithId3Header() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new FlacExtractor();
|
||||
}
|
||||
},
|
||||
"bear_with_id3.flac",
|
||||
getInstrumentation().getContext());
|
||||
FlacExtractor::new, "bear_with_id3.flac", getInstrumentation().getContext());
|
||||
}
|
||||
}
|
||||
|
@ -853,15 +853,12 @@ import java.util.Collections;
|
||||
private void sendMessageToTargetThread(final PlayerMessage message) {
|
||||
Handler handler = message.getHandler();
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
deliverMessage(message);
|
||||
} catch (ExoPlaybackException e) {
|
||||
Log.e(TAG, "Unexpected error delivering message on external thread.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
deliverMessage(message);
|
||||
} catch (ExoPlaybackException e) {
|
||||
Log.e(TAG, "Unexpected error delivering message on external thread.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -104,12 +104,7 @@ public interface AudioRendererEventListener {
|
||||
*/
|
||||
public void enabled(final DecoderCounters decoderCounters) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAudioEnabled(decoderCounters);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onAudioEnabled(decoderCounters));
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,13 +114,10 @@ public interface AudioRendererEventListener {
|
||||
public void decoderInitialized(final String decoderName,
|
||||
final long initializedTimestampMs, final long initializationDurationMs) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAudioDecoderInitialized(decoderName, initializedTimestampMs,
|
||||
initializationDurationMs);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() ->
|
||||
listener.onAudioDecoderInitialized(
|
||||
decoderName, initializedTimestampMs, initializationDurationMs));
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,12 +126,7 @@ public interface AudioRendererEventListener {
|
||||
*/
|
||||
public void inputFormatChanged(final Format format) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAudioInputFormatChanged(format);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onAudioInputFormatChanged(format));
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,12 +136,8 @@ public interface AudioRendererEventListener {
|
||||
public void audioTrackUnderrun(final int bufferSize, final long bufferSizeMs,
|
||||
final long elapsedSinceLastFeedMs) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() -> listener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs));
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,13 +146,11 @@ public interface AudioRendererEventListener {
|
||||
*/
|
||||
public void disabled(final DecoderCounters counters) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
counters.ensureUpdated();
|
||||
listener.onAudioDisabled(counters);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() -> {
|
||||
counters.ensureUpdated();
|
||||
listener.onAudioDisabled(counters);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,12 +159,7 @@ public interface AudioRendererEventListener {
|
||||
*/
|
||||
public void audioSessionId(final int audioSessionId) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAudioSessionId(audioSessionId);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onAudioSessionId(audioSessionId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,6 @@ import android.media.MediaDrm;
|
||||
import android.media.MediaDrmException;
|
||||
import android.media.NotProvisionedException;
|
||||
import android.media.UnsupportedSchemeException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.extractor.mp4.PsshAtomUtil;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
@ -80,13 +78,11 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
|
||||
@Override
|
||||
public void setOnEventListener(
|
||||
final ExoMediaDrm.OnEventListener<? super FrameworkMediaCrypto> listener) {
|
||||
mediaDrm.setOnEventListener(listener == null ? null : new MediaDrm.OnEventListener() {
|
||||
@Override
|
||||
public void onEvent(@NonNull MediaDrm md, @Nullable byte[] sessionId, int event, int extra,
|
||||
byte[] data) {
|
||||
listener.onEvent(FrameworkMediaDrm.this, sessionId, event, extra, data);
|
||||
}
|
||||
});
|
||||
mediaDrm.setOnEventListener(
|
||||
listener == null
|
||||
? null
|
||||
: (mediaDrm, sessionId, event, extra, data) ->
|
||||
listener.onEvent(FrameworkMediaDrm.this, sessionId, event, extra, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,20 +95,13 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
|
||||
mediaDrm.setOnKeyStatusChangeListener(
|
||||
listener == null
|
||||
? null
|
||||
: new MediaDrm.OnKeyStatusChangeListener() {
|
||||
@Override
|
||||
public void onKeyStatusChange(
|
||||
@NonNull MediaDrm md,
|
||||
@NonNull byte[] sessionId,
|
||||
@NonNull List<MediaDrm.KeyStatus> keyInfo,
|
||||
boolean hasNewUsableKey) {
|
||||
List<KeyStatus> exoKeyInfo = new ArrayList<>();
|
||||
for (MediaDrm.KeyStatus keyStatus : keyInfo) {
|
||||
exoKeyInfo.add(new KeyStatus(keyStatus.getStatusCode(), keyStatus.getKeyId()));
|
||||
}
|
||||
listener.onKeyStatusChange(
|
||||
FrameworkMediaDrm.this, sessionId, exoKeyInfo, hasNewUsableKey);
|
||||
: (mediaDrm, sessionId, keyInfo, hasNewUsableKey) -> {
|
||||
List<KeyStatus> exoKeyInfo = new ArrayList<>();
|
||||
for (MediaDrm.KeyStatus keyStatus : keyInfo) {
|
||||
exoKeyInfo.add(new KeyStatus(keyStatus.getStatusCode(), keyStatus.getKeyId()));
|
||||
}
|
||||
listener.onKeyStatusChange(
|
||||
FrameworkMediaDrm.this, sessionId, exoKeyInfo, hasNewUsableKey);
|
||||
},
|
||||
null);
|
||||
}
|
||||
|
@ -29,16 +29,13 @@ import java.util.regex.Pattern;
|
||||
public final class GaplessInfoHolder {
|
||||
|
||||
/**
|
||||
* A {@link FramePredicate} suitable for use when decoding {@link Metadata} that will be passed
|
||||
* to {@link #setFromMetadata(Metadata)}. Only frames that might contain gapless playback
|
||||
* information are decoded.
|
||||
* A {@link FramePredicate} suitable for use when decoding {@link Metadata} that will be passed to
|
||||
* {@link #setFromMetadata(Metadata)}. Only frames that might contain gapless playback information
|
||||
* are decoded.
|
||||
*/
|
||||
public static final FramePredicate GAPLESS_INFO_ID3_FRAME_PREDICATE = new FramePredicate() {
|
||||
@Override
|
||||
public boolean evaluate(int majorVersion, int id0, int id1, int id2, int id3) {
|
||||
return id0 == 'C' && id1 == 'O' && id2 == 'M' && (id3 == 'M' || majorVersion == 2);
|
||||
}
|
||||
};
|
||||
public static final FramePredicate GAPLESS_INFO_ID3_FRAME_PREDICATE =
|
||||
(majorVersion, id0, id1, id2, id3) ->
|
||||
id0 == 'C' && id1 == 'O' && id2 == 'M' && (id3 == 'M' || majorVersion == 2);
|
||||
|
||||
private static final String GAPLESS_DOMAIN = "com.apple.iTunes";
|
||||
private static final String GAPLESS_DESCRIPTION = "iTunSMPB";
|
||||
|
@ -56,13 +56,7 @@ public final class Id3Decoder implements MetadataDecoder {
|
||||
|
||||
/** A predicate that indicates no frames should be decoded. */
|
||||
public static final FramePredicate NO_FRAMES_PREDICATE =
|
||||
new FramePredicate() {
|
||||
|
||||
@Override
|
||||
public boolean evaluate(int majorVersion, int id0, int id1, int id2, int id3) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
(majorVersion, id0, id1, id2, id3) -> false;
|
||||
|
||||
private static final String TAG = "Id3Decoder";
|
||||
|
||||
|
@ -59,21 +59,9 @@ public abstract class DownloadHelper {
|
||||
public void run() {
|
||||
try {
|
||||
prepareInternal();
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onPrepared(DownloadHelper.this);
|
||||
}
|
||||
});
|
||||
handler.post(() -> callback.onPrepared(DownloadHelper.this));
|
||||
} catch (final IOException e) {
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onPrepareError(DownloadHelper.this, e);
|
||||
}
|
||||
});
|
||||
handler.post(() -> callback.onPrepareError(DownloadHelper.this, e));
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
@ -336,12 +336,7 @@ public final class DownloadManager {
|
||||
tasks.get(i).stop();
|
||||
}
|
||||
final ConditionVariable fileIOFinishedCondition = new ConditionVariable();
|
||||
fileIOHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fileIOFinishedCondition.open();
|
||||
}
|
||||
});
|
||||
fileIOHandler.post(fileIOFinishedCondition::open);
|
||||
fileIOFinishedCondition.block();
|
||||
fileIOThread.quit();
|
||||
logd("Released");
|
||||
@ -451,51 +446,45 @@ public final class DownloadManager {
|
||||
|
||||
private void loadActions() {
|
||||
fileIOHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DownloadAction[] loadedActions;
|
||||
try {
|
||||
loadedActions = actionFile.load(DownloadManager.this.deserializers);
|
||||
logd("Action file is loaded.");
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, "Action file loading failed.", e);
|
||||
loadedActions = new DownloadAction[0];
|
||||
}
|
||||
final DownloadAction[] actions = loadedActions;
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (released) {
|
||||
return;
|
||||
}
|
||||
List<Task> pendingTasks = new ArrayList<>(tasks);
|
||||
tasks.clear();
|
||||
for (DownloadAction action : actions) {
|
||||
addTaskForAction(action);
|
||||
}
|
||||
logd("Tasks are created.");
|
||||
initialized = true;
|
||||
for (Listener listener : listeners) {
|
||||
listener.onInitialized(DownloadManager.this);
|
||||
}
|
||||
if (!pendingTasks.isEmpty()) {
|
||||
tasks.addAll(pendingTasks);
|
||||
saveActions();
|
||||
}
|
||||
maybeStartTasks();
|
||||
for (int i = 0; i < tasks.size(); i++) {
|
||||
Task task = tasks.get(i);
|
||||
if (task.currentState == STATE_QUEUED) {
|
||||
// Task did not change out of its initial state, and so its initial state
|
||||
// won't have been reported to listeners. Do so now.
|
||||
notifyListenersTaskStateChange(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
() -> {
|
||||
DownloadAction[] loadedActions;
|
||||
try {
|
||||
loadedActions = actionFile.load(DownloadManager.this.deserializers);
|
||||
logd("Action file is loaded.");
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, "Action file loading failed.", e);
|
||||
loadedActions = new DownloadAction[0];
|
||||
}
|
||||
final DownloadAction[] actions = loadedActions;
|
||||
handler.post(
|
||||
() -> {
|
||||
if (released) {
|
||||
return;
|
||||
}
|
||||
List<Task> pendingTasks = new ArrayList<>(tasks);
|
||||
tasks.clear();
|
||||
for (DownloadAction action : actions) {
|
||||
addTaskForAction(action);
|
||||
}
|
||||
logd("Tasks are created.");
|
||||
initialized = true;
|
||||
for (Listener listener : listeners) {
|
||||
listener.onInitialized(DownloadManager.this);
|
||||
}
|
||||
if (!pendingTasks.isEmpty()) {
|
||||
tasks.addAll(pendingTasks);
|
||||
saveActions();
|
||||
}
|
||||
maybeStartTasks();
|
||||
for (int i = 0; i < tasks.size(); i++) {
|
||||
Task task = tasks.get(i);
|
||||
if (task.currentState == STATE_QUEUED) {
|
||||
// Task did not change out of its initial state, and so its initial state
|
||||
// won't have been reported to listeners. Do so now.
|
||||
notifyListenersTaskStateChange(task);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -507,17 +496,15 @@ public final class DownloadManager {
|
||||
for (int i = 0; i < tasks.size(); i++) {
|
||||
actions[i] = tasks.get(i).action;
|
||||
}
|
||||
fileIOHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
actionFile.store(actions);
|
||||
logd("Actions persisted.");
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Persisting actions failed.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
fileIOHandler.post(
|
||||
() -> {
|
||||
try {
|
||||
actionFile.store(actions);
|
||||
logd("Actions persisted.");
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Persisting actions failed.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void logd(String message) {
|
||||
@ -771,12 +758,7 @@ public final class DownloadManager {
|
||||
private void cancel() {
|
||||
if (changeStateAndNotify(STATE_QUEUED, STATE_QUEUED_CANCELING)) {
|
||||
downloadManager.handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
changeStateAndNotify(STATE_QUEUED_CANCELING, STATE_CANCELED);
|
||||
}
|
||||
});
|
||||
() -> changeStateAndNotify(STATE_QUEUED_CANCELING, STATE_CANCELED));
|
||||
} else if (changeStateAndNotify(STATE_STARTED, STATE_STARTED_CANCELING)) {
|
||||
cancelDownload();
|
||||
}
|
||||
@ -851,19 +833,14 @@ public final class DownloadManager {
|
||||
}
|
||||
final Throwable finalError = error;
|
||||
downloadManager.handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (changeStateAndNotify(
|
||||
STATE_STARTED,
|
||||
finalError != null ? STATE_FAILED : STATE_COMPLETED,
|
||||
finalError)
|
||||
|| changeStateAndNotify(STATE_STARTED_CANCELING, STATE_CANCELED)
|
||||
|| changeStateAndNotify(STATE_STARTED_STOPPING, STATE_QUEUED)) {
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
() -> {
|
||||
if (changeStateAndNotify(
|
||||
STATE_STARTED, finalError != null ? STATE_FAILED : STATE_COMPLETED, finalError)
|
||||
|| changeStateAndNotify(STATE_STARTED_CANCELING, STATE_CANCELED)
|
||||
|| changeStateAndNotify(STATE_STARTED_STOPPING, STATE_QUEUED)) {
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -101,13 +101,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||
protected final void prepareChildSource(final T id, MediaSource mediaSource) {
|
||||
Assertions.checkArgument(!childSources.containsKey(id));
|
||||
SourceInfoRefreshListener sourceListener =
|
||||
new SourceInfoRefreshListener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(
|
||||
MediaSource source, Timeline timeline, @Nullable Object manifest) {
|
||||
onChildSourceInfoRefreshed(id, source, timeline, manifest);
|
||||
}
|
||||
};
|
||||
(source, timeline, manifest) -> onChildSourceInfoRefreshed(id, source, timeline, manifest);
|
||||
MediaSourceEventListener eventListener = new ForwardingEventListener(id);
|
||||
childSources.put(id, new MediaSourceAndListener(mediaSource, sourceListener, eventListener));
|
||||
mediaSource.addEventListener(Assertions.checkNotNull(eventHandler), eventListener);
|
||||
|
@ -325,12 +325,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
final ComponentListener componentListener = new ComponentListener();
|
||||
this.componentListener = componentListener;
|
||||
prepareChildSource(DUMMY_CONTENT_MEDIA_PERIOD_ID, contentMediaSource);
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adsLoader.attachPlayer(player, componentListener, adUiViewGroup);
|
||||
}
|
||||
});
|
||||
mainHandler.post(() -> adsLoader.attachPlayer(player, componentListener, adUiViewGroup));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -397,12 +392,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
adPlaybackState = null;
|
||||
adGroupMediaSources = new MediaSource[0][];
|
||||
adDurationsUs = new long[0][];
|
||||
mainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adsLoader.detachPlayer();
|
||||
}
|
||||
});
|
||||
mainHandler.post(adsLoader::detachPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -500,15 +490,13 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
if (released) {
|
||||
return;
|
||||
}
|
||||
playerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (released) {
|
||||
return;
|
||||
}
|
||||
AdsMediaSource.this.onAdPlaybackState(adPlaybackState);
|
||||
}
|
||||
});
|
||||
playerHandler.post(
|
||||
() -> {
|
||||
if (released) {
|
||||
return;
|
||||
}
|
||||
AdsMediaSource.this.onAdPlaybackState(adPlaybackState);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -517,14 +505,12 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
return;
|
||||
}
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!released) {
|
||||
eventListener.onAdClicked();
|
||||
}
|
||||
}
|
||||
});
|
||||
eventHandler.post(
|
||||
() -> {
|
||||
if (!released) {
|
||||
eventListener.onAdClicked();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,14 +520,12 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
return;
|
||||
}
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!released) {
|
||||
eventListener.onAdTapped();
|
||||
}
|
||||
}
|
||||
});
|
||||
eventHandler.post(
|
||||
() -> {
|
||||
if (!released) {
|
||||
eventListener.onAdTapped();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,15 +546,12 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
/* wasCanceled= */ true);
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!released) {
|
||||
if (error.type == AdLoadException.TYPE_UNEXPECTED) {
|
||||
eventListener.onInternalAdLoadError(error.getRuntimeExceptionForUnexpected());
|
||||
} else {
|
||||
eventListener.onAdLoadError(error);
|
||||
}
|
||||
() -> {
|
||||
if (!released) {
|
||||
if (error.type == AdLoadException.TYPE_UNEXPECTED) {
|
||||
eventListener.onInternalAdLoadError(error.getRuntimeExceptionForUnexpected());
|
||||
} else {
|
||||
eventListener.onAdLoadError(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -603,12 +584,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||
AdLoadException.createForAd(exception),
|
||||
/* wasCanceled= */ true);
|
||||
mainHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adsLoader.handlePrepareError(adGroupIndex, adIndexInAdGroup, exception);
|
||||
}
|
||||
});
|
||||
() -> adsLoader.handlePrepareError(adGroupIndex, adIndexInAdGroup, exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,7 @@ public final class DummyDataSource implements DataSource {
|
||||
public static final DummyDataSource INSTANCE = new DummyDataSource();
|
||||
|
||||
/** A factory that produces {@link DummyDataSource}. */
|
||||
public static final Factory FACTORY = new Factory() {
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
return new DummyDataSource();
|
||||
}
|
||||
};
|
||||
public static final Factory FACTORY = DummyDataSource::new;
|
||||
|
||||
private DummyDataSource() {}
|
||||
|
||||
|
@ -211,20 +211,15 @@ public interface HttpDataSource extends DataSource {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Predicate} that rejects content types often used for pay-walls.
|
||||
*/
|
||||
Predicate<String> REJECT_PAYWALL_TYPES = new Predicate<String>() {
|
||||
|
||||
@Override
|
||||
public boolean evaluate(String contentType) {
|
||||
contentType = Util.toLowerInvariant(contentType);
|
||||
return !TextUtils.isEmpty(contentType)
|
||||
&& (!contentType.contains("text") || contentType.contains("text/vtt"))
|
||||
&& !contentType.contains("html") && !contentType.contains("xml");
|
||||
}
|
||||
|
||||
};
|
||||
/** A {@link Predicate} that rejects content types often used for pay-walls. */
|
||||
Predicate<String> REJECT_PAYWALL_TYPES =
|
||||
contentType -> {
|
||||
contentType = Util.toLowerInvariant(contentType);
|
||||
return !TextUtils.isEmpty(contentType)
|
||||
&& (!contentType.contains("text") || contentType.contains("text/vtt"))
|
||||
&& !contentType.contains("html")
|
||||
&& !contentType.contains("xml");
|
||||
};
|
||||
|
||||
/**
|
||||
* Thrown when an error is encountered when trying to read from a {@link HttpDataSource}.
|
||||
|
@ -55,13 +55,7 @@ public final class CacheUtil {
|
||||
public static final int DEFAULT_BUFFER_SIZE_BYTES = 128 * 1024;
|
||||
|
||||
/** Default {@link CacheKeyFactory} that calls through to {@link #getKey}. */
|
||||
public static final CacheKeyFactory DEFAULT_CACHE_KEY_FACTORY =
|
||||
new CacheKeyFactory() {
|
||||
@Override
|
||||
public String buildCacheKey(DataSpec dataSpec) {
|
||||
return getKey(dataSpec);
|
||||
}
|
||||
};
|
||||
public static final CacheKeyFactory DEFAULT_CACHE_KEY_FACTORY = CacheUtil::getKey;
|
||||
|
||||
/**
|
||||
* Generates a cache key out of the given {@link Uri}.
|
||||
|
@ -35,19 +35,9 @@ import java.util.Comparator;
|
||||
public class SlidingPercentile {
|
||||
|
||||
// Orderings.
|
||||
private static final Comparator<Sample> INDEX_COMPARATOR = new Comparator<Sample>() {
|
||||
@Override
|
||||
public int compare(Sample a, Sample b) {
|
||||
return a.index - b.index;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Comparator<Sample> VALUE_COMPARATOR = new Comparator<Sample>() {
|
||||
@Override
|
||||
public int compare(Sample a, Sample b) {
|
||||
return a.value < b.value ? -1 : b.value < a.value ? 1 : 0;
|
||||
}
|
||||
};
|
||||
private static final Comparator<Sample> INDEX_COMPARATOR = (a, b) -> a.index - b.index;
|
||||
private static final Comparator<Sample> VALUE_COMPARATOR =
|
||||
(a, b) -> Float.compare(a.value, b.value);
|
||||
|
||||
private static final int SORT_ORDER_NONE = -1;
|
||||
private static final int SORT_ORDER_BY_VALUE = 0;
|
||||
|
@ -34,7 +34,6 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.security.NetworkSecurityPolicy;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@ -67,7 +66,6 @@ import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.DataFormatException;
|
||||
@ -341,12 +339,7 @@ public final class Util {
|
||||
* @return The executor.
|
||||
*/
|
||||
public static ExecutorService newSingleThreadExecutor(final String threadName) {
|
||||
return Executors.newSingleThreadExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(@NonNull Runnable r) {
|
||||
return new Thread(r, threadName);
|
||||
}
|
||||
});
|
||||
return Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, threadName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,12 +129,7 @@ public interface VideoRendererEventListener {
|
||||
*/
|
||||
public void enabled(final DecoderCounters decoderCounters) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onVideoEnabled(decoderCounters);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onVideoEnabled(decoderCounters));
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,13 +139,10 @@ public interface VideoRendererEventListener {
|
||||
public void decoderInitialized(final String decoderName,
|
||||
final long initializedTimestampMs, final long initializationDurationMs) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onVideoDecoderInitialized(decoderName, initializedTimestampMs,
|
||||
initializationDurationMs);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() ->
|
||||
listener.onVideoDecoderInitialized(
|
||||
decoderName, initializedTimestampMs, initializationDurationMs));
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,12 +151,7 @@ public interface VideoRendererEventListener {
|
||||
*/
|
||||
public void inputFormatChanged(final Format format) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onVideoInputFormatChanged(format);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onVideoInputFormatChanged(format));
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,12 +160,7 @@ public interface VideoRendererEventListener {
|
||||
*/
|
||||
public void droppedFrames(final int droppedFrameCount, final long elapsedMs) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onDroppedFrames(droppedFrameCount, elapsedMs);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onDroppedFrames(droppedFrameCount, elapsedMs));
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,13 +170,10 @@ public interface VideoRendererEventListener {
|
||||
public void videoSizeChanged(final int width, final int height,
|
||||
final int unappliedRotationDegrees, final float pixelWidthHeightRatio) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onVideoSizeChanged(width, height, unappliedRotationDegrees,
|
||||
pixelWidthHeightRatio);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() ->
|
||||
listener.onVideoSizeChanged(
|
||||
width, height, unappliedRotationDegrees, pixelWidthHeightRatio));
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,12 +182,7 @@ public interface VideoRendererEventListener {
|
||||
*/
|
||||
public void renderedFirstFrame(final Surface surface) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onRenderedFirstFrame(surface);
|
||||
}
|
||||
});
|
||||
handler.post(() -> listener.onRenderedFirstFrame(surface));
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,13 +191,11 @@ public interface VideoRendererEventListener {
|
||||
*/
|
||||
public void disabled(final DecoderCounters counters) {
|
||||
if (listener != null) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
counters.ensureUpdated();
|
||||
listener.onVideoDisabled(counters);
|
||||
}
|
||||
});
|
||||
handler.post(
|
||||
() -> {
|
||||
counters.ensureUpdated();
|
||||
listener.onVideoDisabled(counters);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,24 +277,15 @@ public final class ExoPlayerTest {
|
||||
.waitForTimelineChanged(timeline)
|
||||
.prepareSource(secondSource)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
queuedSourceInfoCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore.
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
queuedSourceInfoCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore.
|
||||
}
|
||||
})
|
||||
.prepareSource(thirdSource)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
completePreparationCountDownLatch.countDown();
|
||||
}
|
||||
})
|
||||
.executeRunnable(completePreparationCountDownLatch::countDown)
|
||||
.build();
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new Builder()
|
||||
@ -436,13 +427,7 @@ public final class ExoPlayerTest {
|
||||
new ActionSchedule.Builder("testAdGroupWithLoadErrorIsSkipped")
|
||||
.pause()
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fakeMediaSource.setNewSourceInfo(adErrorTimeline, null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> fakeMediaSource.setNewSourceInfo(adErrorTimeline, null))
|
||||
.waitForTimelineChanged(adErrorTimeline)
|
||||
.play()
|
||||
.build();
|
||||
@ -823,13 +808,7 @@ public final class ExoPlayerTest {
|
||||
new ActionSchedule.Builder("testDynamicTimelineChangeReason")
|
||||
.pause()
|
||||
.waitForTimelineChanged(timeline1)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(timeline2, null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2, null))
|
||||
.waitForTimelineChanged(timeline2)
|
||||
.play()
|
||||
.build();
|
||||
@ -911,26 +890,17 @@ public final class ExoPlayerTest {
|
||||
.waitForPlaybackState(Player.STATE_BUFFERING)
|
||||
// Block until createPeriod has been called on the fake media source.
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
createPeriodCalledCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
createPeriodCalledCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
})
|
||||
// Set playback parameters (while the fake media period is not yet prepared).
|
||||
.setPlaybackParameters(new PlaybackParameters(/* speed= */ 2f, /* pitch= */ 2f))
|
||||
// Complete preparation of the fake media period.
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fakeMediaPeriodHolder[0].setPreparationComplete();
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete())
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
@ -1280,13 +1250,7 @@ public final class ExoPlayerTest {
|
||||
// is still being prepared. The error will be thrown while the player handles the new
|
||||
// source info.
|
||||
.seek(/* windowIndex= */ 100, /* positionMs= */ 0)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(timeline, /* newManifest= */ null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> mediaSource.setNewSourceInfo(timeline, /* newManifest= */ null))
|
||||
.waitForPlaybackState(Player.STATE_IDLE)
|
||||
.build();
|
||||
ExoPlayerTestRunner testRunner =
|
||||
@ -1789,13 +1753,7 @@ public final class ExoPlayerTest {
|
||||
.pause()
|
||||
.waitForTimelineChanged(timeline)
|
||||
.sendMessage(target, /* positionMs= */ 50)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(secondTimeline, null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline, null))
|
||||
.waitForTimelineChanged(secondTimeline)
|
||||
.play()
|
||||
.build();
|
||||
@ -1868,13 +1826,7 @@ public final class ExoPlayerTest {
|
||||
.pause()
|
||||
.waitForTimelineChanged(timeline)
|
||||
.sendMessage(target, /* windowIndex = */ 1, /* positionMs= */ 50)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(secondTimeline, null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline, null))
|
||||
.waitForTimelineChanged(secondTimeline)
|
||||
.seek(/* windowIndex= */ 0, /* positionMs= */ 0)
|
||||
.play()
|
||||
@ -1943,13 +1895,7 @@ public final class ExoPlayerTest {
|
||||
})
|
||||
// Play a bit to ensure message arrived in internal player.
|
||||
.playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 30)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
message.get().cancel();
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> message.get().cancel())
|
||||
.play()
|
||||
.build();
|
||||
new Builder()
|
||||
@ -1987,13 +1933,7 @@ public final class ExoPlayerTest {
|
||||
.playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 51)
|
||||
// Seek back, cancel the message, and play past the same position again.
|
||||
.seek(/* positionMs= */ 0)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
message.get().cancel();
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> message.get().cancel())
|
||||
.play()
|
||||
.build();
|
||||
new Builder()
|
||||
@ -2064,13 +2004,7 @@ public final class ExoPlayerTest {
|
||||
.playUntilPosition(
|
||||
/* windowIndex= */ 0,
|
||||
/* positionMs= */ C.usToMs(TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US))
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.setNewSourceInfo(timeline2, /* newManifest= */ null);
|
||||
}
|
||||
})
|
||||
.executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2, /* newManifest= */ null))
|
||||
.waitForTimelineChanged(timeline2)
|
||||
.play()
|
||||
.build();
|
||||
|
@ -17,9 +17,6 @@ package com.google.android.exoplayer2.analytics;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -35,10 +32,7 @@ import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.Timeline.Window;
|
||||
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.MetadataOutput;
|
||||
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
@ -53,7 +47,6 @@ import com.google.android.exoplayer2.testutil.FakeMediaSource;
|
||||
import com.google.android.exoplayer2.testutil.FakeRenderer;
|
||||
import com.google.android.exoplayer2.testutil.FakeTimeline;
|
||||
import com.google.android.exoplayer2.testutil.RobolectricUtil;
|
||||
import com.google.android.exoplayer2.text.TextOutput;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||
@ -601,13 +594,9 @@ public final class AnalyticsCollectorTest {
|
||||
// Ensure second period is already being read from.
|
||||
.playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ periodDurationMs)
|
||||
.executeRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
concatenatedMediaSource.moveMediaSource(
|
||||
/* currentIndex= */ 0, /* newIndex= */ 1);
|
||||
}
|
||||
})
|
||||
/* currentIndex= */ 0, /* newIndex= */ 1))
|
||||
.waitForTimelineChanged(/* expectedTimeline= */ null)
|
||||
.play()
|
||||
.build();
|
||||
@ -658,10 +647,6 @@ public final class AnalyticsCollectorTest {
|
||||
@Test
|
||||
public void testNotifyExternalEvents() throws Exception {
|
||||
MediaSource mediaSource = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, /* manifest= */ null);
|
||||
final NetworkInfo networkInfo =
|
||||
((ConnectivityManager)
|
||||
RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.getActiveNetworkInfo();
|
||||
ActionSchedule actionSchedule =
|
||||
new ActionSchedule.Builder("AnalyticsCollectorTest")
|
||||
.pause()
|
||||
@ -689,21 +674,16 @@ public final class AnalyticsCollectorTest {
|
||||
private static TestAnalyticsListener runAnalyticsTest(
|
||||
MediaSource mediaSource, @Nullable ActionSchedule actionSchedule) throws Exception {
|
||||
RenderersFactory renderersFactory =
|
||||
new RenderersFactory() {
|
||||
@Override
|
||||
public Renderer[] createRenderers(
|
||||
Handler eventHandler,
|
||||
VideoRendererEventListener videoRendererEventListener,
|
||||
AudioRendererEventListener audioRendererEventListener,
|
||||
TextOutput textRendererOutput,
|
||||
MetadataOutput metadataRendererOutput,
|
||||
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
|
||||
return new Renderer[] {
|
||||
(eventHandler,
|
||||
videoRendererEventListener,
|
||||
audioRendererEventListener,
|
||||
textRendererOutput,
|
||||
metadataRendererOutput,
|
||||
drmSessionManager) ->
|
||||
new Renderer[] {
|
||||
new FakeVideoRenderer(eventHandler, videoRendererEventListener),
|
||||
new FakeAudioRenderer(eventHandler, audioRendererEventListener)
|
||||
};
|
||||
}
|
||||
};
|
||||
TestAnalyticsListener listener = new TestAnalyticsListener();
|
||||
try {
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
|
@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
|
||||
import com.google.android.exoplayer2.metadata.id3.CommentFrame;
|
||||
import com.google.android.exoplayer2.metadata.id3.Id3Decoder;
|
||||
import com.google.android.exoplayer2.metadata.id3.Id3DecoderTest;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
import java.io.IOException;
|
||||
@ -95,12 +94,8 @@ public final class Id3PeekerTest {
|
||||
Metadata metadata =
|
||||
id3Peeker.peekId3Data(
|
||||
input,
|
||||
new Id3Decoder.FramePredicate() {
|
||||
@Override
|
||||
public boolean evaluate(int majorVersion, int id0, int id1, int id2, int id3) {
|
||||
return id0 == 'C' && id1 == 'O' && id2 == 'M' && id3 == 'M';
|
||||
}
|
||||
});
|
||||
(majorVersion, id0, id1, id2, id3) ->
|
||||
id0 == 'C' && id1 == 'O' && id2 == 'M' && id3 == 'M');
|
||||
assertThat(metadata.length()).isEqualTo(1);
|
||||
|
||||
CommentFrame commentFrame = (CommentFrame) metadata.get(0);
|
||||
|
@ -250,14 +250,11 @@ public final class AmrExtractorTest {
|
||||
|
||||
@NonNull
|
||||
private static ExtractorAsserts.ExtractorFactory createAmrExtractorFactory(boolean withSeeking) {
|
||||
return new ExtractorAsserts.ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
if (!withSeeking) {
|
||||
return new AmrExtractor();
|
||||
} else {
|
||||
return new AmrExtractor(AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING);
|
||||
}
|
||||
return () -> {
|
||||
if (!withSeeking) {
|
||||
return new AmrExtractor();
|
||||
} else {
|
||||
return new AmrExtractor(AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.flv;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,13 +26,6 @@ public final class FlvExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new FlvExtractor();
|
||||
}
|
||||
},
|
||||
"flv/sample.flv");
|
||||
ExtractorAsserts.assertBehavior(FlvExtractor::new, "flv/sample.flv");
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.mkv;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,37 +26,17 @@ public final class MatroskaExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testMkvSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new MatroskaExtractor();
|
||||
}
|
||||
},
|
||||
"mkv/sample.mkv");
|
||||
ExtractorAsserts.assertBehavior(MatroskaExtractor::new, "mkv/sample.mkv");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebmSubsampleEncryption() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new MatroskaExtractor();
|
||||
}
|
||||
},
|
||||
"mkv/subsample_encrypted_noaltref.webm");
|
||||
MatroskaExtractor::new, "mkv/subsample_encrypted_noaltref.webm");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebmSubsampleEncryptionWithAltrefFrames() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new MatroskaExtractor();
|
||||
}
|
||||
},
|
||||
"mkv/subsample_encrypted_altref.webm");
|
||||
ExtractorAsserts.assertBehavior(MatroskaExtractor::new, "mkv/subsample_encrypted_altref.webm");
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.mp3;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,25 +26,11 @@ public final class Mp3ExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testMp3Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new Mp3Extractor();
|
||||
}
|
||||
},
|
||||
"mp3/bear.mp3");
|
||||
ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/bear.mp3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrimmedMp3Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new Mp3Extractor();
|
||||
}
|
||||
},
|
||||
"mp3/play-trimmed.mp3");
|
||||
ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/play-trimmed.mp3");
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.google.android.exoplayer2.extractor.mp4;
|
||||
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
@ -53,11 +52,6 @@ public final class FragmentedMp4ExtractorTest {
|
||||
}
|
||||
|
||||
private static ExtractorFactory getExtractorFactory(final List<Format> closedCaptionFormats) {
|
||||
return new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new FragmentedMp4Extractor(0, null, null, null, closedCaptionFormats);
|
||||
}
|
||||
};
|
||||
return () -> new FragmentedMp4Extractor(0, null, null, null, closedCaptionFormats);
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,7 @@
|
||||
package com.google.android.exoplayer2.extractor.mp4;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -30,13 +28,6 @@ public final class Mp4ExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testMp4Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new Mp4Extractor();
|
||||
}
|
||||
},
|
||||
"mp4/sample.mp4");
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample.mp4");
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package com.google.android.exoplayer2.extractor.ogg;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
@ -32,13 +31,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class OggExtractorTest {
|
||||
|
||||
private static final ExtractorFactory OGG_EXTRACTOR_FACTORY =
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new OggExtractor();
|
||||
}
|
||||
};
|
||||
private static final ExtractorFactory OGG_EXTRACTOR_FACTORY = OggExtractor::new;
|
||||
|
||||
@Test
|
||||
public void testOpus() throws Exception {
|
||||
|
@ -17,9 +17,7 @@ package com.google.android.exoplayer2.extractor.rawcc;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -33,10 +31,8 @@ public final class RawCcExtractorTest {
|
||||
@Test
|
||||
public void testRawCcSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new RawCcExtractor(
|
||||
() ->
|
||||
new RawCcExtractor(
|
||||
Format.createTextContainerFormat(
|
||||
/* id= */ null,
|
||||
/* label= */ null,
|
||||
@ -46,9 +42,7 @@ public final class RawCcExtractorTest {
|
||||
/* bitrate= */ Format.NO_VALUE,
|
||||
/* selectionFlags= */ 0,
|
||||
/* language= */ null,
|
||||
/* accessibilityChannel= */ 1));
|
||||
}
|
||||
},
|
||||
/* accessibilityChannel= */ 1)),
|
||||
"rawcc/sample.rawcc");
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.ts;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,13 +26,6 @@ public final class Ac3ExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new Ac3Extractor();
|
||||
}
|
||||
},
|
||||
"ts/sample.ac3");
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample.ac3");
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.ts;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,27 +26,16 @@ public final class AdtsExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new AdtsExtractor();
|
||||
}
|
||||
},
|
||||
"ts/sample.adts");
|
||||
ExtractorAsserts.assertBehavior(AdtsExtractor::new, "ts/sample.adts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSample_withSeeking() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new AdtsExtractor(
|
||||
() ->
|
||||
new AdtsExtractor(
|
||||
/* firstStreamSampleTimestampUs= */ 0,
|
||||
/* flags= */ AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING);
|
||||
}
|
||||
},
|
||||
/* flags= */ AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING),
|
||||
"ts/sample_cbs.adts");
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.ts;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,13 +26,6 @@ public final class PsExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new PsExtractor();
|
||||
}
|
||||
},
|
||||
"ts/sample.ps");
|
||||
ExtractorAsserts.assertBehavior(PsExtractor::new, "ts/sample.ps");
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import com.google.android.exoplayer2.extractor.TrackOutput;
|
||||
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.EsInfo;
|
||||
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
|
||||
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
|
||||
@ -50,14 +49,7 @@ public final class TsExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new TsExtractor();
|
||||
}
|
||||
},
|
||||
"ts/sample.ts");
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample.ts");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -82,15 +74,7 @@ public final class TsExtractorTest {
|
||||
fileData = out.toByteArray();
|
||||
|
||||
ExtractorAsserts.assertOutput(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new TsExtractor();
|
||||
}
|
||||
},
|
||||
"ts/sample.ts",
|
||||
fileData,
|
||||
RuntimeEnvironment.application);
|
||||
TsExtractor::new, "ts/sample.ts", fileData, RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.extractor.wav;
|
||||
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.ExtractorFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@ -28,13 +26,6 @@ public final class WavExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
new ExtractorFactory() {
|
||||
@Override
|
||||
public Extractor create() {
|
||||
return new WavExtractor();
|
||||
}
|
||||
},
|
||||
"wav/sample.wav");
|
||||
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample.wav");
|
||||
}
|
||||
}
|
||||
|
@ -331,13 +331,7 @@ public class DownloadManagerTest {
|
||||
remove2Action.post().assertStarted();
|
||||
download2Action.post().assertDoesNotStart();
|
||||
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.stopDownloads();
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.stopDownloads());
|
||||
|
||||
download1Action.assertStopped();
|
||||
|
||||
@ -354,13 +348,7 @@ public class DownloadManagerTest {
|
||||
// New download actions can be added but they don't start.
|
||||
download3Action.post().assertDoesNotStart();
|
||||
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.startDownloads());
|
||||
|
||||
download2Action.assertStarted().unblock().assertCompleted();
|
||||
download3Action.assertStarted().unblock().assertCompleted();
|
||||
@ -380,24 +368,12 @@ public class DownloadManagerTest {
|
||||
// download3Action doesn't start as DM was configured to run two downloads in parallel.
|
||||
download3Action.post().assertDoesNotStart();
|
||||
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.stopDownloads();
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.stopDownloads());
|
||||
|
||||
// download1Action doesn't stop yet as it ignores interrupts.
|
||||
download2Action.assertStopped();
|
||||
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.startDownloads());
|
||||
|
||||
// download2Action starts immediately.
|
||||
download2Action.assertStarted();
|
||||
@ -421,22 +397,19 @@ public class DownloadManagerTest {
|
||||
}
|
||||
try {
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(
|
||||
Mockito.mock(Cache.class), DummyDataSource.FACTORY),
|
||||
maxActiveDownloadTasks,
|
||||
MIN_RETRY_COUNT,
|
||||
actionFile,
|
||||
ProgressiveDownloadAction.DESERIALIZER);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
() -> {
|
||||
downloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(
|
||||
Mockito.mock(Cache.class), DummyDataSource.FACTORY),
|
||||
maxActiveDownloadTasks,
|
||||
MIN_RETRY_COUNT,
|
||||
actionFile,
|
||||
ProgressiveDownloadAction.DESERIALIZER);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
});
|
||||
} catch (Throwable throwable) {
|
||||
throw new Exception(throwable);
|
||||
@ -445,13 +418,7 @@ public class DownloadManagerTest {
|
||||
|
||||
private void releaseDownloadManager() throws Exception {
|
||||
try {
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.release();
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.release());
|
||||
} catch (Throwable throwable) {
|
||||
throw new Exception(throwable);
|
||||
}
|
||||
@ -519,13 +486,7 @@ public class DownloadManagerTest {
|
||||
}
|
||||
|
||||
private FakeDownloadAction post() {
|
||||
runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadManager.handleAction(FakeDownloadAction.this);
|
||||
}
|
||||
});
|
||||
runOnMainThread(() -> downloadManager.handleAction(FakeDownloadAction.this));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -501,9 +501,7 @@ public final class ClippingMediaSourceTest {
|
||||
final MediaLoadData[] reportedMediaLoadData = new MediaLoadData[1];
|
||||
try {
|
||||
testRunner.runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
clippingMediaSource.addEventListener(
|
||||
new Handler(),
|
||||
new DefaultMediaSourceEventListener() {
|
||||
@ -514,9 +512,7 @@ public final class ClippingMediaSourceTest {
|
||||
MediaLoadData mediaLoadData) {
|
||||
reportedMediaLoadData[0] = mediaLoadData;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
testRunner.prepareSource();
|
||||
// Create period to send the test event configured above.
|
||||
testRunner.createPeriod(
|
||||
|
@ -247,12 +247,7 @@ public final class ConcatenatingMediaSourceTest {
|
||||
// Trigger source info refresh for lazy source and check that the timeline now contains all
|
||||
// information for all windows.
|
||||
testRunner.runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lazySources[1].setNewSourceInfo(createFakeTimeline(8), null);
|
||||
}
|
||||
});
|
||||
() -> lazySources[1].setNewSourceInfo(createFakeTimeline(8), null));
|
||||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 1, 9);
|
||||
TimelineAsserts.assertWindowTags(timeline, 111, 999);
|
||||
@ -292,12 +287,7 @@ public final class ConcatenatingMediaSourceTest {
|
||||
// Trigger source info refresh for lazy media source. Assert that now all information is
|
||||
// available again and the previously created period now also finished preparing.
|
||||
testRunner.runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lazySources[3].setNewSourceInfo(createFakeTimeline(7), null);
|
||||
}
|
||||
});
|
||||
() -> lazySources[3].setNewSourceInfo(createFakeTimeline(7), null));
|
||||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 8, 1, 2, 9);
|
||||
TimelineAsserts.assertWindowTags(timeline, 888, 111, 222, 999);
|
||||
@ -484,12 +474,7 @@ public final class ConcatenatingMediaSourceTest {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSource(createFakeMediaSource(), timelineGrabber);
|
||||
}
|
||||
});
|
||||
() -> mediaSource.addMediaSource(createFakeMediaSource(), timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||
} finally {
|
||||
@ -504,15 +489,11 @@ public final class ConcatenatingMediaSourceTest {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
@ -527,12 +508,8 @@ public final class ConcatenatingMediaSourceTest {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSource(/* index */ 0, createFakeMediaSource(), timelineGrabber);
|
||||
}
|
||||
});
|
||||
() ->
|
||||
mediaSource.addMediaSource(/* index */ 0, createFakeMediaSource(), timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||
} finally {
|
||||
@ -547,16 +524,12 @@ public final class ConcatenatingMediaSourceTest {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
mediaSource.addMediaSources(
|
||||
/* index */ 0,
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
@ -569,23 +542,12 @@ public final class ConcatenatingMediaSourceTest {
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
try {
|
||||
testRunner.prepareSource();
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSource(createFakeMediaSource());
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(() -> mediaSource.addMediaSource(createFakeMediaSource()));
|
||||
testRunner.assertTimelineChangeBlocking();
|
||||
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.removeMediaSource(/* index */ 0, timelineGrabber);
|
||||
}
|
||||
});
|
||||
() -> mediaSource.removeMediaSource(/* index */ 0, timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(0);
|
||||
} finally {
|
||||
@ -599,24 +561,15 @@ public final class ConcatenatingMediaSourceTest {
|
||||
try {
|
||||
testRunner.prepareSource();
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||
}
|
||||
});
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()})));
|
||||
testRunner.assertTimelineChangeBlocking();
|
||||
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.moveMediaSource(/* fromIndex */ 1, /* toIndex */ 0, timelineGrabber);
|
||||
}
|
||||
});
|
||||
() -> mediaSource.moveMediaSource(/* fromIndex */ 1, /* toIndex */ 0, timelineGrabber));
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
@ -849,23 +802,14 @@ public final class ConcatenatingMediaSourceTest {
|
||||
final FakeMediaSource unpreparedChildSource =
|
||||
new FakeMediaSource(/* timeline= */ null, /* manifest= */ null);
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSource(preparedChildSource);
|
||||
mediaSource.addMediaSource(unpreparedChildSource);
|
||||
}
|
||||
() -> {
|
||||
mediaSource.addMediaSource(preparedChildSource);
|
||||
mediaSource.addMediaSource(unpreparedChildSource);
|
||||
});
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.clear(timelineGrabber);
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(() -> mediaSource.clear(timelineGrabber));
|
||||
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertThat(timeline.isEmpty()).isTrue();
|
||||
|
@ -60,13 +60,7 @@ public final class CacheDataSourceTest {
|
||||
testDataUri = Uri.parse("test_data");
|
||||
fixedCacheKey = CacheUtil.generateKey(testDataUri);
|
||||
expectedCacheKey = fixedCacheKey;
|
||||
cacheKeyFactory =
|
||||
new CacheKeyFactory() {
|
||||
@Override
|
||||
public String buildCacheKey(DataSpec dataSpec) {
|
||||
return CACHE_KEY_PREFIX + "." + CacheUtil.generateKey(dataSpec.uri);
|
||||
}
|
||||
};
|
||||
cacheKeyFactory = dataSpec -> CACHE_KEY_PREFIX + "." + CacheUtil.generateKey(dataSpec.uri);
|
||||
tempFolder = Util.createTempDirectory(RuntimeEnvironment.application, "ExoPlayerTest");
|
||||
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor());
|
||||
}
|
||||
@ -366,13 +360,7 @@ public final class CacheDataSourceTest {
|
||||
// Insert an action just before the end of the data to fail the test if reading from upstream
|
||||
// reaches end of the data.
|
||||
fakeData
|
||||
.appendReadAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fail("Read from upstream shouldn't reach to the end of the data.");
|
||||
}
|
||||
})
|
||||
.appendReadAction(() -> fail("Read from upstream shouldn't reach to the end of the data."))
|
||||
.appendReadData(1);
|
||||
// Create cache read-only CacheDataSource.
|
||||
CacheDataSource cacheDataSource =
|
||||
@ -408,13 +396,7 @@ public final class CacheDataSourceTest {
|
||||
// Insert an action just before the end of the data to fail the test if reading from upstream
|
||||
// reaches end of the data.
|
||||
fakeData
|
||||
.appendReadAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fail("Read from upstream shouldn't reach to the end of the data.");
|
||||
}
|
||||
})
|
||||
.appendReadAction(() -> fail("Read from upstream shouldn't reach to the end of the data."))
|
||||
.appendReadData(1);
|
||||
|
||||
// Lock the content on the cache.
|
||||
|
@ -292,22 +292,15 @@ public final class CacheUtilTest {
|
||||
@Test
|
||||
public void testCachePolling() throws Exception {
|
||||
final CachingCounters counters = new CachingCounters();
|
||||
FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data")
|
||||
.appendReadData(TestUtil.buildTestData(100))
|
||||
.appendReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertCounters(counters, 0, 100, 300);
|
||||
}
|
||||
})
|
||||
.appendReadData(TestUtil.buildTestData(100))
|
||||
.appendReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertCounters(counters, 0, 200, 300);
|
||||
}
|
||||
})
|
||||
.appendReadData(TestUtil.buildTestData(100)).endData();
|
||||
FakeDataSet fakeDataSet =
|
||||
new FakeDataSet()
|
||||
.newData("test_data")
|
||||
.appendReadData(TestUtil.buildTestData(100))
|
||||
.appendReadAction(() -> assertCounters(counters, 0, 100, 300))
|
||||
.appendReadData(TestUtil.buildTestData(100))
|
||||
.appendReadAction(() -> assertCounters(counters, 0, 200, 300))
|
||||
.appendReadData(TestUtil.buildTestData(100))
|
||||
.endData();
|
||||
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
|
||||
|
||||
CacheUtil.cache(
|
||||
|
@ -37,8 +37,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@ -259,12 +257,12 @@ public class SimpleCacheTest {
|
||||
addCache(simpleCache, KEY_1, 0, 15);
|
||||
|
||||
// Make index.store() throw exception from now on.
|
||||
doAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
throw new Cache.CacheException("SimpleCacheTest");
|
||||
}
|
||||
}).when(index).store();
|
||||
doAnswer(
|
||||
invocation -> {
|
||||
throw new CacheException("SimpleCacheTest");
|
||||
})
|
||||
.when(index)
|
||||
.store();
|
||||
|
||||
// Adding more content will make LeastRecentlyUsedCacheEvictor evict previous content.
|
||||
try {
|
||||
|
@ -589,18 +589,8 @@ public final class DashMediaSource extends BaseMediaSource {
|
||||
} else {
|
||||
manifestCallback = new ManifestCallback();
|
||||
manifestLoadErrorThrower = new ManifestLoadErrorThrower();
|
||||
refreshManifestRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startLoadingManifest();
|
||||
}
|
||||
};
|
||||
simulateManifestRefreshRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
processManifest(false);
|
||||
}
|
||||
};
|
||||
refreshManifestRunnable = this::startLoadingManifest;
|
||||
simulateManifestRefreshRunnable = () -> processManifest(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,18 +110,14 @@ public class DownloadManagerDashTest {
|
||||
fakeDataSet
|
||||
.newData(TEST_MPD_URI)
|
||||
.appendReadAction(
|
||||
new Runnable() {
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Wait until interrupted.
|
||||
while (true) {
|
||||
Thread.sleep(100000);
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
() -> {
|
||||
try {
|
||||
// Wait until interrupted.
|
||||
while (true) {
|
||||
Thread.sleep(100000);
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
})
|
||||
.appendReadData(TEST_MPD)
|
||||
@ -130,13 +126,10 @@ public class DownloadManagerDashTest {
|
||||
// Run DM accessing code on UI/main thread as it should be. Also not to block handling of loaded
|
||||
// actions.
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Setup an Action and immediately release the DM.
|
||||
handleDownloadAction(fakeStreamKey1, fakeStreamKey2);
|
||||
downloadManager.release();
|
||||
}
|
||||
() -> {
|
||||
// Setup an Action and immediately release the DM.
|
||||
handleDownloadAction(fakeStreamKey1, fakeStreamKey2);
|
||||
downloadManager.release();
|
||||
});
|
||||
|
||||
assertThat(actionFile.exists()).isTrue();
|
||||
@ -146,13 +139,7 @@ public class DownloadManagerDashTest {
|
||||
// Revert fakeDataSet to normal.
|
||||
fakeDataSet.setData(TEST_MPD_URI, TEST_MPD);
|
||||
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createDownloadManager();
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(this::createDownloadManager);
|
||||
|
||||
// Block on the test thread.
|
||||
blockUntilTasksCompleteAndThrowAnyDownloadError();
|
||||
@ -178,13 +165,7 @@ public class DownloadManagerDashTest {
|
||||
public void testHandleInterferingDownloadAction() throws Throwable {
|
||||
fakeDataSet
|
||||
.newData("audio_segment_2")
|
||||
.appendReadAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleDownloadAction(fakeStreamKey2);
|
||||
}
|
||||
})
|
||||
.appendReadAction(() -> handleDownloadAction(fakeStreamKey2))
|
||||
.appendReadData(TestUtil.buildTestData(5))
|
||||
.endData();
|
||||
|
||||
@ -224,13 +205,7 @@ public class DownloadManagerDashTest {
|
||||
final ConditionVariable downloadInProgressCondition = new ConditionVariable();
|
||||
fakeDataSet
|
||||
.newData("audio_segment_2")
|
||||
.appendReadAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadInProgressCondition.open();
|
||||
}
|
||||
})
|
||||
.appendReadAction(downloadInProgressCondition::open)
|
||||
.appendReadData(TestUtil.buildTestData(5))
|
||||
.endData();
|
||||
|
||||
@ -259,24 +234,21 @@ public class DownloadManagerDashTest {
|
||||
|
||||
private void createDownloadManager() {
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Factory fakeDataSourceFactory =
|
||||
new FakeDataSource.Factory(null).setFakeDataSet(fakeDataSet);
|
||||
downloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(cache, fakeDataSourceFactory),
|
||||
/* maxSimultaneousDownloads= */ 1,
|
||||
/* minRetryCount= */ 3,
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
() -> {
|
||||
Factory fakeDataSourceFactory =
|
||||
new FakeDataSource.Factory(null).setFakeDataSet(fakeDataSet);
|
||||
downloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(cache, fakeDataSourceFactory),
|
||||
/* maxSimultaneousDownloads= */ 1,
|
||||
/* minRetryCount= */ 3,
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
}
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(downloadManager, dummyMainThread);
|
||||
downloadManager.addListener(downloadManagerListener);
|
||||
downloadManager.startDownloads();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -78,15 +78,12 @@ public class DownloadServiceDashTest {
|
||||
cache = new SimpleCache(tempFolder, new NoOpCacheEvictor());
|
||||
|
||||
Runnable pauseAction =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (pauseDownloadCondition != null) {
|
||||
try {
|
||||
pauseDownloadCondition.block();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
() -> {
|
||||
if (pauseDownloadCondition != null) {
|
||||
try {
|
||||
pauseDownloadCondition.block();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -109,55 +106,46 @@ public class DownloadServiceDashTest {
|
||||
fakeStreamKey2 = new StreamKey(0, 1, 0);
|
||||
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File actionFile;
|
||||
try {
|
||||
actionFile = Util.createTempFile(context, "ExoPlayerTest");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
actionFile.delete();
|
||||
final DownloadManager dashDownloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(cache, fakeDataSourceFactory),
|
||||
1,
|
||||
3,
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(dashDownloadManager, dummyMainThread);
|
||||
dashDownloadManager.addListener(downloadManagerListener);
|
||||
dashDownloadManager.startDownloads();
|
||||
|
||||
dashDownloadService =
|
||||
new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
|
||||
@Override
|
||||
protected DownloadManager getDownloadManager() {
|
||||
return dashDownloadManager;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Scheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
dashDownloadService.onCreate();
|
||||
() -> {
|
||||
File actionFile;
|
||||
try {
|
||||
actionFile = Util.createTempFile(context, "ExoPlayerTest");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
actionFile.delete();
|
||||
final DownloadManager dashDownloadManager =
|
||||
new DownloadManager(
|
||||
new DownloaderConstructorHelper(cache, fakeDataSourceFactory),
|
||||
1,
|
||||
3,
|
||||
actionFile,
|
||||
DashDownloadAction.DESERIALIZER);
|
||||
downloadManagerListener =
|
||||
new TestDownloadManagerListener(dashDownloadManager, dummyMainThread);
|
||||
dashDownloadManager.addListener(downloadManagerListener);
|
||||
dashDownloadManager.startDownloads();
|
||||
|
||||
dashDownloadService =
|
||||
new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
|
||||
@Override
|
||||
protected DownloadManager getDownloadManager() {
|
||||
return dashDownloadManager;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Scheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
dashDownloadService.onCreate();
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dashDownloadService.onDestroy();
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(() -> dashDownloadService.onDestroy());
|
||||
Util.recursiveDelete(tempFolder);
|
||||
dummyMainThread.release();
|
||||
}
|
||||
@ -210,13 +198,10 @@ public class DownloadServiceDashTest {
|
||||
|
||||
private void callDownloadServiceOnStart(final DownloadAction action) {
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent startIntent =
|
||||
DownloadService.buildAddActionIntent(context, DownloadService.class, action, false);
|
||||
dashDownloadService.onStartCommand(startIntent, 0, 0);
|
||||
}
|
||||
() -> {
|
||||
Intent startIntent =
|
||||
DownloadService.buildAddActionIntent(context, DownloadService.class, action, false);
|
||||
dashDownloadService.onStartCommand(startIntent, 0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -684,12 +684,7 @@ public final class SsMediaSource extends BaseMediaSource
|
||||
}
|
||||
long nextLoadTimestamp = manifestLoadStartTimestamp + MINIMUM_MANIFEST_REFRESH_PERIOD_MS;
|
||||
long delayUntilNextLoad = Math.max(0, nextLoadTimestamp - SystemClock.elapsedRealtime());
|
||||
manifestRefreshHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startLoadingManifest();
|
||||
}
|
||||
}, delayUntilNextLoad);
|
||||
manifestRefreshHandler.postDelayed(this::startLoadingManifest, delayUntilNextLoad);
|
||||
}
|
||||
|
||||
private void startLoadingManifest() {
|
||||
|
@ -208,6 +208,8 @@ public class PlayerControlView extends FrameLayout {
|
||||
private final Formatter formatter;
|
||||
private final Timeline.Period period;
|
||||
private final Timeline.Window window;
|
||||
private final Runnable updateProgressAction;
|
||||
private final Runnable hideAction;
|
||||
|
||||
private final Drawable repeatOffButtonDrawable;
|
||||
private final Drawable repeatOneButtonDrawable;
|
||||
@ -236,22 +238,6 @@ public class PlayerControlView extends FrameLayout {
|
||||
private long[] extraAdGroupTimesMs;
|
||||
private boolean[] extraPlayedAdGroups;
|
||||
|
||||
private final Runnable updateProgressAction =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress();
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable hideAction =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
public PlayerControlView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@ -303,6 +289,8 @@ public class PlayerControlView extends FrameLayout {
|
||||
extraPlayedAdGroups = new boolean[0];
|
||||
componentListener = new ComponentListener();
|
||||
controlDispatcher = new com.google.android.exoplayer2.DefaultControlDispatcher();
|
||||
updateProgressAction = this::updateProgress;
|
||||
hideAction = this::hide;
|
||||
|
||||
LayoutInflater.from(context).inflate(controllerLayoutId, this);
|
||||
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
|
||||
|
@ -203,14 +203,11 @@ public class PlayerNotificationManager {
|
||||
public void onBitmap(final Bitmap bitmap) {
|
||||
if (bitmap != null) {
|
||||
mainHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (player != null
|
||||
&& notificationTag == currentNotificationTag
|
||||
&& isNotificationStarted) {
|
||||
updateNotification(bitmap);
|
||||
}
|
||||
() -> {
|
||||
if (player != null
|
||||
&& notificationTag == currentNotificationTag
|
||||
&& isNotificationStarted) {
|
||||
updateNotification(bitmap);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -80,13 +79,7 @@ public class TrackSelectionView extends LinearLayout {
|
||||
|
||||
final TrackSelectionView selectionView = dialogView.findViewById(R.id.exo_track_selection_view);
|
||||
selectionView.init(trackSelector, rendererIndex);
|
||||
Dialog.OnClickListener okClickListener =
|
||||
new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
selectionView.applySelection();
|
||||
}
|
||||
};
|
||||
Dialog.OnClickListener okClickListener = (dialog, which) -> selectionView.applySelection();
|
||||
|
||||
AlertDialog dialog =
|
||||
builder
|
||||
|
@ -469,12 +469,8 @@ public abstract class Action {
|
||||
SimpleExoPlayer player, DefaultTrackSelector trackSelector, Surface surface) {
|
||||
player
|
||||
.createMessage(
|
||||
new Target() {
|
||||
@Override
|
||||
public void handleMessage(int messageType, Object payload)
|
||||
throws ExoPlaybackException {
|
||||
throw exception;
|
||||
}
|
||||
(messageType, payload) -> {
|
||||
throw exception;
|
||||
})
|
||||
.send();
|
||||
}
|
||||
@ -510,25 +506,14 @@ public abstract class Action {
|
||||
// Schedule one message on the playback thread to pause the player immediately.
|
||||
player
|
||||
.createMessage(
|
||||
new Target() {
|
||||
@Override
|
||||
public void handleMessage(int messageType, Object payload)
|
||||
throws ExoPlaybackException {
|
||||
player.setPlayWhenReady(/* playWhenReady= */ false);
|
||||
}
|
||||
})
|
||||
(messageType, payload) -> player.setPlayWhenReady(/* playWhenReady= */ false))
|
||||
.setPosition(windowIndex, positionMs)
|
||||
.send();
|
||||
// Schedule another message on this test thread to continue action schedule.
|
||||
player
|
||||
.createMessage(
|
||||
new Target() {
|
||||
@Override
|
||||
public void handleMessage(int messageType, Object payload)
|
||||
throws ExoPlaybackException {
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
})
|
||||
(messageType, payload) ->
|
||||
nextAction.schedule(player, trackSelector, surface, handler))
|
||||
.setPosition(windowIndex, positionMs)
|
||||
.setHandler(new Handler())
|
||||
.send();
|
||||
|
@ -610,13 +610,7 @@ public final class ActionSchedule {
|
||||
ActionNode nextAction) {
|
||||
Assertions.checkArgument(nextAction == null);
|
||||
if (callback != null) {
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onActionScheduleFinished();
|
||||
}
|
||||
});
|
||||
handler.post(() -> callback.onActionScheduleFinished());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,9 @@ public final class DummyMainThread {
|
||||
} else {
|
||||
final ConditionVariable finishedCondition = new ConditionVariable();
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
finishedCondition.open();
|
||||
}
|
||||
() -> {
|
||||
runnable.run();
|
||||
finishedCondition.open();
|
||||
});
|
||||
assertThat(finishedCondition.block(timeoutMs)).isTrue();
|
||||
}
|
||||
|
@ -344,12 +344,7 @@ public abstract class ExoHostedTest
|
||||
player = null;
|
||||
// We post opening of the finished condition so that any events posted to the main thread as a
|
||||
// result of player.release() are guaranteed to be handled before the test returns.
|
||||
actionHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
testFinished.open();
|
||||
}
|
||||
});
|
||||
actionHandler.post(testFinished::open);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -33,12 +33,8 @@ import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
|
||||
import com.google.android.exoplayer2.analytics.AnalyticsListener;
|
||||
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
||||
import com.google.android.exoplayer2.metadata.MetadataOutput;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.text.TextOutput;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
@ -307,18 +303,12 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
renderers = new Renderer[] {new FakeRenderer(supportedFormats)};
|
||||
}
|
||||
renderersFactory =
|
||||
new RenderersFactory() {
|
||||
@Override
|
||||
public Renderer[] createRenderers(
|
||||
android.os.Handler eventHandler,
|
||||
VideoRendererEventListener videoRendererEventListener,
|
||||
AudioRendererEventListener audioRendererEventListener,
|
||||
TextOutput textRendererOutput,
|
||||
MetadataOutput metadataRendererOutput,
|
||||
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
|
||||
return renderers;
|
||||
}
|
||||
};
|
||||
(eventHandler,
|
||||
videoRendererEventListener,
|
||||
audioRendererEventListener,
|
||||
textRendererOutput,
|
||||
metadataRendererOutput,
|
||||
drmSessionManager) -> renderers;
|
||||
}
|
||||
if (loadControl == null) {
|
||||
loadControl = new DefaultLoadControl();
|
||||
@ -425,35 +415,31 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
*/
|
||||
public ExoPlayerTestRunner start() {
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
player =
|
||||
new TestSimpleExoPlayer(
|
||||
context, renderersFactory, trackSelector, loadControl, clock);
|
||||
player.addListener(ExoPlayerTestRunner.this);
|
||||
if (eventListener != null) {
|
||||
player.addListener(eventListener);
|
||||
}
|
||||
if (videoRendererEventListener != null) {
|
||||
player.addVideoDebugListener(videoRendererEventListener);
|
||||
}
|
||||
if (audioRendererEventListener != null) {
|
||||
player.addAudioDebugListener(audioRendererEventListener);
|
||||
}
|
||||
if (analyticsListener != null) {
|
||||
player.addAnalyticsListener(analyticsListener);
|
||||
}
|
||||
player.setPlayWhenReady(true);
|
||||
if (actionSchedule != null) {
|
||||
actionSchedule.start(
|
||||
player, trackSelector, null, handler, ExoPlayerTestRunner.this);
|
||||
}
|
||||
player.prepare(mediaSource);
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
() -> {
|
||||
try {
|
||||
player =
|
||||
new TestSimpleExoPlayer(
|
||||
context, renderersFactory, trackSelector, loadControl, clock);
|
||||
player.addListener(ExoPlayerTestRunner.this);
|
||||
if (eventListener != null) {
|
||||
player.addListener(eventListener);
|
||||
}
|
||||
if (videoRendererEventListener != null) {
|
||||
player.addVideoDebugListener(videoRendererEventListener);
|
||||
}
|
||||
if (audioRendererEventListener != null) {
|
||||
player.addAudioDebugListener(audioRendererEventListener);
|
||||
}
|
||||
if (analyticsListener != null) {
|
||||
player.addAnalyticsListener(analyticsListener);
|
||||
}
|
||||
player.setPlayWhenReady(true);
|
||||
if (actionSchedule != null) {
|
||||
actionSchedule.start(player, trackSelector, null, handler, ExoPlayerTestRunner.this);
|
||||
}
|
||||
player.prepare(mediaSource);
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
@ -579,20 +565,18 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
// Private implementation details.
|
||||
|
||||
private void release() throws InterruptedException {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (player != null) {
|
||||
player.release();
|
||||
handler.post(
|
||||
() -> {
|
||||
try {
|
||||
if (player != null) {
|
||||
player.release();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
} finally {
|
||||
playerThread.quit();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
} finally {
|
||||
playerThread.quit();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
playerThread.join();
|
||||
}
|
||||
|
||||
|
@ -93,13 +93,7 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||
public synchronized void setPreparationComplete() {
|
||||
deferOnPrepared = false;
|
||||
if (playerHandler != null && prepareCallback != null) {
|
||||
playerHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finishPreparation();
|
||||
}
|
||||
});
|
||||
playerHandler.post(this::finishPreparation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,15 +149,12 @@ public class FakeMediaSource extends BaseMediaSource {
|
||||
public synchronized void setNewSourceInfo(final Timeline newTimeline, final Object newManifest) {
|
||||
if (sourceInfoRefreshHandler != null) {
|
||||
sourceInfoRefreshHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(releasedSource).isFalse();
|
||||
assertThat(preparedSource).isTrue();
|
||||
timeline = newTimeline;
|
||||
manifest = newManifest;
|
||||
finishSourcePreparation();
|
||||
}
|
||||
() -> {
|
||||
assertThat(releasedSource).isFalse();
|
||||
assertThat(preparedSource).isTrue();
|
||||
timeline = newTimeline;
|
||||
manifest = newManifest;
|
||||
finishSourcePreparation();
|
||||
});
|
||||
} else {
|
||||
timeline = newTimeline;
|
||||
|
@ -118,13 +118,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
|
||||
forcedStopped = false;
|
||||
hostedTestStarted = false;
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HostActivity.this.hostedTest = hostedTest;
|
||||
maybeStartHostedTest();
|
||||
}
|
||||
});
|
||||
runOnUiThread(
|
||||
() -> {
|
||||
HostActivity.this.hostedTest = hostedTest;
|
||||
maybeStartHostedTest();
|
||||
});
|
||||
|
||||
if (!hostedTestStartedCondition.block(START_TIMEOUT_MS)) {
|
||||
String message =
|
||||
@ -145,12 +143,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
|
||||
fail(message);
|
||||
}
|
||||
} else {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hostedTest.forceStop();
|
||||
}
|
||||
});
|
||||
runOnUiThread(hostedTest::forceStop);
|
||||
String message = "Test timed out after " + timeoutMs + " ms.";
|
||||
Log.e(TAG, message);
|
||||
if (failOnTimeout) {
|
||||
|
@ -131,13 +131,7 @@ public final class FakeClockTest {
|
||||
|
||||
private static void waitForHandler(HandlerWrapper handler) {
|
||||
final ConditionVariable handlerFinished = new ConditionVariable();
|
||||
handler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handlerFinished.open();
|
||||
}
|
||||
});
|
||||
handler.post(handlerFinished::open);
|
||||
handlerFinished.block();
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,8 @@ public final class FakeDataSetTest {
|
||||
public void testSegmentTypes() {
|
||||
byte[] testData = TestUtil.buildTestData(3);
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Do nothing.
|
||||
}
|
||||
() -> {
|
||||
// Do nothing.
|
||||
};
|
||||
IOException exception = new IOException();
|
||||
FakeDataSet fakeDataSet =
|
||||
|
@ -97,16 +97,13 @@ public class MediaSourceTestRunner {
|
||||
final Throwable[] throwable = new Throwable[1];
|
||||
final ConditionVariable finishedCondition = new ConditionVariable();
|
||||
playbackHandler.post(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable e) {
|
||||
throwable[0] = e;
|
||||
} finally {
|
||||
finishedCondition.open();
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable e) {
|
||||
throwable[0] = e;
|
||||
} finally {
|
||||
finishedCondition.open();
|
||||
}
|
||||
});
|
||||
assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
|
||||
@ -123,22 +120,19 @@ public class MediaSourceTestRunner {
|
||||
public Timeline prepareSource() throws IOException {
|
||||
final IOException[] prepareError = new IOException[1];
|
||||
runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.prepareSource(
|
||||
player,
|
||||
/* isTopLevelSource= */ true,
|
||||
mediaSourceListener,
|
||||
/* mediaTransferListener= */ null);
|
||||
try {
|
||||
// TODO: This only catches errors that are set synchronously in prepareSource. To
|
||||
// capture async errors we'll need to poll maybeThrowSourceInfoRefreshError until the
|
||||
// first call to onSourceInfoRefreshed.
|
||||
mediaSource.maybeThrowSourceInfoRefreshError();
|
||||
} catch (IOException e) {
|
||||
prepareError[0] = e;
|
||||
}
|
||||
() -> {
|
||||
mediaSource.prepareSource(
|
||||
player,
|
||||
/* isTopLevelSource= */ true,
|
||||
mediaSourceListener,
|
||||
/* mediaTransferListener= */ null);
|
||||
try {
|
||||
// TODO: This only catches errors that are set synchronously in prepareSource. To
|
||||
// capture async errors we'll need to poll maybeThrowSourceInfoRefreshError until the
|
||||
// first call to onSourceInfoRefreshed.
|
||||
mediaSource.maybeThrowSourceInfoRefreshError();
|
||||
} catch (IOException e) {
|
||||
prepareError[0] = e;
|
||||
}
|
||||
});
|
||||
if (prepareError[0] != null) {
|
||||
@ -156,13 +150,7 @@ public class MediaSourceTestRunner {
|
||||
*/
|
||||
public MediaPeriod createPeriod(final MediaPeriodId periodId) {
|
||||
final MediaPeriod[] holder = new MediaPeriod[1];
|
||||
runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder[0] = mediaSource.createPeriod(periodId, allocator);
|
||||
}
|
||||
});
|
||||
runOnPlaybackThread(() -> holder[0] = mediaSource.createPeriod(periodId, allocator));
|
||||
assertThat(holder[0]).isNotNull();
|
||||
return holder[0];
|
||||
}
|
||||
@ -179,24 +167,21 @@ public class MediaSourceTestRunner {
|
||||
final ConditionVariable prepareCalled = new ConditionVariable();
|
||||
final CountDownLatch preparedCountDown = new CountDownLatch(1);
|
||||
runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaPeriod.prepare(
|
||||
new MediaPeriod.Callback() {
|
||||
@Override
|
||||
public void onPrepared(MediaPeriod mediaPeriod) {
|
||||
preparedCountDown.countDown();
|
||||
}
|
||||
() -> {
|
||||
mediaPeriod.prepare(
|
||||
new MediaPeriod.Callback() {
|
||||
@Override
|
||||
public void onPrepared(MediaPeriod mediaPeriod1) {
|
||||
preparedCountDown.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContinueLoadingRequested(MediaPeriod source) {
|
||||
// Do nothing.
|
||||
}
|
||||
},
|
||||
positionUs);
|
||||
prepareCalled.open();
|
||||
}
|
||||
@Override
|
||||
public void onContinueLoadingRequested(MediaPeriod source) {
|
||||
// Do nothing.
|
||||
}
|
||||
},
|
||||
positionUs);
|
||||
prepareCalled.open();
|
||||
});
|
||||
prepareCalled.block();
|
||||
return preparedCountDown;
|
||||
@ -208,13 +193,7 @@ public class MediaSourceTestRunner {
|
||||
* @param mediaPeriod The {@link MediaPeriod} to release.
|
||||
*/
|
||||
public void releasePeriod(final MediaPeriod mediaPeriod) {
|
||||
runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.releasePeriod(mediaPeriod);
|
||||
}
|
||||
});
|
||||
runOnPlaybackThread(() -> mediaSource.releasePeriod(mediaPeriod));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,13 +201,7 @@ public class MediaSourceTestRunner {
|
||||
* thread.
|
||||
*/
|
||||
public void releaseSource() {
|
||||
runOnPlaybackThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.releaseSource(mediaSourceListener);
|
||||
}
|
||||
});
|
||||
runOnPlaybackThread(() -> mediaSource.releaseSource(mediaSourceListener));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,12 +81,9 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
|
||||
downloadFinishedCondition = new CountDownLatch(1);
|
||||
}
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (downloadManager.isIdle()) {
|
||||
downloadFinishedCondition.countDown();
|
||||
}
|
||||
() -> {
|
||||
if (downloadManager.isIdle()) {
|
||||
downloadFinishedCondition.countDown();
|
||||
}
|
||||
});
|
||||
assertThat(downloadFinishedCondition.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
|
||||
|
Loading…
x
Reference in New Issue
Block a user