使用 JMF 从网络摄像头流式传输视频会导致 Windows 7 切换到基本主题
我的 Java 程序打开网络摄像头流并将捕获的视频流式传输到 Swing 组件,但当我启动它时,它会导致 Windows 切换到基本主题。这是我的代码的摘录:
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
captureDeviceInfo = CaptureDeviceManager.getDevice(str2);
Format[] formats = captureDeviceInfo.getFormats();
for (Format format : formats) {
System.out.println(format);
}
mediaLocator = captureDeviceInfo.getLocator();
try {
player = Manager.createRealizedPlayer(mediaLocator);
player.start();
Component comp;
if ((comp = player.getVisualComponent()) != null) {
playerPanel.add(comp);
add(playerPanel, BorderLayout.NORTH);
}
如果我注释掉将 comp 添加到playerPanel 的行,它不会切换到基本主题,所以我认为这就是出错的地方。据我了解,JMF 不再维护,并且可能与 Windows 7 Aero 主题不完全兼容。但仍然有办法解决这个问题吗?为什么会切换?
My Java program that opens up a webcam stream and streams the captured video to a Swing component works, but when I launch it, it causes Windows to switch to the Basic theme. This is an excerpt from my code:
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
captureDeviceInfo = CaptureDeviceManager.getDevice(str2);
Format[] formats = captureDeviceInfo.getFormats();
for (Format format : formats) {
System.out.println(format);
}
mediaLocator = captureDeviceInfo.getLocator();
try {
player = Manager.createRealizedPlayer(mediaLocator);
player.start();
Component comp;
if ((comp = player.getVisualComponent()) != null) {
playerPanel.add(comp);
add(playerPanel, BorderLayout.NORTH);
}
If I comment out the line where the I add comp to playerPanel, it doesn't switch to the basic theme, so I assume that's where it goes wrong. From what I understand JMF is not maintained anymore and probably isn't fully compatible with Windows 7 Aero Theme. But still, is there a way to fix this? Why does it switch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
既然您说只有当您将组件添加到播放器面板时(因此当视频可见时)才会发生这种情况,我认为这可能与我曾经遇到的 Media Player Classic 问题有关。
来自 http://www.codecguide.com/faq_mpc.htm:
播放器组件可能使用此 Overlay Mixer 来显示视频。尝试看看是否可以改变它。
Since you said that it only happens when you add the component to the player panel (so when the video is visible), I think it might be related to an issue I once had with Media Player Classic.
From http://www.codecguide.com/faq_mpc.htm:
Probably the player component uses this Overlay Mixer to display the video. Try to find out if you can change it.
好的,这个问题的答案是安装网络摄像头驱动程序。我使用的是 Logitech QuickCam Pro 9000,因此我刚刚从 Logitech 网站下载了驱动程序。显然,如果您使用 Windows 提供的通用网络摄像头驱动程序,您可以获得我之前描述的行为。
Okay so, the answer to this one was to install the webcam drivers. I'm using a Logitech QuickCam Pro 9000, so I just downloaded the driver from Logitech's website. Apparently if you use the generic webcam driver that Windows provides you can get the behavior I described earlier.
要解决该问题,请在构造函数中添加以下内容:
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, Boolean.TRUE);
您的问题仅仅是由于 Swing 是轻量级的并且默认渲染目标是重量级组件。
To solve the problem, add the following in your constructor:
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, Boolean.TRUE);
Your problem is simply due to the fact that Swing is lightweight and the default rendering targets heavyweight components.