如何通过从数据库获取在jsp上显示视频? [英] How can I show the video on jsp by getting from database?

查看:94
本文介绍了如何通过从数据库获取在jsp上显示视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在执行一项功能,以在jsp上显示视频.我将视频保存为 BLOB 格式.以 byte [] 格式获取视频后,我想在jsp上显示视频.我使用了<video>,但视频无法播放.

I currently doing an function which is to display the video on the jsp. I am saving the video in BLOB format. After getting the video in the byte[] format I want to show the video on the jsp. I used the <video> but the video is not able to play.

我该如何实现?有人可以举个小例子吗?

How can I achieve this? Can anyone please suggest with a small example?

在jsp中返回一个URL:

In jsp return an url :

<video id="addVideo" controls autoplay>
    <source src="${videoUrl}" />
</video>

从控制器中,我将Url返回为:

From the controller I return the Url as:

byte[]  v_byte = (getting from the data base)
String videoUrl = new String(org.apache.commons.codec.binary.Base64.encodeBase64(v_byte);
model.addAttribute("videoUrl ",videoUrl );

推荐答案

您可以尝试以下视频/mp4视频代码:

You can try the following code for video/mp4 video:

    byte[]  v_byte = (getting from the data base)
    StringBuilder sb = new StringBuilder();
sb.append("data:video/mp4;base64,");
sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(v_byte, false)));
String videoUrl = sb.toString();
    model.addAttribute("videoUrl",videoUrl );

这篇关于如何通过从数据库获取在jsp上显示视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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