首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java http流视频与VLCJ -您的输入无法打开

Java http流视频与VLCJ -您的输入无法打开
EN

Stack Overflow用户
提问于 2017-10-08 19:53:47
回答 1查看 1.1K关注 0票数 1

我试图用VLCJ库用Java编写一个http视频流应用程序,但我遇到了“您的输入无法打开”的问题。

OS: Windows10 x64

我的源代码:https://github.com/caprica/vlcj/blob/master/src/test/java/uk/co/caprica/vlcj/test/streaming/StreamHttp.java

代码语言:javascript
复制
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.runtime.x.LibXUtil;
import java.io.File;

/**
 * An example of how to stream a media file over HTTP.
 * <p>
 * The client specifies an MRL of <code>http://127.0.0.1:5555</code>
 */
public class VideoStream extends  VlcjTest{

    public static void main(String[] args) throws Exception {
        System.setProperty("VLC_PLUGIN_PATH", "D:\\Program Files\\VideoLAN\\VLC\\plugins");
        File vlcInstallPath = new File("D:\\Program Files\\VideoLAN\\VLC");
        NativeLibrary.addSearchPath(
                RuntimeUtil.getLibVlcLibraryName(), vlcInstallPath.getAbsolutePath());
        Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
        LibXUtil.initialise();
        String media = "D://demo.mp4";
        String options = formatHttpStream("127.0.0.1", 5555);
        System.out.println("Streaming '" + media + "' to '" + options + "'");

        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
        HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
        mediaPlayer.playMedia(media, options);

        // Don't exit
        Thread.currentThread().join();
    }

    private static String formatHttpStream(String serverAddress, int serverPort) {
        StringBuilder sb = new StringBuilder(60);
        sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,");
        sb.append("dst=");
        sb.append(serverAddress);
        sb.append(':');
        sb.append(serverPort);
        sb.append("}}");
        return sb.toString();
    }
}

和结果:

代码语言:javascript
复制
[000000001a948be0] access_output_http access out: Consider passing --http-host=IP on the command line instead.
[000000001aa2def0] core input error: open of `D://demo.mp4' failed
[000000001aa2def0] core input error: Your input can't be opened
[000000001aa2def0] core input error: VLC is unable to open the MRL 'D://demo.mp4'. Check the log for details. 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-08 20:43:56

问题在

代码语言:javascript
复制
String media = "D://demo.mp4";

正如评论所暗示的那样。对于//,在D:之后,它将被视为协议名。

下列变体之一应适用于您:

代码语言:javascript
复制
String media = "D:/demo.mp4";

只要playMedia支持本地文件路径。或

代码语言:javascript
复制
String media = new File("D:/demo.mp4").toURI().toURL();

如果它需要一个URL字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46635412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档