Sign in to follow this  
Pracka

[java] How to close Frame window after it player video?(JMF)

Recommended Posts

Iam using Java media framework to play intro from my game. I've got one class(it extends Frame) which takes care about playing video and another class(which is in LWJGL OPenGl window)to start the game. I want to play video in and after it and I want to create class which start the game and close the Frame window. Please take a look on code. Class playing video
 
ublic class VideoPlayer extends Frame implements ControllerListener{
    
    private Player videoPlayer;
    public VideoPlayer() {
     addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        dispose();
      }
    });
  
    }
    public static void playVideo() {
        VideoPlayer prehravac = new VideoPlayer(); 
        prehravac.setUndecorated(true);
        prehravac.show();
        prehravac.setExtendedState(MAXIMIZED_BOTH);
        prehravac.setLocation(0, 0);
        prehravac.play();
    }
    
    public void play()  
    {
        URL url;
        try {
            url = new URL("file:///f:\\1.mov");
            videoPlayer = Manager.createPlayer(url);
            videoPlayer.addControllerListener(this);
            videoPlayer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

     videoPlayer.addControllerListener(this);
    }
    public synchronized void controllerUpdate(ControllerEvent event) {
    if (event instanceof RealizeCompleteEvent) {
    	Component comp;
    	if ((comp = videoPlayer.getVisualComponent()) != null)
    		add ("Center", comp);
    	validate();
    }
    
    }
    
}
Main method of game(in LWJGL OpenGl Window
 
public static void main(String[] args)
	{
		VideoPlayer.playVideo();
		Window window = new Window(1024,768,true);
		okno.startGame();
    }
Probably this isnt best way to play video, but if you got better I will be pleased if you share it with me. Thank to every advice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this