buffercontrol

This commit is contained in:
Page Asgardius 2022-10-08 08:44:25 -07:00
parent 110f4be0b2
commit fa314adfc3
5 changed files with 104 additions and 30 deletions

View file

@ -47,7 +47,7 @@ public class BucketSelect extends AppCompatActivity {
AWSCredentials myCredentials;
AmazonS3 s3client;
ProgressBar simpleProgressBar;
int videocache, videotime;
int videocache, videotime, buffersize;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -59,6 +59,7 @@ public class BucketSelect extends AppCompatActivity {
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1);
buffersize = getIntent().getIntExtra("buffersize", 2000);
prefix = "";
setContentView(R.layout.activity_bucket_select);
region = Region.getRegion("us-east-1");
@ -198,6 +199,7 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize);
startActivity(intent);
}

View file

@ -27,7 +27,7 @@ public class MainActivity extends AppCompatActivity {
ArrayList Name;
ArrayList Img;
MyDbHelper dbHelper;
int videocache, videotime;
int videocache, videotime, buffersize;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -56,21 +56,34 @@ public class MainActivity extends AppCompatActivity {
videocache = (Integer.parseInt(cursor.getString(0)));
}
db.close();
} catch (Exception e) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
videocache = 300;
db.close();
} catch (Exception f) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
videocache = 300;
//videotime = 3;
db.close();
if (videocache == 0) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
videocache = 300;
db.close();
} catch (Exception e) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
db.execSQL("INSERT INTO preferences VALUES ('buffersize', '12000')");
videocache = 300;
//videotime = 3;
db.close();
}
}
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
}
try {
db = dbHelper.getWritableDatabase();
@ -80,17 +93,61 @@ public class MainActivity extends AppCompatActivity {
videotime = (Integer.parseInt(cursor.getString(0)));
}
db.close();
} catch (Exception e) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
videotime = 3;
db.close();
} catch (Exception f) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.close();
if (videotime == 0) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
videotime = 3;
db.close();
} catch (Exception e) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.close();
}
}
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
}
try {
db = dbHelper.getWritableDatabase();
String query = "SELECT value FROM preferences where setting='buffersize'";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
buffersize = (Integer.parseInt(cursor.getString(0)));
}
db.close();
if (buffersize == 0) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('buffersize', '12000')");
buffersize = 12000;
db.close();
} catch (Exception e) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.close();
}
}
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
}
} catch (Exception e) {
e.printStackTrace();
@ -291,6 +348,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize);
startActivity(intent);
}

View file

@ -9,6 +9,7 @@ public class MyDbHelper extends SQLiteOpenHelper {
private static final String preftable = "CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)";
private static final String setvideocache = "INSERT INTO preferences VALUES ('videocache', '300')";
private static final String setvideotime = "INSERT INTO preferences VALUES ('videotime', '3')";
private static final String setbuffersize = "INSERT INTO preferences VALUES ('buffersize', '12000')";
//private static final String upgrade = "ALTER TABLE account add column pdfendpoint text";
private static final int DATABASE_VERSION = 1;
private static final String dbname = "accounts.sqlite3";
@ -22,6 +23,7 @@ public class MyDbHelper extends SQLiteOpenHelper {
db.execSQL(preftable);
db.execSQL(setvideocache);
db.execSQL(setvideotime);
db.execSQL(setbuffersize);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

View file

@ -50,7 +50,7 @@ public class ObjectSelect extends AppCompatActivity {
AWSCredentials myCredentials;
AmazonS3 s3client;
ProgressBar simpleProgressBar;
int videocache, videotime;
int videocache, videotime, buffersize;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -65,6 +65,7 @@ public class ObjectSelect extends AppCompatActivity {
treelevel = getIntent().getIntExtra("treelevel", 0);
videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1);
buffersize = getIntent().getIntExtra("buffersize", 2000);
setContentView(R.layout.activity_object_select);
getSupportActionBar().setTitle(bucket+"/"+prefix);
region = Region.getRegion(location);
@ -408,6 +409,7 @@ public class ObjectSelect extends AppCompatActivity {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
startActivity(intent);
}
@ -450,6 +452,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize);
startActivity(intent);
}

View file

@ -10,6 +10,8 @@ import android.os.PowerManager;
import android.view.View;
import android.widget.Toast;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
@ -42,9 +44,10 @@ public class VideoPlayer extends AppCompatActivity {
LeastRecentlyUsedCacheEvictor evictor;
StandaloneDatabaseProvider standaloneDatabaseProvider;
SimpleCache simpleCache;
int videocache;
int videocache, buffersize;
ProgressiveMediaSource mediaSource;
DefaultLoadControl loadControl;
DefaultRenderersFactory renderersFactory;
ExoPlayer player;
@Override
@ -58,11 +61,17 @@ public class VideoPlayer extends AppCompatActivity {
//Get media url
String videoURL = getIntent().getStringExtra("video_url");
videocache = getIntent().getIntExtra("videocache", 40);
buffersize = getIntent().getIntExtra("buffersize", 2000);
loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build();
@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;
renderersFactory = new DefaultRenderersFactory(this) .setExtensionRendererMode(extensionRendererMode);
standaloneDatabaseProvider = new StandaloneDatabaseProvider(this);
maxCacheSize = (long)videocache * 1024 * 1024;
playerView = findViewById(R.id.player_view);
// creating a variable for exoplayer
player = new ExoPlayer.Builder(this).build();
player = new ExoPlayer.Builder(this).setLoadControl(loadControl).build();
evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
simpleCache = new SimpleCache(
new File(this.getCacheDir(), "media"),