use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class SsMediaSource method prepareSource.
// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
sourceListener = listener;
if (manifest != null) {
manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
processManifest();
} else {
manifestDataSource = manifestDataSourceFactory.createDataSource();
manifestLoader = new Loader("Loader:Manifest");
manifestLoaderErrorThrower = manifestLoader;
manifestRefreshHandler = new Handler();
startLoadingManifest();
}
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class ConcatenatingMediaSource method handleSourceInfoRefreshed.
private void handleSourceInfoRefreshed(int sourceFirstIndex, Timeline sourceTimeline, Object sourceManifest) {
// Set the timeline and manifest.
timelines[sourceFirstIndex] = sourceTimeline;
manifests[sourceFirstIndex] = sourceManifest;
// Also set the timeline and manifest for any duplicate entries of the same source.
for (int i = sourceFirstIndex + 1; i < mediaSources.length; i++) {
if (mediaSources[i] == mediaSources[sourceFirstIndex]) {
timelines[i] = sourceTimeline;
manifests[i] = sourceManifest;
}
}
for (Timeline timeline : timelines) {
if (timeline == null) {
// Don't invoke the listener until all sources have timelines.
return;
}
}
timeline = new ConcatenatedTimeline(timelines.clone());
listener.onSourceInfoRefreshed(timeline, manifests.clone());
}
use of com.google.android.exoplayer2.Player.Listener in project Camera-Roll-Android-App by kollerlukas.
the class VideoPlayerActivity method setWindowInsets.
public void setWindowInsets() {
final Toolbar toolbar = findViewById(R.id.toolbar);
final View bottomBarControls = findViewById(R.id.controls);
final ViewGroup rootView = findViewById(R.id.root_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0);
bottomBarControls.setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
} else {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hacky way of getting window insets on pre-Lollipop
int[] screenSize = us.koller.cameraroll.util.Util.getScreenSize(VideoPlayerActivity.this);
int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
toolbar.setPadding(windowInsets[0], windowInsets[1], windowInsets[2], 0);
bottomBarControls.setPadding(windowInsets[0], 0, windowInsets[2], windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class SessionCallbackBuilderTest method setCustomCommandProvider_withCustomCommandProvider_receivesCustomCommand.
@Test
public void setCustomCommandProvider_withCustomCommandProvider_receivesCustomCommand() throws Exception {
SessionCommand testCommand = new SessionCommand("exo.ext.media2.COMMAND", null);
CountDownLatch latch = new CountDownLatch(1);
SessionCallbackBuilder.CustomCommandProvider provider = new SessionCallbackBuilder.CustomCommandProvider() {
@Override
public SessionResult onCustomCommand(MediaSession session, MediaSession.ControllerInfo controllerInfo, SessionCommand customCommand, @Nullable Bundle args) {
assertThat(customCommand.getCustomAction()).isEqualTo(testCommand.getCustomAction());
assertThat(args).isNull();
latch.countDown();
return new SessionResult(SessionResult.RESULT_SUCCESS, null);
}
@Override
public SessionCommandGroup getCustomCommands(MediaSession session, MediaSession.ControllerInfo controllerInfo) {
return new SessionCommandGroup.Builder().addCommand(testCommand).build();
}
};
try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setCustomCommandProvider(provider).build())) {
OnAllowedCommandsChangedListener listener = (controller, allowedCommands) -> {
boolean foundCustomCommand = false;
for (SessionCommand command : allowedCommands.getCommands()) {
if (TextUtils.equals(testCommand.getCustomAction(), command.getCustomAction())) {
foundCustomCommand = true;
break;
}
}
assertThat(foundCustomCommand).isTrue();
};
try (MediaController controller = createConnectedController(session, null, listener)) {
assertSessionResultSuccess(controller.sendCustomCommand(testCommand, null), CONTROLLER_COMMAND_WAIT_TIME_MS);
assertThat(latch.await(0, MILLISECONDS)).isTrue();
}
}
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class AdTagLoader method addListenerWithAdView.
/**
* Starts passing events from this instance (including any pending ad playback state) and
* registers obstructions.
*/
public void addListenerWithAdView(EventListener eventListener, AdViewProvider adViewProvider) {
boolean isStarted = !eventListeners.isEmpty();
eventListeners.add(eventListener);
if (isStarted) {
if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
// Pass the existing ad playback state to the new listener.
eventListener.onAdPlaybackState(adPlaybackState);
}
return;
}
lastVolumePercent = 0;
lastAdProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
lastContentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
maybeNotifyPendingAdLoadError();
if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
// Pass the ad playback state to the player, and resume ads if necessary.
eventListener.onAdPlaybackState(adPlaybackState);
} else if (adsManager != null) {
adPlaybackState = new AdPlaybackState(adsId, getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
updateAdPlaybackState();
}
for (AdOverlayInfo overlayInfo : adViewProvider.getAdOverlayInfos()) {
adDisplayContainer.registerFriendlyObstruction(imaFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail));
}
}
Aggregations