通过servletvideo java查看flv视频 [英] view flv video by servletvideo java

查看:43
本文介绍了通过servletvideo java查看flv视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从webcontent目录中的文件查看jwplayer中的视频时,它会显示并可以播放,但是当我从数据库中读取相同文件并以flv通过servlet不会显示.有人可以帮我吗?

When I try to view a video in the jwplayer from a file in the webcontent directory it shows up and I can play it, but when I read the same file from a database and respond with an flv via servlet it doesn't show up. Can any one help me?

在HTML文件中:

    <script type='text/javascript' src='/ThoughRecord18-8/jwplayer.js'></script>


    <script type='text/javascript'>
  jwplayer('mediaspace').setup({
    'flashplayer': '/ThoughRecord18-8/player.swf',
    'file': '/ThoughRecord18-8/videoss?videoId=1',
    'controlbar': 'bottom',
    'width': '470',
    'height': '320'
  });
</script>

servlet是

String videoId = request.getParameter("videoId");
        if (videoId != null || !videoId.equals("")) {
            VideoDao dao = new VideoDao();
            Video video = dao.getVideo(videoId);
            Blob blob = video.getVideoBlob();
            byte[] buf = new byte[1024];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream in = null;
            int len;
            try {
                len = (int) blob.length();
                byte[] rb = new byte[len];
                InputStream readImg = blob.getBinaryStream();
                int index = readImg.read(rb, 0, len);

...

            response.reset();
            response.setBufferSize(DEFAULT_BUFFER_SIZE);
            response.setContentType("video/x-flv");
            response.setContentLength(rb.length);
             response.setHeader("Content-Disposition", "inline; filename=file.flv");
            byte[] content = new byte[DEFAULT_BUFFER_SIZE];
            BufferedInputStream is = new BufferedInputStream(
                    new ByteArrayInputStream(rb));
            OutputStream os = response.getOutputStream();
            while (is.read(content) != -1) {
                os.write(content);
            }
            is.close();
            os.close();**

推荐答案

这不是Java问题,JW Player仅支持HTTP Psuedo流和RTMP流.它们都是他们自己的协议-您不能只在其中流传输纯内容.请看此页面: http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12534/video-delivery-http-pseudo-streaming ,页面: http ://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12535/video-delivery-rtmp-streaming 以获得有关JW Player如何进行流媒体播放的信息.

This isn't a java issue, JW Player only supports HTTP Psuedo Streaming and RTMP Streaming. They're both their own protocols - you can't just stream the pure content at it. Take a look at this page: http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12534/video-delivery-http-pseudo-streaming, and this page: http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12535/video-delivery-rtmp-streaming for info on how JW Player does streaming.

如果您不希望用户必须等待获取所有内容,则需要使用其中一种流传输机制.如果这不是问题,则可以考虑更改servlet以将文件写入Webcontent目录中的某个位置,然后重定向到该文件或其他内容,但是我不认为写入响应流会像这样技巧.

If you don't want the user to have to wait to get all of the content, you'll need to go with one of those streaming mechanisms. If that's not an issue, you could consider changing your servlet to write the file somewhere in your webcontent directory and then do a redirect to the file or something, but I don't think writing to the response stream like that is going to do the trick.

这篇关于通过servletvideo java查看flv视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆