m3u playlists

This commit is contained in:
Page Asgardius 2023-03-03 13:17:47 -07:00
parent 684c1e36cc
commit 98cd78a1ec
3 changed files with 97 additions and 17 deletions

View file

@ -19,7 +19,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31" >
tools:targetApi="31"
android:usesCleartextTraffic="true" >
<activity
android:name=".ObjectPolicy"
android:exported="false" />

View file

@ -30,6 +30,8 @@ import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
@ -192,7 +194,7 @@ public class ObjectSelect extends AppCompatActivity {
else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".opus") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".ogg")
|| Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".oga") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mp3")
|| Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".m4a") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".flac")
|| Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mka")) {
|| Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mka") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".m3u")) {
Img.add(R.drawable.audiofile);
}
else if(Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mp4") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mkv")
@ -322,7 +324,7 @@ public class ObjectSelect extends AppCompatActivity {
}
} else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) {
simpleProgressBar.setVisibility(View.VISIBLE);
if (isplaylist) {
if (isplaylist && !Name.get(position).toString().toLowerCase(Locale.ROOT).endsWith(".m3u")) {
videoPlayer(null, Name.get(position).toString());
} else {
Thread mediaread = new Thread(new Runnable() {
@ -471,7 +473,55 @@ public class ObjectSelect extends AppCompatActivity {
}
private void videoPlayer(String url, String title) {
if (isplaylist) {
if (title.toLowerCase(Locale.ROOT).endsWith(".m3u")) {
Thread mediaread = new Thread(new Runnable() {
@Override
public void run() {
try {
//load media file
ArrayList<String> links = getPlaylist(url);
ArrayList<String> medialist = new ArrayList<String>();
for (int i = 0; i < links.size(); i++) {
medialist.add(links.get(i).toString());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// Sending reference and data to Adapter
//videoPlayer(objectURL.toString(), Name.get(position).toString());
Intent intent = new Intent(getApplicationContext(), VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("title", title);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("isplaylist", true);
intent.putExtra("queue", links);
intent.putExtra("names", medialist);
simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent);
}
});
//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(),e.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
});
mediaread.start();
}
else if (isplaylist) {
Thread mediaread = new Thread(new Runnable() {
@Override
@ -490,18 +540,20 @@ public class ObjectSelect extends AppCompatActivity {
@Override
public void run() {
// Sending reference and data to Adapter
//videoPlayer(objectURL.toString(), Name.get(position).toString());
Intent intent = new Intent(getApplicationContext(), VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("title", title);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("isplaylist", isplaylist);
intent.putExtra("queue", links);
intent.putExtra("names", medialist);
simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent);
if(links != null) {
// Sending reference and data to Adapter
//videoPlayer(objectURL.toString(), Name.get(position).toString());
Intent intent = new Intent(getApplicationContext(), VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("title", title);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("isplaylist", isplaylist);
intent.putExtra("queue", links);
intent.putExtra("names", medialist);
simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent);
}
}
});
//System.out.println("tree "+treelevel);
@ -532,6 +584,7 @@ public class ObjectSelect extends AppCompatActivity {
}
}
private void textViewer(String url) {
Intent intent = new Intent(this, TextViewer.class);
@ -789,4 +842,26 @@ public class ObjectSelect extends AppCompatActivity {
}
return links;
}
public ArrayList<String> getPlaylist(String playlist) {
ArrayList<String> links = new ArrayList<String>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader((new URL(playlist).openStream())));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console - do what you want to do
if(!strLine.startsWith("#")) {
links.add(strLine);
}
}
//Close the input stream
return links;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View file

@ -170,7 +170,11 @@ public class VideoPlayer extends AppCompatActivity {
}
}
player.prepare();
player.seekTo(names.indexOf(title), 0);
try {
player.seekTo(names.indexOf(title), 0);
}catch (Exception e) {
System.out.println("Playing m3u file");
}
} else {
if (title.endsWith(".m3u8")) {
MediaItem mediaItem = MediaItem.fromUri(Share.URLify(videoURL));