use of com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory 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);
}
}
Aggregations