-
Notifications
You must be signed in to change notification settings - Fork 6k
/
SimpleBasePlayer.java
803 lines (704 loc) · 24.8 KB
/
SimpleBasePlayer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.os.Looper;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.text.CueGroup;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.ListenerSet;
import com.google.android.exoplayer2.util.Size;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoSize;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.ForOverride;
import java.util.HashSet;
import java.util.List;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/**
* A base implementation for {@link Player} that reduces the number of methods to implement to a
* minimum.
*
* <p>Implementation notes:
*
* <ul>
* <li>Subclasses must override {@link #getState()} to populate the current player state on
* request.
* <li>The {@link State} should set the {@linkplain State.Builder#setAvailableCommands available
* commands} to indicate which {@link Player} methods are supported.
* <li>All setter-like player methods (for example, {@link #setPlayWhenReady}) forward to
* overridable methods (for example, {@link #handleSetPlayWhenReady}) that can be used to
* handle these requests. These methods return a {@link ListenableFuture} to indicate when the
* request has been handled and is fully reflected in the values returned from {@link
* #getState}. This class will automatically request a state update once the request is done.
* If the state changes can be handled synchronously, these methods can return Guava's {@link
* Futures#immediateVoidFuture()}.
* <li>Subclasses can manually trigger state updates with {@link #invalidateState}, for example if
* something changes independent of {@link Player} method calls.
* </ul>
*
* This base class handles various aspects of the player implementation to simplify the subclass:
*
* <ul>
* <li>The {@link State} can only be created with allowed combinations of state values, avoiding
* any invalid player states.
* <li>Only functionality that is declared as {@linkplain Player.Command available} needs to be
* implemented. Other methods are automatically ignored.
* <li>Listener handling and informing listeners of state changes is handled automatically.
* <li>The base class provides a framework for asynchronous handling of method calls. It changes
* the visible playback state immediately to the most likely outcome to ensure the
* user-visible state changes look like synchronous operations. The state is then updated
* again once the asynchronous method calls have been fully handled.
* </ul>
*/
public abstract class SimpleBasePlayer extends BasePlayer {
/** An immutable state description of the player. */
protected static final class State {
/** A builder for {@link State} objects. */
public static final class Builder {
private Commands availableCommands;
private boolean playWhenReady;
private @PlayWhenReadyChangeReason int playWhenReadyChangeReason;
/** Creates the builder. */
public Builder() {
availableCommands = Commands.EMPTY;
playWhenReady = false;
playWhenReadyChangeReason = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST;
}
private Builder(State state) {
this.availableCommands = state.availableCommands;
this.playWhenReady = state.playWhenReady;
this.playWhenReadyChangeReason = state.playWhenReadyChangeReason;
}
/**
* Sets the available {@link Commands}.
*
* @param availableCommands The available {@link Commands}.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setAvailableCommands(Commands availableCommands) {
this.availableCommands = availableCommands;
return this;
}
/**
* Sets whether playback should proceed when ready and not suppressed.
*
* @param playWhenReady Whether playback should proceed when ready and not suppressed.
* @param playWhenReadyChangeReason The {@linkplain PlayWhenReadyChangeReason reason} for
* changing the value.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setPlayWhenReady(
boolean playWhenReady, @PlayWhenReadyChangeReason int playWhenReadyChangeReason) {
this.playWhenReady = playWhenReady;
this.playWhenReadyChangeReason = playWhenReadyChangeReason;
return this;
}
/** Builds the {@link State}. */
public State build() {
return new State(this);
}
}
/** The available {@link Commands}. */
public final Commands availableCommands;
/** Whether playback should proceed when ready and not suppressed. */
public final boolean playWhenReady;
/** The last reason for changing {@link #playWhenReady}. */
public final @PlayWhenReadyChangeReason int playWhenReadyChangeReason;
private State(Builder builder) {
this.availableCommands = builder.availableCommands;
this.playWhenReady = builder.playWhenReady;
this.playWhenReadyChangeReason = builder.playWhenReadyChangeReason;
}
/** Returns a {@link Builder} pre-populated with the current state values. */
public Builder buildUpon() {
return new Builder(this);
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (!(o instanceof State)) {
return false;
}
State state = (State) o;
return playWhenReady == state.playWhenReady
&& playWhenReadyChangeReason == state.playWhenReadyChangeReason
&& availableCommands.equals(state.availableCommands);
}
@Override
public int hashCode() {
int result = 7;
result = 31 * result + availableCommands.hashCode();
result = 31 * result + (playWhenReady ? 1 : 0);
result = 31 * result + playWhenReadyChangeReason;
return result;
}
}
private final ListenerSet<Listener> listeners;
private final Looper applicationLooper;
private final HandlerWrapper applicationHandler;
private final HashSet<ListenableFuture<?>> pendingOperations;
private @MonotonicNonNull State state;
/**
* Creates the base class.
*
* @param applicationLooper The {@link Looper} that must be used for all calls to the player and
* that is used to call listeners on.
*/
protected SimpleBasePlayer(Looper applicationLooper) {
this(applicationLooper, Clock.DEFAULT);
}
/**
* Creates the base class.
*
* @param applicationLooper The {@link Looper} that must be used for all calls to the player and
* that is used to call listeners on.
* @param clock The {@link Clock} that will be used by the player.
*/
protected SimpleBasePlayer(Looper applicationLooper, Clock clock) {
this.applicationLooper = applicationLooper;
applicationHandler = clock.createHandler(applicationLooper, /* callback= */ null);
pendingOperations = new HashSet<>();
@SuppressWarnings("nullness:argument.type.incompatible") // Using this in constructor.
ListenerSet<Player.Listener> listenerSet =
new ListenerSet<>(
applicationLooper,
clock,
(listener, flags) -> listener.onEvents(/* player= */ this, new Events(flags)));
listeners = listenerSet;
}
@Override
public final void addListener(Listener listener) {
// Don't verify application thread. We allow calls to this method from any thread.
listeners.add(checkNotNull(listener));
}
@Override
public final void removeListener(Listener listener) {
// Don't verify application thread. We allow calls to this method from any thread.
checkNotNull(listener);
listeners.remove(listener);
}
@Override
public final Looper getApplicationLooper() {
// Don't verify application thread. We allow calls to this method from any thread.
return applicationLooper;
}
@Override
public final Commands getAvailableCommands() {
verifyApplicationThreadAndInitState();
return state.availableCommands;
}
@Override
public final void setPlayWhenReady(boolean playWhenReady) {
verifyApplicationThreadAndInitState();
State state = this.state;
if (!state.availableCommands.contains(Player.COMMAND_PLAY_PAUSE)) {
return;
}
updateStateForPendingOperation(
/* pendingOperation= */ handleSetPlayWhenReady(playWhenReady),
/* placeholderStateSupplier= */ () ->
state
.buildUpon()
.setPlayWhenReady(playWhenReady, Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST)
.build());
}
@Override
public final boolean getPlayWhenReady() {
verifyApplicationThreadAndInitState();
return state.playWhenReady;
}
@Override
public final void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setMediaItems(
List<MediaItem> mediaItems, int startIndex, long startPositionMs) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void addMediaItems(int index, List<MediaItem> mediaItems) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void moveMediaItems(int fromIndex, int toIndex, int newIndex) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void removeMediaItems(int fromIndex, int toIndex) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void prepare() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getPlaybackState() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getPlaybackSuppressionReason() {
// TODO: implement.
throw new IllegalStateException();
}
@Nullable
@Override
public final PlaybackException getPlayerError() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setRepeatMode(int repeatMode) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getRepeatMode() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setShuffleModeEnabled(boolean shuffleModeEnabled) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final boolean getShuffleModeEnabled() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final boolean isLoading() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void seekTo(int mediaItemIndex, long positionMs) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getSeekBackIncrement() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getSeekForwardIncrement() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getMaxSeekToPreviousPosition() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setPlaybackParameters(PlaybackParameters playbackParameters) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final PlaybackParameters getPlaybackParameters() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void stop() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void stop(boolean reset) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void release() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final Tracks getCurrentTracks() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final TrackSelectionParameters getTrackSelectionParameters() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setTrackSelectionParameters(TrackSelectionParameters parameters) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final MediaMetadata getMediaMetadata() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final MediaMetadata getPlaylistMetadata() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setPlaylistMetadata(MediaMetadata mediaMetadata) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final Timeline getCurrentTimeline() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getCurrentPeriodIndex() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getCurrentMediaItemIndex() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getDuration() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getCurrentPosition() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getBufferedPosition() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getTotalBufferedDuration() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final boolean isPlayingAd() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getCurrentAdGroupIndex() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getCurrentAdIndexInAdGroup() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getContentPosition() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final long getContentBufferedPosition() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final AudioAttributes getAudioAttributes() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setVolume(float volume) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final float getVolume() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void clearVideoSurface() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void clearVideoSurface(@Nullable Surface surface) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setVideoSurface(@Nullable Surface surface) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setVideoSurfaceView(@Nullable SurfaceView surfaceView) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void clearVideoSurfaceView(@Nullable SurfaceView surfaceView) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setVideoTextureView(@Nullable TextureView textureView) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void clearVideoTextureView(@Nullable TextureView textureView) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final VideoSize getVideoSize() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final Size getSurfaceSize() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final CueGroup getCurrentCues() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final DeviceInfo getDeviceInfo() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final int getDeviceVolume() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final boolean isDeviceMuted() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setDeviceVolume(int volume) {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void increaseDeviceVolume() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void decreaseDeviceVolume() {
// TODO: implement.
throw new IllegalStateException();
}
@Override
public final void setDeviceMuted(boolean muted) {
// TODO: implement.
throw new IllegalStateException();
}
/**
* Invalidates the current state.
*
* <p>Triggers a call to {@link #getState()} and informs listeners if the state changed.
*
* <p>Note that this may not have an immediate effect while there are still player methods being
* handled asynchronously. The state will be invalidated automatically once these pending
* synchronous operations are finished and there is no need to call this method again.
*/
protected final void invalidateState() {
verifyApplicationThreadAndInitState();
if (!pendingOperations.isEmpty()) {
return;
}
updateStateAndInformListeners(getState());
}
/**
* Returns the current {@link State} of the player.
*
* <p>The {@link State} should include all {@linkplain
* State.Builder#setAvailableCommands(Commands) available commands} indicating which player
* methods are allowed to be called.
*
* <p>Note that this method won't be called while asynchronous handling of player methods is in
* progress. This means that the implementation doesn't need to handle state changes caused by
* these asynchronous operations until they are done and can return the currently known state
* directly. The placeholder state used while these asynchronous operations are in progress can be
* customized by overriding {@link #getPlaceholderState(State)} if required.
*/
@ForOverride
protected abstract State getState();
/**
* Returns the placeholder state used while a player method is handled asynchronously.
*
* <p>The {@code suggestedPlaceholderState} already contains the most likely state update, for
* example setting {@link State#playWhenReady} to true if {@code player.setPlayWhenReady(true)} is
* called, and an implementations only needs to override this method if it can determine a more
* accurate placeholder state.
*
* @param suggestedPlaceholderState The suggested placeholder {@link State}, including the most
* likely outcome of handling all pending asynchronous operations.
* @return The placeholder {@link State} to use while asynchronous operations are pending.
*/
@ForOverride
protected State getPlaceholderState(State suggestedPlaceholderState) {
return suggestedPlaceholderState;
}
/**
* Handles calls to set {@link State#playWhenReady}.
*
* <p>Will only be called if {@link Player.Command#COMMAND_PLAY_PAUSE} is available.
*
* @param playWhenReady The requested {@link State#playWhenReady}
* @return A {@link ListenableFuture} indicating the completion of all immediate {@link State}
* changes caused by this call.
* @see Player#setPlayWhenReady(boolean)
* @see Player#play()
* @see Player#pause()
*/
@ForOverride
protected ListenableFuture<?> handleSetPlayWhenReady(boolean playWhenReady) {
throw new IllegalStateException();
}
@SuppressWarnings("deprecation") // Calling deprecated listener methods.
@RequiresNonNull("state")
private void updateStateAndInformListeners(State newState) {
State previousState = state;
// Assign new state immediately such that all getters return the right values, but use a
// snapshot of the previous and new state so that listener invocations are triggered correctly.
this.state = newState;
boolean playWhenReadyChanged = previousState.playWhenReady != newState.playWhenReady;
if (playWhenReadyChanged /* TODO: || playbackStateChanged */) {
listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET,
listener ->
listener.onPlayerStateChanged(newState.playWhenReady, /* TODO */ Player.STATE_IDLE));
}
if (playWhenReadyChanged
|| previousState.playWhenReadyChangeReason != newState.playWhenReadyChangeReason) {
listeners.queueEvent(
Player.EVENT_PLAY_WHEN_READY_CHANGED,
listener ->
listener.onPlayWhenReadyChanged(
newState.playWhenReady, newState.playWhenReadyChangeReason));
}
if (isPlaying(previousState) != isPlaying(newState)) {
listeners.queueEvent(
Player.EVENT_IS_PLAYING_CHANGED,
listener -> listener.onIsPlayingChanged(isPlaying(newState)));
}
if (!previousState.availableCommands.equals(newState.availableCommands)) {
listeners.queueEvent(
Player.EVENT_AVAILABLE_COMMANDS_CHANGED,
listener -> listener.onAvailableCommandsChanged(newState.availableCommands));
}
listeners.flushEvents();
}
@EnsuresNonNull("state")
private void verifyApplicationThreadAndInitState() {
if (Thread.currentThread() != applicationLooper.getThread()) {
String message =
Util.formatInvariant(
"Player is accessed on the wrong thread.\n"
+ "Current thread: '%s'\n"
+ "Expected thread: '%s'\n"
+ "See https://exoplayer.dev/issues/player-accessed-on-wrong-thread",
Thread.currentThread().getName(), applicationLooper.getThread().getName());
throw new IllegalStateException(message);
}
if (state == null) {
// First time accessing state.
state = getState();
}
}
@RequiresNonNull("state")
private void updateStateForPendingOperation(
ListenableFuture<?> pendingOperation, Supplier<State> placeholderStateSupplier) {
if (pendingOperation.isDone() && pendingOperations.isEmpty()) {
updateStateAndInformListeners(getState());
} else {
pendingOperations.add(pendingOperation);
State suggestedPlaceholderState = placeholderStateSupplier.get();
updateStateAndInformListeners(getPlaceholderState(suggestedPlaceholderState));
pendingOperation.addListener(
() -> {
castNonNull(state); // Already check by method @RequiresNonNull pre-condition.
pendingOperations.remove(pendingOperation);
if (pendingOperations.isEmpty()) {
updateStateAndInformListeners(getState());
}
},
this::postOrRunOnApplicationHandler);
}
}
private void postOrRunOnApplicationHandler(Runnable runnable) {
if (applicationHandler.getLooper() == Looper.myLooper()) {
runnable.run();
} else {
applicationHandler.post(runnable);
}
}
private static boolean isPlaying(State state) {
return state.playWhenReady && false;
// TODO: && state.playbackState == Player.STATE_READY
// && state.playbackSuppressionReason == PLAYBACK_SUPPRESSION_REASON_NONE
}
}