Search in sources :

Example 61 with State

use of com.google.android.exoplayer2.ext.ima.ImaServerSideAdInsertionMediaSource.AdsLoader.State in project Slide by ccrama.

the class ExoVideoView method setVideoURI.

/**
 * Sets the player's URI and prepares for playback
 *
 * @param uri      URI
 * @param type     Type of video
 * @param listener EventLister attached to the player, helpful for player state
 */
public void setVideoURI(Uri uri, VideoType type, Player.Listener listener) {
    // Create the data sources used to retrieve and cache the video
    DataSource.Factory downloader = new OkHttpDataSource.Factory(Reddit.client).setUserAgent(context.getString(R.string.app_name));
    DataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Reddit.videoCache).setUpstreamDataSourceFactory(downloader);
    // Create an appropriate media source for the video type
    MediaSource videoSource;
    switch(type) {
        // DASH video, e.g. v.redd.it video
        case DASH:
            videoSource = new DashMediaSource.Factory(cacheDataSourceFactory).createMediaSource(MediaItem.fromUri(uri));
            break;
        // Standard video, e.g. MP4 file
        case STANDARD:
        default:
            videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory).createMediaSource(MediaItem.fromUri(uri));
            break;
    }
    player.setMediaSource(videoSource);
    player.prepare();
    if (listener != null) {
        player.addListener(listener);
    }
}
Also used : ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) OkHttpDataSource(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) OkHttpDataSource(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource)

Aggregations

Test (org.junit.Test)26 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)10 Nullable (androidx.annotation.Nullable)9 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)9 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)9 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)8 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)8 SuppressLint (android.annotation.SuppressLint)7 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)7 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)7 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)7 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)6 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)6 ArrayList (java.util.ArrayList)6 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)5 Listener (com.google.android.exoplayer2.Player.Listener)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)4 IOException (java.io.IOException)4 Pair (android.util.Pair)3