简体   繁体   English

如何将视频从Play 2 Framework流式传输到HTML5播放器

[英]How to stream a video from Play 2 Framework to HTML5 player

How can i stream a video from a play 2 application to a HTML5 video player? 如何将视频从播放2应用程序流式传输到HTML5视频播放器?

When i use the solutions from play stream doc i can receive the video but the video length is infinity in the video player. 当我使用播放流文档中的解决方案时,我可以接收视频,但视频播放器中的视频长度是无限的。

I adapted this solution . 我改编了这个解决方案

 def stream(id: Long) = Action {
    implicit r =>
      val v = videos.where(_.id === id).single
      val file = new java.io.File(v.filePath)
      import ExecutionContext.Implicits.global
      val fileContent: Enumerator[Array[Byte]] = Enumerator.fromFile(file)

      SimpleResult(
        header = ResponseHeader(200, Map(
          CONTENT_LENGTH -> file.length.toString,
          CONTENT_RANGE -> s"bytes */${file.length.toString}",
          ACCEPT_RANGES -> "bytes",
          CONTENT_TYPE -> v.format,
          PRAGMA -> "public",
          CONTENT_TRANSFER_ENCODING -> "binary",
          CONTENT_DISPOSITION -> "attachment"
        )),
        body = fileContent
      )
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM