Search in sources :

Example 46 with Factory

use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.

the class HlsMediaSourceTest method loadLivePlaylist_partHoldBackWithoutPartInformationInPlaylist_targetLiveOffsetFromHoldBack.

@Test
public void loadLivePlaylist_partHoldBackWithoutPartInformationInPlaylist_targetLiveOffsetFromHoldBack() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a part hold back but not EXT-X-PART-INF. We should pick up the hold back.
    // The duration of the playlist is 16 seconds so that the defined hold back is within the live
    // window.
    String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK=12,PART-HOLD-BACK=3";
    // The playlist finishes 1 second before the current time.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
    HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
    MediaItem mediaItem = MediaItem.fromUri(playlistUri);
    HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
    Timeline timeline = prepareAndWaitForTimeline(mediaSource);
    Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
    // The target live offset is picked from hold back and then expressed in relation to the live
    // edge (+1 seconds).
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(13000);
    assertThat(window.liveConfiguration.minPlaybackSpeed).isEqualTo(C.RATE_UNSET);
    assertThat(window.liveConfiguration.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET);
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 47 with Factory

use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.

the class HlsMediaSourceTest method loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment.

@Test
public void loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a duration of 16 seconds, and part hold back, hold back and start time
    // defined.
    String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-START:TIME-OFFSET=-10\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK=12,PART-HOLD-BACK=3\n";
    // The playlist finishes 1 second before the current time.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
    HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
    MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(3000).build()).build();
    HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
    Timeline timeline = prepareAndWaitForTimeline(mediaSource);
    Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(3000);
    // The default position points to the segment containing the start time.
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 48 with Factory

use of com.google.android.exoplayer2.upstream.DataSource.Factory in project android by owncloud.

the class PrepareVideoPlayerAsyncTask method buildHttpDataSourceFactory.

/**
 * Returns a new HttpDataSource factory.
 *
 * @param bandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *                       DataSource factory.
 * @return A new HttpDataSource factory.
 */
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter, OCFile file, Account account) {
    if (file.isDown()) {
        return new DefaultHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter);
    } else {
        try {
            OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(MainApp.Companion.getAppContext(), account);
            String login = credentials.getUsername();
            String password = credentials.getAuthToken();
            Map<String, String> params = new HashMap<String, String>(1);
            if (credentials instanceof OwnCloudBasicCredentials) {
                // Basic auth
                String cred = login + ":" + password;
                String auth = "Basic " + Base64.encodeToString(cred.getBytes(), Base64.URL_SAFE);
                params.put("Authorization", auth);
            } else if (credentials instanceof OwnCloudBearerCredentials) {
                // OAuth
                String bearerToken = credentials.getAuthToken();
                String auth = "Bearer " + bearerToken;
                params.put("Authorization", auth);
            }
            return new CustomHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter, params);
        } catch (AuthenticatorException | IOException | OperationCanceledException e) {
            Timber.e(e);
        }
    }
    return null;
}
Also used : OwnCloudBearerCredentials(com.owncloud.android.lib.common.authentication.OwnCloudBearerCredentials) OwnCloudBasicCredentials(com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) HashMap(java.util.HashMap) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException) OwnCloudCredentials(com.owncloud.android.lib.common.authentication.OwnCloudCredentials)

Example 49 with Factory

use of com.google.android.exoplayer2.upstream.DataSource.Factory in project HybridMediaPlayer by mkaflowski.

the class ExoMediaPlayer method setDataSource.

public void setDataSource(List<MediaSourceInfo> normalSources, List<MediaSourceInfo> castSources) {
    if (exoPlayer != null)
        exoPlayer.stop();
    String userAgent = Util.getUserAgent(context, "yourApplicationName");
    DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, /* listener */
    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new SeekableExtractorsFactory();
    MediaSource[] sources = new MediaSource[normalSources.size()];
    for (int i = 0; i < normalSources.size(); i++) {
        // This is the MediaSource representing the media to be played.
        ProgressiveMediaSource.Factory factory = new ProgressiveMediaSource.Factory(dataSourceFactory);
        if (loadErrorHandlingPolicy != null)
            factory.setLoadErrorHandlingPolicy(loadErrorHandlingPolicy);
        sources[i] = factory.createMediaSource(Uri.parse(normalSources.get(i).getUrl()));
    }
    exoMediaSource = new ConcatenatingMediaSource(sources);
    prepareCastMediaSourceInfoList(castSources);
}
Also used : ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource)

Aggregations

Test (org.junit.Test)34 MediaItem (com.google.android.exoplayer2.MediaItem)23 Timeline (com.google.android.exoplayer2.Timeline)21 StreamKey (com.google.android.exoplayer2.offline.StreamKey)6 Format (com.google.android.exoplayer2.Format)5 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)5 ArrayList (java.util.ArrayList)5 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)4 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)4 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)4 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)4 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)4 List (java.util.List)4 Extractor (com.google.android.exoplayer2.extractor.Extractor)3 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)3