cache implementation

This commit is contained in:
Page Asgardius 2022-10-04 12:30:51 -07:00
parent 5969115062
commit 1ca6c42e87

View file

@ -47,17 +47,19 @@ public class VideoPlayer extends AppCompatActivity {
playerView = findViewById(R.id.player_view); playerView = findViewById(R.id.player_view);
// creating a variable for exoplayer // creating a variable for exoplayer
player = new ExoPlayer.Builder(this).build(); player = new ExoPlayer.Builder(this).build();
MediaSource mediaSource = new ProgressiveMediaSource.Factory(new CacheDataSourceFactory(this, 100 * 1024 * 1024, 512 * 1024 * 1024))
.createMediaSource(MediaItem.fromUri(Uri.parse(videoURL)));
//MediaSource audioSource = new ProgressiveMediaSource(Uri.parse("url"), //MediaSource audioSource = new ProgressiveMediaSource(Uri.parse("url"),
// new CacheDataSourceFactory(this, 100 * 1024 * 1024, 5 * 1024 * 1024), new DefaultExtractorsFactory(), null, null); // new CacheDataSourceFactory(this, 100 * 1024 * 1024, 5 * 1024 * 1024), new DefaultExtractorsFactory(), null, null);
// Attach player to the view. // Attach player to the view.
playerView.setPlayer(player); playerView.setPlayer(player);
MediaItem mediaItem = MediaItem.fromUri(videoURL); //MediaItem mediaItem = MediaItem.fromUri(videoURL);
// Set the media item to be played. // Set the media item to be played.
player.setMediaItem(mediaItem); //player.setMediaItem(mediaItem);
// Prepare the player. // Prepare the player.
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
//player.setMediaSource(audioSource); player.setMediaSource(mediaSource);
player.prepare(); player.prepare();
// Start the playback. // Start the playback.
player.play(); player.play();