first step
This commit is contained in:
parent
2822f299f1
commit
5969115062
2 changed files with 49 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
package asgardius.page.s3manager;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.android.exoplayer2.database.DatabaseProvider;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer2.upstream.FileDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSink;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CacheDataSourceFactory implements DataSource.Factory {
|
||||
private final Context context;
|
||||
private final DefaultDataSource.Factory defaultDatasourceFactory;
|
||||
private final long maxFileSize, maxCacheSize;
|
||||
//DatabaseProvider databaseProvider = ExoDatabaseProvider(this);
|
||||
|
||||
public CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.maxCacheSize = maxCacheSize;
|
||||
this.maxFileSize = maxFileSize;
|
||||
String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name));
|
||||
//DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||
defaultDatasourceFactory = new DefaultDataSource.Factory(this.context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
|
||||
SimpleCache simpleCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor);
|
||||
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
|
||||
new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
|
||||
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package asgardius.page.s3manager;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
|
@ -13,6 +14,9 @@ import com.google.android.exoplayer2.ExoPlayer;
|
|||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerView;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
|
||||
|
@ -43,6 +47,8 @@ public class VideoPlayer extends AppCompatActivity {
|
|||
playerView = findViewById(R.id.player_view);
|
||||
// creating a variable for exoplayer
|
||||
player = new ExoPlayer.Builder(this).build();
|
||||
//MediaSource audioSource = new ProgressiveMediaSource(Uri.parse("url"),
|
||||
// new CacheDataSourceFactory(this, 100 * 1024 * 1024, 5 * 1024 * 1024), new DefaultExtractorsFactory(), null, null);
|
||||
// Attach player to the view.
|
||||
playerView.setPlayer(player);
|
||||
MediaItem mediaItem = MediaItem.fromUri(videoURL);
|
||||
|
@ -50,6 +56,8 @@ public class VideoPlayer extends AppCompatActivity {
|
|||
// Set the media item to be played.
|
||||
player.setMediaItem(mediaItem);
|
||||
// Prepare the player.
|
||||
player.setPlayWhenReady(true);
|
||||
//player.setMediaSource(audioSource);
|
||||
player.prepare();
|
||||
// Start the playback.
|
||||
player.play();
|
||||
|
|
Loading…
Reference in a new issue