视频无法完整地获取,

时间:2017-12-28 10:49:20

标签: spring mongodb spring-mvc html5-video

我想从mongodb获取视频,而不是播放该视频到视频大小,但它只播放了一秒钟,我给了maxUploadSize是20mb,maxInMemorySize也是20mb,但在jsp页面上,它只获取1mb视频视频大小超过1mb。 我无法做什么,视频应该根据视频大小播放

这是控制器

@RequestMapping(value = "/welcome-video-controller/{videoObj}", produces = "video/webm")
@ResponseBody
public ResponseEntity<byte[]> getVideoForLoginPage(@PathVariable String videoObj, HttpServletResponse response)
        throws IOException {

    LOG.info("Entry :: getVideoForPost");
    BufferedImage bufferedVideoForPost = null;
    URL resourcePath = null;
    byte[] videoArray = null;
    ResponseEntity<byte[]> result = null;
    LOG.info("videoObj-->" + videoObj);
    File videoFromMongo = new File(VIDEO_FROM_PATH + videoObj);
    GridFSDBFile videoFile = MongoUtility.getVideoFileFromMongo(videoObj);
    videoFile.writeTo(videoFromMongo);
    bufferedVideoForPost = ImageIO.read(videoFromMongo);
    videoFile.getInputStream();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentLength((int) videoFile.getLength());
    videoArray = new byte[(int) videoFile.getLength()];
    result = new ResponseEntity<byte[]>(videoArray, headers, HttpStatus.OK);
    videoFile.getInputStream().read(videoArray);
    LOG.info("videoArray-->" + videoArray);
    LOG.info("videoArray size-->" + videoArray.length);
    return result;
}

这是html codding

<c:set value="${videoPostDetail.videoNames}" var="videoObj" />
<c:if test="${videoObj ne ''}">
    <video width="96%" height="220" controls id="sideVideo">
          <source src='/SocialNetworkingApp/welcome-video-controller/${videoObj}.do' type='video/webm'>

    </video>
</c:if>

它应该播放完整的视频,我尝试了很多,但没有任何工作,请告诉我们有什么问题,

1 个答案:

答案 0 :(得分:0)

我得到了解决方案,实际问题是块大小,我设置文件的块大小,默认情况下chunkSize小于1 mb, 现在我将这一行添加到代码gfsFile.setChunkSize(uploadVideoFile.length());并且工作正常。

    public static void saveVideoIntoMongo(File uploadVideoFile, String videoFilePath, String newVideoFileName)
        throws IOException {

    LOG.info("Entry :: saveVideoIntoMongo");
    LOG.info("videoFilePath-->" + videoFilePath);
    LOG.info("newVideoFileName-->" + newVideoFileName);
    LOG.info("uploadVideoFile-->" + uploadVideoFile);

    DB db = getMongoDBInstance("videoDb");// later on take it from the properties file instead of hardcoding
    GridFS gfsPhoto = getGridFSForFiles(db, "video");

    if (!("").equals(newVideoFileName)) {
        GridFSInputFile gfsFile = gfsPhoto.createFile(uploadVideoFile);
        gfsFile.setChunkSize(uploadVideoFile.length());//setting chunkSize
        gfsFile.setFilename(newVideoFileName);
        gfsFile.save();

    }

    LOG.info("Exit :: saveVideoIntoMongo");
}