本文介绍了在Swing GUI中嵌入视频的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一段将视频嵌入Java Swing GUI的简单方法。我追风吗?理想情况下,我希望有类似的东西:

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:

VideoPlayer video = new VideoPlayer("filename");
frame.getContentPane().add(video);
video.play();

我在寻找不存在的东西吗?我主要针对Linux进行开发,但考虑到Windows,因为我可能会尝试在未来使用我的应用程序。

Am I searching for something that doesn't exist? I've developing mainly for linux but with windows in mind as I might try and make my application cross platform in the future.

附加信息:


  • 之前我曾看过JMF,并且对视频实际显示和播放之前所需的代码量感到不满意。我可能会再次访问它。

  • 我想到了一个可以使用VLC播放视频的嵌入式浏览器,但同样不是最简单的事情。

  • 我完全控制了要播放的视频的格式。它们是固定的,如果需要可以重新编码。

推荐答案

我不知道你为什么认为你需要很多代码才能使用JMF。

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);
        }
    }

类似6的完整媒体播放器线,prob可以做得更少。如果您需要的只是基本的东西,那么id就是JMF。

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.

正如Zemzela所说,Xuggle也是一个很好的解决方案,但需要更多的工作。

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

还有Java绑定VLC。

There are also Java bindings VLC. Click Here

这篇关于在Swing GUI中嵌入视频的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:46