Results 1 to 3 of 3
  1. #1
    Gog
    Gog is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Talking JMF mediaPlayer.close

    Hi,
    I have problem, when I click to any JButton -> It start plays MPEG video (for example: 10s) -> (I use Timer to check duration of video), video plays in JWINDOW /setVisible(true)/ and start Timer set on 10s, after 10s Timer setVisible(false) *JWINDOW* -> It works! But when I want second time click on the same JButton, I have
    last picture from first video.

    I post you 4 classes of my program, check it pls (I have problem with mediaPlayer.close).

    first class ->
    *PLAYER*

    Java Code:
    package kiosk;
    
    import java.awt.Component;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JWindow;
    
    public class Prehravac extends JWindow {
    
        public Prehravac(URL mediaURL) throws MalformedURLException, IOException, NoPlayerException, CannotRealizeException {
            Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
            Component video = mediaPlayer.getVisualComponent();
    //        Component stop = mediaPlayer.getControlPanelComponent();
            mediaPlayer.start();
    
            if (Background.viditelnostOkna == false) {
                mediaPlayer.stop();
            }
    
            if (mediaURL != null) {
    //            Background.oknoPrehravace.add(stop);
                Background.viditelnostOkna = true;
                Background.oknoPrehravace.add(video);
                Background.oknoPrehravace.setVisible(Background.viditelnostOkna);
    
            }
        }
    }
    --------------
    2. class: (only part of class)
    *public static JWindow oknoPrehravace = new JWindow();public static boolean viditelnostOkna = true;*
    Java Code:
    package kiosk;
    
    import kiosk.Akce.ZpetAZobrazeni;
    import java.awt.Font;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JTextArea;
    import javax.swing.JWindow;
    import kiosk.Akce.CtvrtePatro;
    import kiosk.Akce.DruhePatro;
    import kiosk.Akce.PrvniPatro;
    import kiosk.Akce.TretiPatro;
    import kiosk.Akce.Vedeni;
    import kiosk.Tlacitka.MenuTlacitko;
    import kiosk.Tlacitka.MistnostTlacitko;
    import kiosk.Tlacitka.ZpetTlacitko;
    
    public class Background extends JWindow {
    
        public static JWindow oknoPrehravace = new JWindow();
        public static boolean viditelnostOkna = true;
     
    }
    3. class:
    *TIMER*

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package kiosk;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    /**
     *
     * @author Gog
     */
    public class Casovac implements ActionListener {
    
        javax.swing.Timer t = null;
    
        public Casovac(int delay) {
            t = new javax.swing.Timer(delay, this);
            t.start();
        }
    
        public void actionPerformed(ActionEvent e) {
            Background.viditelnostOkna = false;
            Background.oknoPrehravace.setVisible(Background.viditelnostOkna);
        }
    }
    4. class:
    *ACTION*

    Java Code:
    package kiosk.Akce;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.media.CannotRealizeException;
    import javax.media.NoPlayerException;
    import kiosk.Background;
    import kiosk.Casovac;
    import kiosk.Prehravac;
    
    public class Vedeni {
    
        public Vedeni() {
    
            ActionListener sborovnaAction = new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
                    try {
                        Prehravac p = new Prehravac(new File("d:/bailey.mpg").toURL());
                        Casovac c = new Casovac(26000);
                    } catch (MalformedURLException ex) {
                        Logger.getLogger(Background.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        Logger.getLogger(Background.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (NoPlayerException ex) {
                        Logger.getLogger(Background.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (CannotRealizeException ex) {
                        Logger.getLogger(Background.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            };
    
    }
    }
    I think when *Background.oknoPrehravace.setVisible(Background.v iditelnostOkna);* will be *FALSE* it STOP *mediaPlayer* -> *if (Background.viditelnostOkna == false){mediaPlayer.stop();}*

    Thx for help

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You have the last picture from the first video because all you did was hide the view and then make it visible again. You may need to destroy some of the resources and recreate them for each new file - unless JMF has some handy methods to do that automatically. I did this years ago, and just can't remember anymore!

  3. #3
    Gog
    Gog is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    yeah, I know what you mean but I write IF -> if(backgroud.viditelnostOkna == false)mediaPlayer.stop(); -> It doesn't works :-( When I play VIDEO, It will be visible (It plays mediaPlayer -> method -> mediaPlayer.start(); -> after video END I set JWINDOW to invisible -> so mediaPlayer restarted ?! Please help me more :-(

Similar Threads

  1. donīt close a jFrame
    By flaquitqm in forum AWT / Swing
    Replies: 4
    Last Post: 04-25-2010, 02:57 AM
  2. Replies: 13
    Last Post: 04-09-2010, 11:15 AM
  3. close to zero
    By nokicky in forum New To Java
    Replies: 6
    Last Post: 10-26-2009, 04:30 PM
  4. Video MediaPlayer Errors
    By Menre in forum Advanced Java
    Replies: 6
    Last Post: 09-21-2009, 09:49 AM
  5. [SOLVED] Close Exe
    By smartsubroto in forum New To Java
    Replies: 11
    Last Post: 10-14-2008, 08:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •