Search in sources :

Example 16 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class DefaultMediaClock method syncClocks.

private void syncClocks(boolean isReadingAhead) {
    if (shouldUseStandaloneClock(isReadingAhead)) {
        isUsingStandaloneClock = true;
        if (standaloneClockIsStarted) {
            standaloneClock.start();
        }
        return;
    }
    // We are either already using the renderer clock or switching from the standalone to the
    // renderer clock, so it must be non-null.
    MediaClock rendererClock = Assertions.checkNotNull(this.rendererClock);
    long rendererClockPositionUs = rendererClock.getPositionUs();
    if (isUsingStandaloneClock) {
        // Ensure enabling the renderer clock doesn't jump backwards in time.
        if (rendererClockPositionUs < standaloneClock.getPositionUs()) {
            standaloneClock.stop();
            return;
        }
        isUsingStandaloneClock = false;
        if (standaloneClockIsStarted) {
            standaloneClock.start();
        }
    }
    // Continuously sync stand-alone clock to renderer clock so that it can take over if needed.
    standaloneClock.resetPosition(rendererClockPositionUs);
    PlaybackParameters playbackParameters = rendererClock.getPlaybackParameters();
    if (!playbackParameters.equals(standaloneClock.getPlaybackParameters())) {
        standaloneClock.setPlaybackParameters(playbackParameters);
        listener.onPlaybackParametersChanged(playbackParameters);
    }
}
Also used : MediaClock(com.google.android.exoplayer2.util.MediaClock) StandaloneMediaClock(com.google.android.exoplayer2.util.StandaloneMediaClock)

Example 17 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class MediaFormatUtilTest method createMediaFormatFromFormat_withPopulatedFormat_generatesExpectedEntries.

@Test
public void createMediaFormatFromFormat_withPopulatedFormat_generatesExpectedEntries() {
    Format format = new Format.Builder().setAverageBitrate(1).setChannelCount(2).setColorInfo(new ColorInfo(/* colorSpace= */
    C.COLOR_SPACE_BT601, /* colorRange= */
    C.COLOR_RANGE_FULL, /* colorTransfer= */
    C.COLOR_TRANSFER_HLG, new byte[] { 3 })).setSampleMimeType(MimeTypes.VIDEO_H264).setCodecs("avc.123").setFrameRate(4).setWidth(5).setHeight(6).setInitializationData(ImmutableList.of(new byte[] { 7 }, new byte[] { 8 })).setPcmEncoding(C.ENCODING_PCM_8BIT).setLanguage("en").setMaxInputSize(9).setRotationDegrees(10).setSampleRate(11).setAccessibilityChannel(12).setSelectionFlags(C.SELECTION_FLAG_AUTOSELECT | C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED).setEncoderDelay(13).setEncoderPadding(14).setPixelWidthHeightRatio(.5f).build();
    MediaFormat mediaFormat = MediaFormatUtil.createMediaFormatFromFormat(format);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_BIT_RATE)).isEqualTo(format.bitrate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)).isEqualTo(format.channelCount);
    ColorInfo colorInfo = Assertions.checkNotNull(format.colorInfo);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_TRANSFER)).isEqualTo(colorInfo.colorTransfer);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_RANGE)).isEqualTo(colorInfo.colorRange);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_STANDARD)).isEqualTo(colorInfo.colorSpace);
    assertThat(mediaFormat.getByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO).array()).isEqualTo(colorInfo.hdrStaticInfo);
    assertThat(mediaFormat.getString(MediaFormat.KEY_MIME)).isEqualTo(format.sampleMimeType);
    assertThat(mediaFormat.getString(MediaFormat.KEY_CODECS_STRING)).isEqualTo(format.codecs);
    assertThat(mediaFormat.getFloat(MediaFormat.KEY_FRAME_RATE)).isEqualTo(format.frameRate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_WIDTH)).isEqualTo(format.width);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_HEIGHT)).isEqualTo(format.height);
    assertThat(mediaFormat.getByteBuffer("csd-0").array()).isEqualTo(format.initializationData.get(0));
    assertThat(mediaFormat.getByteBuffer("csd-1").array()).isEqualTo(format.initializationData.get(1));
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING)).isEqualTo(format.pcmEncoding);
    assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_PCM_ENCODING_EXTENDED)).isEqualTo(format.pcmEncoding);
    assertThat(mediaFormat.getString(MediaFormat.KEY_LANGUAGE)).isEqualTo(format.language);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE)).isEqualTo(format.maxInputSize);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ROTATION)).isEqualTo(format.rotationDegrees);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)).isEqualTo(format.sampleRate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_CAPTION_SERVICE_NUMBER)).isEqualTo(format.accessibilityChannel);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_AUTOSELECT)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_DEFAULT)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_DELAY)).isEqualTo(format.encoderDelay);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_PADDING)).isEqualTo(format.encoderPadding);
    float calculatedPixelAspectRatio = (float) mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) / mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT);
    assertThat(calculatedPixelAspectRatio).isWithin(.0001f).of(format.pixelWidthHeightRatio);
    assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)).isEqualTo(format.pixelWidthHeightRatio);
}
Also used : MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) MediaFormat(android.media.MediaFormat) ColorInfo(com.google.android.exoplayer2.video.ColorInfo) Test(org.junit.Test)

Example 18 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class PlayerWrapper method addPlaylistItem.

public boolean addPlaylistItem(int index, androidx.media2.common.MediaItem media2MediaItem) {
    Assertions.checkArgument(!media2Playlist.contains(media2MediaItem));
    index = Util.constrainValue(index, 0, media2Playlist.size());
    MediaItem exoPlayerMediaItem = Assertions.checkNotNull(mediaItemConverter.convertToExoPlayerMediaItem(media2MediaItem));
    player.addMediaItem(index, exoPlayerMediaItem);
    return true;
}
Also used : CallbackMediaItem(androidx.media2.common.CallbackMediaItem) MediaItem(com.google.android.exoplayer2.MediaItem)

Example 19 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class PlayerWrapper method setPlaylist.

public boolean setPlaylist(List<androidx.media2.common.MediaItem> playlist, @Nullable MediaMetadata metadata) {
    // Check for duplication.
    for (int i = 0; i < playlist.size(); i++) {
        androidx.media2.common.MediaItem media2MediaItem = playlist.get(i);
        Assertions.checkArgument(playlist.indexOf(media2MediaItem) == i);
    }
    this.playlistMetadata = metadata;
    List<MediaItem> exoPlayerMediaItems = new ArrayList<>();
    for (int i = 0; i < playlist.size(); i++) {
        androidx.media2.common.MediaItem media2MediaItem = playlist.get(i);
        MediaItem exoPlayerMediaItem = Assertions.checkNotNull(mediaItemConverter.convertToExoPlayerMediaItem(media2MediaItem));
        exoPlayerMediaItems.add(exoPlayerMediaItem);
    }
    player.setMediaItems(exoPlayerMediaItems, /* resetPosition= */
    true);
    currentWindowIndex = getCurrentMediaItemIndex();
    return true;
}
Also used : CallbackMediaItem(androidx.media2.common.CallbackMediaItem) MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList)

Example 20 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class PlayerWrapper method updatePlaylist.

private void updatePlaylist(Timeline timeline) {
    List<androidx.media2.common.MediaItem> media2MediaItemToBeRemoved = new ArrayList<>(media2Playlist);
    media2Playlist.clear();
    exoPlayerPlaylist.clear();
    Timeline.Window window = new Timeline.Window();
    int windowCount = timeline.getWindowCount();
    for (int i = 0; i < windowCount; i++) {
        timeline.getWindow(i, window);
        MediaItem exoPlayerMediaItem = window.mediaItem;
        androidx.media2.common.MediaItem media2MediaItem = Assertions.checkNotNull(mediaItemConverter.convertToMedia2MediaItem(exoPlayerMediaItem));
        exoPlayerPlaylist.add(exoPlayerMediaItem);
        media2Playlist.add(media2MediaItem);
        media2MediaItemToBeRemoved.remove(media2MediaItem);
    }
    for (androidx.media2.common.MediaItem item : media2MediaItemToBeRemoved) {
        releaseMediaItem(item);
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) CallbackMediaItem(androidx.media2.common.CallbackMediaItem) MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList)

Aggregations

Nullable (androidx.annotation.Nullable)28 Format (com.google.android.exoplayer2.Format)10 ArrayList (java.util.ArrayList)9 MediaItem (com.google.android.exoplayer2.MediaItem)8 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 Matcher (java.util.regex.Matcher)5 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 Uri (android.net.Uri)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 SQLException (android.database.SQLException)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Bundle (android.os.Bundle)3 CallbackMediaItem (androidx.media2.common.CallbackMediaItem)3 C (com.google.android.exoplayer2.C)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)3