Search in sources :

Example 96 with Listener

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();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Example 97 with Listener

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());
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 98 with Listener

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);
            }
        });
    }
}
Also used : WindowInsets(android.view.WindowInsets) ViewGroup(android.view.ViewGroup) RequiresApi(android.support.annotation.RequiresApi) View(android.view.View) SimpleExoPlayerView(com.google.android.exoplayer2.ui.SimpleExoPlayerView) PlaybackControlView(com.google.android.exoplayer2.ui.PlaybackControlView) ViewTreeObserver(android.view.ViewTreeObserver) Toolbar(android.support.v7.widget.Toolbar)

Example 99 with Listener

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();
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) Bundle(android.os.Bundle) CountDownLatch(java.util.concurrent.CountDownLatch) SessionResult(androidx.media2.session.SessionResult) MediaSession(androidx.media2.session.MediaSession) SessionCommand(androidx.media2.session.SessionCommand) Nullable(androidx.annotation.Nullable) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 100 with Listener

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));
    }
}
Also used : AdOverlayInfo(com.google.android.exoplayer2.ui.AdOverlayInfo) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState)

Aggregations

Test (org.junit.Test)87 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)68 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)58 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)54 Listener (com.google.android.exoplayer2.Player.Listener)45 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 MediaSource (com.google.android.exoplayer2.source.MediaSource)38 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)34 ArrayList (java.util.ArrayList)33 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)31 Nullable (androidx.annotation.Nullable)27 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)27 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)26 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)26 PositionInfo (com.google.android.exoplayer2.Player.PositionInfo)25 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)25 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 InOrder (org.mockito.InOrder)22 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)21