Skip to content

Commit

Permalink
Dont release Media right after initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kairusds committed Oct 17, 2024
1 parent 66e9f0a commit 8ca517c
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity {
private VLCVideoLayout videoLayout = null;
private LibVLC libVLC = null;
private MediaPlayer mediaPlayer = null;
private Media media = null;
private long time = 0L;
private int audiotrackSessionId = 0;
private final ArrayList<String> options = new ArrayList<>();
Expand Down Expand Up @@ -116,8 +117,10 @@ private void destroyVLC(){
mediaPlayer.detachViews();
mediaPlayer.release();
libVLC.release();
media.release();
mediaPlayer = null;
libVLC = null;
media = null;
videoPath = null;
}

Expand Down Expand Up @@ -169,10 +172,10 @@ private void attachViews(){
if(!libVLCAvailable() && videoPath == null) return;
mediaPlayer.attachViews(videoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);
try{
final Media media = new Media(libVLC, videoPath);
media = new Media(libVLC, videoPath);
media.setHWDecoderEnabled(true, true); // full hardware decoding
mediaPlayer.setMedia(media);
media.release();
// media.release();
}catch(Exception e){
toast(e.getMessage());
// throw new RuntimeException("Invalid file");
Expand All @@ -195,7 +198,7 @@ private void setVLCMedia(String path){
break;
}
});

play();
}

Expand Down Expand Up @@ -300,7 +303,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();
// attachViews();
play();
}

Expand All @@ -311,7 +314,7 @@ protected void onStop(){ // activity is in the background or minimized
pause();
// mediaPlayer.pause();
// mediaPlayer.stop();
mediaPlayer.detachViews();
// mediaPlayer.detachViews();
}

}

0 comments on commit 8ca517c

Please sign in to comment.