mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Rearrange condition blocking to ensure Handler thread loops
Without this change, any prepare() operation that requires posting to the DummyMainThread's handler cannot complete preparation. PiperOrigin-RevId: 233050367
This commit is contained in:
parent
fd979790f2
commit
891ec2230e
2 changed files with 8 additions and 8 deletions
|
|
@ -53,7 +53,7 @@ public final class DummyMainThread {
|
|||
* Runs the provided {@link Runnable} on the main thread, blocking until execution completes or
|
||||
* until timeout milliseconds have passed.
|
||||
*
|
||||
* @param timeoutMs the maximum time to wait in milliseconds.
|
||||
* @param timeoutMs The maximum time to wait in milliseconds.
|
||||
* @param runnable The {@link Runnable} to run.
|
||||
*/
|
||||
public void runOnMainThread(int timeoutMs, final Runnable runnable) {
|
||||
|
|
|
|||
|
|
@ -187,13 +187,14 @@ public final class MediaPeriodAsserts {
|
|||
private static TrackGroupArray getTrackGroups(MediaPeriod mediaPeriod) {
|
||||
AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>(null);
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
ConditionVariable preparedCondition = new ConditionVariable();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() -> {
|
||||
ConditionVariable preparedCondition = new ConditionVariable();
|
||||
mediaPeriod.prepare(
|
||||
new Callback() {
|
||||
@Override
|
||||
public void onPrepared(MediaPeriod mediaPeriod) {
|
||||
trackGroupArray.set(mediaPeriod.getTrackGroups());
|
||||
preparedCondition.open();
|
||||
}
|
||||
|
||||
|
|
@ -203,13 +204,12 @@ public final class MediaPeriodAsserts {
|
|||
}
|
||||
},
|
||||
/* positionUs= */ 0);
|
||||
try {
|
||||
preparedCondition.block();
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore.
|
||||
}
|
||||
trackGroupArray.set(mediaPeriod.getTrackGroups());
|
||||
});
|
||||
try {
|
||||
preparedCondition.block();
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore.
|
||||
}
|
||||
dummyMainThread.release();
|
||||
return trackGroupArray.get();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue