A simple way of embedding a video in my Swing GUI

前端 未结 2 1989
小鲜肉
小鲜肉 2021-02-02 02:23

I\'ve been looking for a while now for a dead simple way of embedding a video into my Java Swing GUI. Am I chasing after the wind? Ideally, I would love to have something like:<

2条回答
  •  遇见更好的自我
    2021-02-02 03:06

    I dont know why you think you need a lot of code to use JMF.

    
        public class mediaPlayer extends JFrame
        {
            public mediaPlayer()
            {
                setLayout(new BorderLayout());
    
                //file you want to play
                URL mediaURL = //Whatever
                //create the media player with the media url
                Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
                //get components for video and playback controls
                Component video = mediaPlayer.getVisualComponent();
                Component controls = mediaPlayer.getControlPanelComponent();
                add(video,BorderLayout.CENTER);
                add(controls,BorderLayout.SOUTH);
            }
        }
    
    

    A complete media player in like 6 lines, prob could have done it in less. If all you need is something basic, then id go with JMF.

    As Zemzela mentioned, Xuggle is also a good solution but will require more work.

    There are also Java bindings VLC. Click Here

提交回复
热议问题