开发者

view flv video by servletvideo java

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?

In Html file :

    <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>

and the servlet is 开发者_StackOverflow

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();**


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜