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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager" android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31" > tools:targetApi="31"
android:usesCleartextTraffic="true" >
<activity <activity
android:name=".ObjectPolicy" android:name=".ObjectPolicy"
android:exported="false" /> 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.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; 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") 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(".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(".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); 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") 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)) { } else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) {
simpleProgressBar.setVisibility(View.VISIBLE); simpleProgressBar.setVisibility(View.VISIBLE);
if (isplaylist) { if (isplaylist && !Name.get(position).toString().toLowerCase(Locale.ROOT).endsWith(".m3u")) {
videoPlayer(null, Name.get(position).toString()); videoPlayer(null, Name.get(position).toString());
} else { } else {
Thread mediaread = new Thread(new Runnable() { Thread mediaread = new Thread(new Runnable() {
@ -471,7 +473,55 @@ public class ObjectSelect extends AppCompatActivity {
} }
private void videoPlayer(String url, String title) { 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() { Thread mediaread = new Thread(new Runnable() {
@Override @Override
@ -490,6 +540,7 @@ public class ObjectSelect extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
if(links != null) {
// Sending reference and data to Adapter // Sending reference and data to Adapter
//videoPlayer(objectURL.toString(), Name.get(position).toString()); //videoPlayer(objectURL.toString(), Name.get(position).toString());
Intent intent = new Intent(getApplicationContext(), VideoPlayer.class); Intent intent = new Intent(getApplicationContext(), VideoPlayer.class);
@ -503,6 +554,7 @@ public class ObjectSelect extends AppCompatActivity {
simpleProgressBar.setVisibility(View.INVISIBLE); simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent); startActivity(intent);
} }
}
}); });
//System.out.println("tree "+treelevel); //System.out.println("tree "+treelevel);
//System.out.println("prefix "+prefix); //System.out.println("prefix "+prefix);
@ -532,6 +584,7 @@ public class ObjectSelect extends AppCompatActivity {
} }
} }
private void textViewer(String url) { private void textViewer(String url) {
Intent intent = new Intent(this, TextViewer.class); Intent intent = new Intent(this, TextViewer.class);
@ -789,4 +842,26 @@ public class ObjectSelect extends AppCompatActivity {
} }
return links; 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.prepare();
try {
player.seekTo(names.indexOf(title), 0); player.seekTo(names.indexOf(title), 0);
}catch (Exception e) {
System.out.println("Playing m3u file");
}
} else { } else {
if (title.endsWith(".m3u8")) { if (title.endsWith(".m3u8")) {
MediaItem mediaItem = MediaItem.fromUri(Share.URLify(videoURL)); MediaItem mediaItem = MediaItem.fromUri(Share.URLify(videoURL));