Search in sources :

Example 6 with Player

use of com.google.android.exoplayer2.Player in project ExoPlayer by google.

the class PlaybackControlView method updateNavigation.

private void updateNavigation() {
    if (!isVisible() || !isAttachedToWindow) {
        return;
    }
    Timeline currentTimeline = player != null ? player.getCurrentTimeline() : null;
    boolean haveNonEmptyTimeline = currentTimeline != null && !currentTimeline.isEmpty();
    boolean isSeekable = false;
    boolean enablePrevious = false;
    boolean enableNext = false;
    if (haveNonEmptyTimeline) {
        int currentWindowIndex = player.getCurrentWindowIndex();
        currentTimeline.getWindow(currentWindowIndex, currentWindow);
        isSeekable = currentWindow.isSeekable;
        enablePrevious = currentWindowIndex > 0 || isSeekable || !currentWindow.isDynamic;
        enableNext = (currentWindowIndex < currentTimeline.getWindowCount() - 1) || currentWindow.isDynamic;
    }
    setButtonEnabled(enablePrevious, previousButton);
    setButtonEnabled(enableNext, nextButton);
    setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton);
    setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton);
    if (progressBar != null) {
        progressBar.setEnabled(isSeekable);
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 7 with Player

use of com.google.android.exoplayer2.Player in project ExoPlayer by google.

the class SimpleExoPlayerView method updateForCurrentTrackSelections.

private void updateForCurrentTrackSelections() {
    if (player == null) {
        return;
    }
    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
            // onRenderedFirstFrame().
            hideArtwork();
            return;
        }
    }
    // Video disabled so the shutter must be closed.
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    // Display artwork if enabled and available, else hide it.
    if (useArtwork) {
        for (int i = 0; i < selections.length; i++) {
            TrackSelection selection = selections.get(i);
            if (selection != null) {
                for (int j = 0; j < selection.length(); j++) {
                    Metadata metadata = selection.getFormat(j).metadata;
                    if (metadata != null && setArtworkFromMetadata(metadata)) {
                        return;
                    }
                }
            }
        }
        if (setArtworkFromBitmap(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray)

Example 8 with Player

use of com.google.android.exoplayer2.Player in project ExoPlayer by google.

the class DashMediaSource method prepareSource.

// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
    sourceListener = listener;
    if (sideloadedManifest) {
        loaderErrorThrower = new LoaderErrorThrower.Dummy();
        processManifest(false);
    } else {
        dataSource = manifestDataSourceFactory.createDataSource();
        loader = new Loader("Loader:DashMediaSource");
        loaderErrorThrower = loader;
        handler = new Handler();
        startLoadingManifest();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Example 9 with Player

use of com.google.android.exoplayer2.Player in project react-native-video by react-native-community.

the class ExoPlayerView method updateForCurrentTrackSelections.

private void updateForCurrentTrackSelections() {
    if (player == null) {
        return;
    }
    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            // onRenderedFirstFrame().
            return;
        }
    }
    // Video disabled so the shutter must be closed.
    shutterView.setVisibility(VISIBLE);
}
Also used : TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray)

Example 10 with Player

use of com.google.android.exoplayer2.Player in project LeafPic by HoraApps.

the class PlayerActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(org.horaapps.leafpic.R.menu.menu_video_player, menu);
    MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
    if (player != null && mappedTrackInfo != null) {
        for (int i = 0; i < mappedTrackInfo.length; i++) {
            TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i);
            if (trackGroups.length != 0) {
                switch(player.getRendererType(i)) {
                    case C.TRACK_TYPE_AUDIO:
                        menu.findItem(R.id.audio_stuff).setVisible(true);
                        audio = i;
                        break;
                    case C.TRACK_TYPE_VIDEO:
                        menu.findItem(R.id.video_stuff).setVisible(true);
                        video = i;
                        break;
                    case C.TRACK_TYPE_TEXT:
                        menu.findItem(R.id.text_stuff).setVisible(true);
                        text = i;
                        break;
                }
            }
        }
    }
    return true;
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Aggregations

Test (org.junit.Test)250 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)185 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)174 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)127 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)107 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)91 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)89 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)89 Listener (com.google.android.exoplayer2.Player.Listener)85 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)72 MediaSource (com.google.android.exoplayer2.source.MediaSource)68 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)67 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)66 Nullable (androidx.annotation.Nullable)56 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)49 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)49 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)49 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)49 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)49 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)47