1 Reply Latest reply: Nov 28, 2012 10:34 AM by MiPa RSS

    (Video-)Media not getting released

    Marcello
      I noticed this while testing the capability of playing videos with an alpha channel.
      When a movie is loaded, the file cannot become deleted with the (Windows-)Filemanager. I get the error msg that the file is "used by java".
      How can I make sure that the media file is getting released ?
      Below is my Test:
      public class MediaTestFX extends Application {
           MediaPlayer player;
           MediaView mediaView;
           Media media;
           
           @Override
           public void start(Stage stage) throws Exception {          
                 
                media = new Media( 
      
                     "file:/C:/blabla/Titel.flv"                   
                         );
                     media.setOnError( new Runnable(){
      
                     @Override
                     public void run() {
                          player.stop();                    
                     }               
                });
                                              
                player = new MediaPlayer(     media);
                player.setMute( true);
                player.setAutoPlay( true);
                
                mediaView = new MediaView();
                mediaView.setMediaPlayer( player);
                
                player.setOnError( new Runnable(){
      
                     @Override
                     public void run() {
                          player.stop();
                     }
                     
                });
                mediaView.setVisible( true);
              player.setOnEndOfMedia( new Runnable() {
                     
                     @Override
                     public void run() {
                     }
                });
           
              BorderPane border = new BorderPane();                    
                border.setCenter(  mediaView);                    
      
                Button but = new Button("Stop");
               but.setOnAction( new EventHandler<ActionEvent>() {
                     @Override
                     public void handle(ActionEvent arg0) {                    
                          player.stop();
                          player = null;
                     
                          media = null;
                          mediaView = null;                    
                     }
                });
                                                      
                border.setBottom( but);
                BorderPane.setAlignment( but, Pos.CENTER);
                          
                
                     
                
                stage.setScene( new Scene( border, 640, 480, Color.WHITESMOKE));
                stage.show();
      
                                    
           }     
           
      
           public static void main(String[] args) throws Exception{          
              Application.launch(args);
          }
      
      }