Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
kairusds committed Oct 17, 2024
1 parent 88d4b0b commit 66e9f0a
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public class MainActivity extends AppCompatActivity {
private ExecutorService executor;

private VLCVideoLayout videoLayout = null;

private LibVLC libVLC = null;
private MediaPlayer mediaPlayer = null;
private long time = 0L;
private int audiotrackSessionId = 0;

private final ArrayList<String> options = new ArrayList<>();

private String videoPath;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -112,11 +112,13 @@ private void initVLC(){

private void destroyVLC(){
if(!libVLCAvailable()) return;
mediaPlayer.stop();
mediaPlayer.detachViews();
mediaPlayer.release();
libVLC.release();
mediaPlayer = null;
libVLC = null;
videoPath = null;
}

private boolean libVLCAvailable(){
Expand Down Expand Up @@ -163,29 +165,32 @@ private void play(){
mediaPlayer.play();
}

private void setVLCMedia(String path){
if(libVLCAvailable()) return;
toast("setVLCMedia");
initVLC();
private void attachViews(){
if(!libVLCAvailable() && videoPath == null) return;
mediaPlayer.attachViews(videoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);
try{
final Media media = new Media(libVLC, path);
final Media media = new Media(libVLC, videoPath);
media.setHWDecoderEnabled(true, true); // full hardware decoding
mediaPlayer.setMedia(media);
media.release();
toast("1");
}catch(Exception e){
toast(e.getMessage());
// throw new RuntimeException("Invalid file");
}
}

private void setVLCMedia(String path){
if(libVLCAvailable()) return;
initVLC();
videoPath = path;
attachViews();

mediaPlayer.setEventListener(event -> {
switch(event.type){
case Event.TimeChanged:
time = event.getTimeChanged();
break;
case Event.EndReached:
mediaPlayer.stop();
destroyVLC();
break;
}
Expand Down Expand Up @@ -295,6 +300,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data){
protected void onStart(){ // activity is in view again or the real resumed state
super.onStart();
// mediaPlayer.play();
attachViews();
play();
}

Expand Down

0 comments on commit 66e9f0a

Please sign in to comment.