开发者

play video using jmf repeat automcatically

hello frien开发者_运维技巧ds 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


"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();

           }
        }
     });


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜