【发布时间】:2016-01-19 12:26:41
【问题描述】:
我正在为 scala 使用 play framework 2.4.6。我的问题是我的应用程序的视频可以通过 chrome 打开/播放/下载。桌面上的 Safari 下载它。但 iphone/ipad 上的 safari 浏览器无法播放。我希望我的网络应用程序以 iphone/ipad 上的 safari 浏览器的方式呈现视频。
注意: 我为苹果设备正确转换了视频,甚至更多:当我将视频链接嵌入到 HTML 文件并使用 Apache 服务器将其复制到 xampps htdocs 文件夹时,iPhone 上的 safari 可以毫无问题地播放它。 这是我的路线文件内容:
GET / controllers.Application.index
GET /videos/:name controllers.Videos.stream(name:String)
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
Videos.scala 控制器:
class Videos extends Controller{
def stream (name:String)= Action {
//video files stored locally in 'videos' folder in order to use it on production mode also
val file = new java.io.File(Play.application().path()+"/videos/"+name)
import ExecutionContext.Implicits.global
val fileContent: Enumerator[Array[Byte]] = Enumerator.fromFile(file)
Result(
ResponseHeader(200, Map(
CONTENT_LENGTH -> file.length.toString,
CONTENT_RANGE -> s"bytes */${file.length.toString}",
ACCEPT_RANGES -> "bytes",
CONTENT_TYPE -> "video/mp4",
PRAGMA -> "public",
CONTENT_TRANSFER_ENCODING -> "binary",
CONTENT_DISPOSITION -> "attachment"
)),
body = fileContent
)
}
}
我的索引测试页:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>myvideo</title>
</head>
<body>
<video controls="true"
poster="@routes.Assets.versioned("images/myvideo.jpg")" style="width:auto;" title="myvideo">
<source src="@routes.Videos.stream("myvideo.mp4")" type="video/mp4"/>
<source src="@routes.Videos.stream("myvideo.m4v")" type="video/mp4"/>
<source src="@routes.Videos.stream("myvideo.3gp")" type="video/3gp"/>
<source src="@routes.Videos.stream("myvideo.mov")" type="video/mov"/>
</video>
</body>
</html>
即使我在 safari 浏览器地址栏中写“http://mypcipaddress:9000/videos/myvideo.mp4”。它表明播放器无法播放视频: smartphone screenshot
请任何人帮助我。
【问题讨论】:
-
iPhone 上的 Safari 无法播放我的视频,这就是问题
-
您确定视频是 mp4 文件而不是 ogg/webm 文件。我知道 Safari 在解码这些视频格式时可能会遇到问题。
-
我解决了这个问题,方法是在我的控制器中以编程方式复制 VPS 上 Apache 的公共文件夹的视频,然后在我的视图中添加指向该视频的链接,这样视频不是由 Play 呈现,而是由 Apache 本身呈现
标签: iphone scala mobile-safari playframework-2.4