get links

This commit is contained in:
Page Asgardius 2023-01-02 11:52:55 -07:00
parent 3c8d41e05e
commit c3cf489510
4 changed files with 131 additions and 62 deletions

View file

@ -44,14 +44,13 @@ public class BucketSelect extends AppCompatActivity {
ArrayList Img; ArrayList Img;
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, prefix, location, file, pdfendpoint; String username, password, endpoint, prefix, location, file, pdfendpoint;
boolean style; boolean style, isplaylist;
int treelevel;
Region region; Region region;
S3ClientOptions s3ClientOptions; S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
ProgressBar simpleProgressBar; ProgressBar simpleProgressBar;
int videocache, videotime, buffersize; int videocache, videotime, buffersize, treelevel, playlisttime;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -64,7 +63,9 @@ public class BucketSelect extends AppCompatActivity {
style = getIntent().getBooleanExtra("style", false); style = getIntent().getBooleanExtra("style", false);
videocache = getIntent().getIntExtra("videocache", 40); videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1); videotime = getIntent().getIntExtra("videotime", 1);
playlisttime = getIntent().getIntExtra("playlisttime", 1);
buffersize = getIntent().getIntExtra("buffersize", 2000); buffersize = getIntent().getIntExtra("buffersize", 2000);
isplaylist = getIntent().getBooleanExtra("isplaylist", false);
prefix = ""; prefix = "";
setContentView(R.layout.activity_bucket_select); setContentView(R.layout.activity_bucket_select);
region = Region.getRegion("us-east-1"); region = Region.getRegion("us-east-1");
@ -216,6 +217,8 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("videocache", videocache); intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime); intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize); intent.putExtra("buffersize", buffersize);
intent.putExtra("playlisttime", playlisttime);
intent.putExtra("isplaylist", isplaylist);
startActivity(intent); startActivity(intent);
} }

View file

@ -20,19 +20,21 @@ import java.util.ArrayList;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
boolean style; boolean style, isplaylist;
String alias, username, password, endpoint, location, pdfendpoint; String alias, username, password, endpoint, location, pdfendpoint;
RecyclerView recyclerView; RecyclerView recyclerView;
SQLiteDatabase db; SQLiteDatabase db;
ArrayList Name; ArrayList Name;
ArrayList Img; ArrayList Img;
MyDbHelper dbHelper; MyDbHelper dbHelper;
int videocache, videotime, buffersize; int videocache, videotime, buffersize, playlisttime;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
isplaylist = true;
playlisttime = 1;
recyclerView = findViewById(R.id.alist); recyclerView = findViewById(R.id.alist);
@ -379,6 +381,8 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("videocache", videocache); intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime); intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize); intent.putExtra("buffersize", buffersize);
intent.putExtra("playlisttime", playlisttime);
intent.putExtra("isplaylist", isplaylist);
startActivity(intent); startActivity(intent);
} }

View file

@ -4,15 +4,11 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.app.AppOpsManager;
import android.app.PictureInPictureParams;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
@ -39,7 +35,6 @@ import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -50,16 +45,14 @@ public class ObjectSelect extends AppCompatActivity {
//ArrayList object; //ArrayList object;
RecyclerView recyclerView; RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location, pdfendpoint, query; String username, password, endpoint, bucket, prefix, location, pdfendpoint, query;
boolean style; boolean style, isplaylist;
int treelevel;
String[] filename; String[] filename;
Region region; Region region;
S3ClientOptions s3ClientOptions; S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials; AWSCredentials myCredentials;
AmazonS3 s3client; AmazonS3 s3client;
ProgressBar simpleProgressBar; ProgressBar simpleProgressBar;
int videocache, videotime, buffersize; int videocache, videotime, buffersize, treelevel, playlisttime;
AppOpsManager appOpsManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -75,8 +68,9 @@ public class ObjectSelect extends AppCompatActivity {
treelevel = getIntent().getIntExtra("treelevel", 0); treelevel = getIntent().getIntExtra("treelevel", 0);
videocache = getIntent().getIntExtra("videocache", 40); videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1); videotime = getIntent().getIntExtra("videotime", 1);
playlisttime = getIntent().getIntExtra("playlisttime", 1);
buffersize = getIntent().getIntExtra("buffersize", 2000); buffersize = getIntent().getIntExtra("buffersize", 2000);
appOpsManager = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE); isplaylist = getIntent().getBooleanExtra("isplaylist", false);
setContentView(R.layout.activity_object_select); setContentView(R.layout.activity_object_select);
getSupportActionBar().setTitle(bucket+"/"+prefix); getSupportActionBar().setTitle(bucket+"/"+prefix);
region = Region.getRegion(location); region = Region.getRegion(location);
@ -327,48 +321,52 @@ public class ObjectSelect extends AppCompatActivity {
pdfread.start(); pdfread.start();
} }
} else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) { } else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) {
Thread mediaread = new Thread(new Runnable() { if (isplaylist) {
videoPlayer(null, Name.get(position).toString());
} else {
Thread mediaread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
//load media file //load media file
Date expiration = new Date(); Date expiration = new Date();
Calendar mycal = Calendar.getInstance(); Calendar mycal = Calendar.getInstance();
mycal.setTime(expiration); mycal.setTime(expiration);
//System.out.println("today is " + mycal.getTime()); //System.out.println("today is " + mycal.getTime());
mycal.add(Calendar.HOUR, videotime); mycal.add(Calendar.HOUR, videotime);
//System.out.println("Expiration date: " + mycal.getTime()); //System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime(); expiration = mycal.getTime();
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()).withExpiration(expiration);; GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()).withExpiration(expiration);;
URL objectURL = s3client.generatePresignedUrl(request); URL objectURL = s3client.generatePresignedUrl(request);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
// Sending reference and data to Adapter // Sending reference and data to Adapter
videoPlayer(objectURL.toString(), Name.get(position).toString(), Name.get(position).toString().endsWith(".m3u8")); videoPlayer(objectURL.toString(), Name.get(position).toString());
} }
}); });
//System.out.println("tree "+treelevel); //System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix); //System.out.println("prefix "+prefix);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
} }
}); });
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish(); finish();
}
} }
} });
}); mediaread.start();
mediaread.start(); }
} else { } else {
Toast.makeText(ObjectSelect.this, getResources().getString(R.string.unsupported_file), Toast.LENGTH_SHORT).show(); Toast.makeText(ObjectSelect.this, getResources().getString(R.string.unsupported_file), Toast.LENGTH_SHORT).show();
} }
@ -459,15 +457,60 @@ public class ObjectSelect extends AppCompatActivity {
})); }));
} }
private void videoPlayer(String url, String title, boolean hls) { private void videoPlayer(String url, String title) {
Intent intent = new Intent(this, VideoPlayer.class); if (isplaylist) {
intent.putExtra("video_url", url); Thread mediaread = new Thread(new Runnable() {
intent.putExtra("title", title);
intent.putExtra("videocache", videocache); @Override
intent.putExtra("buffersize", buffersize); public void run() {
intent.putExtra("hls", hls); try {
startActivity(intent); //load media file
ArrayList<String> medialist = new ArrayList<String>();
for (int i = 0; i < Name.size(); i++) {
if (Img.get(i).equals(R.drawable.audiofile) || Img.get(i).equals(R.drawable.videofile)) {
medialist.add(Name.get(i).toString());
}
}
ArrayList<String> links = getLinks(medialist);
for (int i = 0; i < links.size(); i++) {
System.out.println(links.get(i));
}
System.out.println("Position of selected file: "+medialist.indexOf(title));
runOnUiThread(new Runnable() {
@Override
public void run() {
// Sending reference and data to Adapter
//videoPlayer(objectURL.toString(), Name.get(position).toString());
}
});
//System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix);
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
});
}
}
});
mediaread.start();
} else {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("title", title);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("isplaylist", isplaylist);
startActivity(intent);
}
} }
private void textViewer(String url) { private void textViewer(String url) {
@ -512,6 +555,8 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("videocache", videocache); intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime); intent.putExtra("videotime", videotime);
intent.putExtra("buffersize", buffersize); intent.putExtra("buffersize", buffersize);
intent.putExtra("playlisttime", playlisttime);
intent.putExtra("isplaylist", isplaylist);
startActivity(intent); startActivity(intent);
} }
@ -693,4 +738,20 @@ public class ObjectSelect extends AppCompatActivity {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_name_ok), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.copy_name_ok), Toast.LENGTH_SHORT).show();
} }
} }
public ArrayList<String> getLinks (ArrayList<String> medialist) throws InterruptedException {
ArrayList<String> links = new ArrayList<String>();
Date expiration = new Date();
Calendar mycal = Calendar.getInstance();
mycal.setTime(expiration);
//System.out.println("today is " + mycal.getTime());
mycal.add(Calendar.HOUR, playlisttime);
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
for (int i = 0; i < medialist.size(); i++) {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix+medialist.get(i)).withExpiration(expiration);;
links.add(s3client.generatePresignedUrl(request).toString());
}
return links;
}
} }

View file

@ -56,7 +56,7 @@ public class VideoPlayer extends AppCompatActivity {
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
private PowerManager powerManager; private PowerManager powerManager;
private long maxCacheSize; private long maxCacheSize;
ArrayList<String> queue; ArrayList<String> queue, names;
LeastRecentlyUsedCacheEvictor evictor; LeastRecentlyUsedCacheEvictor evictor;
StandaloneDatabaseProvider standaloneDatabaseProvider; StandaloneDatabaseProvider standaloneDatabaseProvider;
SimpleCache simpleCache; SimpleCache simpleCache;
@ -105,8 +105,9 @@ public class VideoPlayer extends AppCompatActivity {
title = getIntent().getStringExtra("title"); title = getIntent().getStringExtra("title");
videocache = getIntent().getIntExtra("videocache", 40); videocache = getIntent().getIntExtra("videocache", 40);
buffersize = getIntent().getIntExtra("buffersize", 2000); buffersize = getIntent().getIntExtra("buffersize", 2000);
isplaylist = getIntent().getBooleanExtra("hls", false); isplaylist = getIntent().getBooleanExtra("isplaylist", false);
queue = getIntent().getStringArrayListExtra("queue"); queue = getIntent().getStringArrayListExtra("queue");
names = getIntent().getStringArrayListExtra("names");
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build(); loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build();
@ -328,7 +329,7 @@ public class VideoPlayer extends AppCompatActivity {
title = intent.getStringExtra("title"); title = intent.getStringExtra("title");
videocache = intent.getIntExtra("videocache", 40); videocache = intent.getIntExtra("videocache", 40);
buffersize = intent.getIntExtra("buffersize", 2000); buffersize = intent.getIntExtra("buffersize", 2000);
isplaylist = intent.getBooleanExtra("hls", false); isplaylist = intent.getBooleanExtra("isplaylist", false);
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
mediaSource = new ProgressiveMediaSource.Factory( mediaSource = new ProgressiveMediaSource.Factory(
new CacheDataSource.Factory() new CacheDataSource.Factory()