gpt4 book ai didi

java - 运行此代码后 vlcj 出错

转载 作者:行者123 更新时间:2023-12-04 11:32:53 29 4
gpt4 key购买 nike

我正在研究 vlcj,试图运行视频流,这是我在本教程中使用的代码 知道如何解决视频中的这个问题 他使用 JFilechooser< 获得了 vlcliber 路径/em>但我将其更改为直接设置路径

lectur video

头等舱

    /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package video;

import java.io.File;
import javax.swing.JFileChooser;


/**
*
* @author isslam
*/
public class start {
private static final JFileChooser ourFileSelector = new JFileChooser();

public static void main(String[] args){
String vlcPath="C:\\Program Files\\VideoLAN\\VLC";
String mediaPath="";
File ourFile;


ourFileSelector.setFileSelectionMode(JFileChooser.FILES_ONLY);
ourFileSelector.showSaveDialog(null);
ourFile = ourFileSelector.getSelectedFile();
mediaPath = ourFile.getAbsolutePath();
new Tutorial2A(vlcPath,mediaPath).run();
}
}

第二类

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package video;

/**
*
* @author isslam
*/
import com.sun.jna.NativeLibrary;
import javax.swing.JFrame;
import uk.co.caprica.vlcj.component.EmbeddedMediaListPlayerComponent;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class Tutorial2A {
private final JFrame ourFrame = new JFrame();
private final EmbeddedMediaPlayerComponent ourMediaPlayer;
private String mediaPath="";



Tutorial2A(String vlcPath,String mediaURL){
this.mediaPath = mediaURL;
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),vlcPath);
ourMediaPlayer = new EmbeddedMediaListPlayerComponent();
ourFrame.setContentPane(ourMediaPlayer);
ourFrame.setSize(500, 500);
ourFrame.setVisible(true);
ourFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public void run(){
ourMediaPlayer.getMediaPlayer().playMedia(mediaPath);
}
}

错误信息

Exception in thread "main" java.lang.RuntimeException: Failed to initialise libvlc.

This is most often caused either by an invalid vlc option begin passed when creating a MediaPlayerFactory or by libvlc being unable to locate the required plugins.

If libvlc is unable to locate the required plugins the instructions below may help:

In the text below <libvlc-path> represents the name of the directory containing "libvlc.dll" and "libvlccore.dll" and <plugins-path> represents the name of the directory containing the vlc plugins...

For libvlc to function correctly the vlc plugins must be available, there are a number of different ways to achieve this:
1. Make sure the plugins are installed in the "<libvlc-path>/plugins" directory, this should be the case with a normal vlc installation.
2. Set the VLC_PLUGIN_PATH operating system environment variable to point to "<plugins-path>".

More information may be available in the log, specify -Dvlcj.log=DEBUG on the command-line when starting your application.


at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:279)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.<init>(MediaPlayerFactory.java:236)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.onGetMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:278)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:168)
at uk.co.caprica.vlcj.component.EmbeddedMediaListPlayerComponent.<init>(EmbeddedMediaListPlayerComponent.java:50)
at video.Tutorial2A.<init>(Tutorial2A.java:29)
at video.start.main(start.java:30)
Java Result: 1
BUILD SUCCESSFUL (total time: 19 seconds)

最佳答案

如果您使用的是 vlcj 3.0.0,那么该版本的 vlcj 取决于 JNA 的 4.0.0 版本。

不幸的是,Windows 上 LibVLC 和 JNA 4.0.0 的组合暴露了一个新错误 [1]。

目前在 Windows 上可用的唯一解决方案是:

  1. 将 VLC_PLUGIN_PATH 环境变量(不是 Java 系统属性)设置为指向包含 vlc 插件的目录,例如"c:\program files\videolan\vlc\plugins"

  2. 确保在运行 Java 程序时当前目录是“c:\program files\videolan\vlc”。

  3. 使用 3.5.2 版的 JNA 和 Platform jar 而不是 4.0.0。

显然,您将上面的目录字符串替换为您自己磁盘上合适的内容。

这些解决方案都不是理想的。

[1] https://github.com/caprica/vlcj/issues/226

关于java - 运行此代码后 vlcj 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21077527/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com