play video using jmf repeat automcatically

2k Views Asked by At

hello friends i dont know more about jmf i play video using java media framework. now How Can repeat video automatically means video play for ever until usr press stop button thanks

3

There are 3 best solutions below

0
On

After creating the player, you could add a ControllerListener. When the file ends an EndOfMediaEvent is generated. When you get that event, you can use the function setMediaTime(0) to start playing the file from the beginning

0
On

"Reaching the end of play (signaled by an EndOfMedia event) is dealt with by setting the media's own time to zero (back to the start) and restarting the Player" [Book: (Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization)]

In the code below, the object p is a player.

 p.addControllerListener(new ControllerListener() {
        public void controllerUpdate(ControllerEvent event) {
           if (event instanceof EndOfMediaEvent) {

            p.setMediaTime(new Time(0));
            System.out.println("End of Media – restarting");
            p.start();

           }
        }
     });
0
On

With an mp3, I had to call both player.start() and player.setMediaTime(new Time(0.)). Otherwise it would not replay any other way.