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:
我一直在寻找一种将视频嵌入Java Swing GUI的简单方法。我追风吗?理想情况下,我希望有类似的东西:
VideoPlayer video = new VideoPlayer("filename");
frame.getContentPane().add(video);
video.play();
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.
我在寻找不存在的东西吗?我主要针对Linux进行开发,但考虑到Windows,因为我可能会尝试在将来使我的应用程序跨平台。
Addtional information:
- I've looked at JMF before and was unpleased at the amount of code needed before a video could actually be displayed and played. I might visit it again.
- I thought of an embedded browser that would play a video using VLC, but again not the easiest thing ever.
- I have complete control on the format of the videos to be played. They are fixed in number and can be recoded if needed.
我之前看过JMF,并且在视频实际显示和播放之前所需的代码量不高兴。我可能会再次访问它。
我想到了一个嵌入式浏览器,可以使用VLC播放视频,但同样不是最简单的事情。
我完全控制了要播放的视频的格式。它们的数量是固定的,如果需要可以重新编码。
2 个解决方案
#1
6
I dont know why you think you need a lot of code to use JMF.
我不知道为什么你认为你需要很多代码才能使用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.
像6行一样的完整媒体播放器,prob可以做得更少。如果你需要的只是基本的东西,那么id就是JMF。
As Zemzela mentioned, Xuggle is also a good solution but will require more work.
正如Zemzela所说,Xuggle也是一个很好的解决方案,但需要更多的工作。
There are also Java bindings VLC. Click Here
还有Java绑定VLC。点击这里
#2
3
you can use xuggle. This is their site http://www.xuggle.com/. I have use it to display avi(divx) and works "fine". JMF i little bit slow in comparation to xuggle. Problem in java is that you can't accurate sync every frame on windows because Thread.sleep(30) doesn't sleep precisely 30 msec, and minimum how much can sleep in windows OS is 16 msec so you can't tune it to be approximately 30 msec. On linux should work more accurately, I think minimum sleeping time is 1 msec.
你可以使用xuggle。这是他们的网站http://www.xuggle.com/。我用它来显示avi(divx)并且工作“很好”。 JMF在与xuggle的比较中有点慢。 java中的问题是你无法准确同步Windows上的每一帧,因为Thread.sleep(30)没有精确地睡眠30毫秒,并且在Windows操作系统中睡眠的最小值是16毫秒因此你无法将它调到大约30毫秒。在Linux上应该更准确地工作,我认为最小睡眠时间是1毫秒。
#1
6
I dont know why you think you need a lot of code to use JMF.
我不知道为什么你认为你需要很多代码才能使用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.
像6行一样的完整媒体播放器,prob可以做得更少。如果你需要的只是基本的东西,那么id就是JMF。
As Zemzela mentioned, Xuggle is also a good solution but will require more work.
正如Zemzela所说,Xuggle也是一个很好的解决方案,但需要更多的工作。
There are also Java bindings VLC. Click Here
还有Java绑定VLC。点击这里
#2
3
you can use xuggle. This is their site http://www.xuggle.com/. I have use it to display avi(divx) and works "fine". JMF i little bit slow in comparation to xuggle. Problem in java is that you can't accurate sync every frame on windows because Thread.sleep(30) doesn't sleep precisely 30 msec, and minimum how much can sleep in windows OS is 16 msec so you can't tune it to be approximately 30 msec. On linux should work more accurately, I think minimum sleeping time is 1 msec.
你可以使用xuggle。这是他们的网站http://www.xuggle.com/。我用它来显示avi(divx)并且工作“很好”。 JMF在与xuggle的比较中有点慢。 java中的问题是你无法准确同步Windows上的每一帧,因为Thread.sleep(30)没有精确地睡眠30毫秒,并且在Windows操作系统中睡眠的最小值是16毫秒因此你无法将它调到大约30毫秒。在Linux上应该更准确地工作,我认为最小睡眠时间是1毫秒。