Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Video.js在Safari中不工作(代码:4媒体错误SRC不受支持)_Javascript_Html_Safari_Moodle_Video.js - Fatal编程技术网

Javascript Video.js在Safari中不工作(代码:4媒体错误SRC不受支持)

Javascript Video.js在Safari中不工作(代码:4媒体错误SRC不受支持),javascript,html,safari,moodle,video.js,Javascript,Html,Safari,Moodle,Video.js,我试图使用video.js来阻止Moodle站点上mp4视频的快进,但允许倒带。它在Chrome和Opera中正常工作,但在Safari中尝试时,会收到以下错误消息: VIDEOJS: (4) "ERROR:" "(CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED)" "The media could not be loaded, either because the server or network failed or because the format is not

我试图使用video.js来阻止Moodle站点上mp4视频的快进,但允许倒带。它在Chrome和Opera中正常工作,但在Safari中尝试时,会收到以下错误消息:

VIDEOJS: (4)
"ERROR:"
"(CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED)"
"The media could not be loaded, either because the server or network failed or because the format is not supported."
我看到了一个将内容类型头更改为mp4的方法,但是由于某种原因,我的
iframe
根本不生成
head
标记(仅在Safari中;在所有其他浏览器中,
iframe
包含一个
html
标记,该标记同时包含
)。而且,我被阻止在
iframe html
中预先添加
head
标记。我尝试将其放入
元标记中,但这对错误消息没有影响

以下是我用来防止快进的脚本:

<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link href="https://vjs.zencdn.net/5.0/video-js.min.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/5.0/video.min.js"></script>

<script>
window.onload = function() {
  if ($('iframe').length > 0) {

    $('iframe').ready(function() {
      if ($('iframe').contents().find('head').length === 0) {
        console.log("*********************");
        console.log("In the if!");
        $('iframe').contents().find('html').prepend("<head><meta name='viewport' content='width=device-width' content-type='video/mp4'></head>");
        $('iframe').contents().find('html').attr("content-type", "video/mp4");
        console.log($('iframe').contents().find('head'));
        console.log($('iframe').contents().find('html'));
      }

      var videoPlayer = $('iframe').contents().find('video')[0];

      var cssLink = document.createElement("link")
      cssLink.href = "https://vjs.zencdn.net/5.0/video-js.min.css";
      cssLink.rel = "stylesheet";
      cssLink.type = "text/css";

      $('iframe').contents().find('head').append(cssLink);

      videojs(videoPlayer, {}, function() {
        var vjsPlayer = this;
        $('iframe').contents().find('video').prop('controls', 'true');
        $('iframe').contents().find('div .vjs-big-play-button').html('');
        $('iframe').contents().find('div .vjs-control-bar').html('');
        $('iframe').contents().find('div .vjs-caption-settings').html('');

        var currentTime = 0;

        vjsPlayer.on("seeking", function(event) {
          if (currentTime < vjsPlayer.currentTime()) {
            vjsPlayer.currentTime(currentTime);
          }
        });

        vjsPlayer.on("seeked", function(event) {
          if (currentTime < vjsPlayer.currentTime()) {
            vjsPlayer.currentTime(currentTime);
          }
        });

        setInterval(function() {
          if (!vjsPlayer.paused()) {
            currentTime = vjsPlayer.currentTime();
          }
        }, 1000);
      });
    });
  }
}

</script>

window.onload=函数(){
如果($('iframe')。长度>0){
$('iframe').ready(函数(){
if($('iframe').contents().find('head').length==0){
console.log(“*************************”);
log(“在if中!”);
$('iframe').contents().find('html').prepend(“”);
$('iframe').contents().find('html').attr(“内容类型”,“视频/mp4”);
log($('iframe').contents().find('head'));
log($('iframe').contents().find('html'));
}
var videoPlayer=$('iframe').contents().find('video')[0];
var cssLink=document.createElement(“链接”)
cssLink.href=”https://vjs.zencdn.net/5.0/video-js.min.css";
cssLink.rel=“样式表”;
cssLink.type=“text/css”;
$('iframe').contents().find('head').append(cssLink);
videojs(videoPlayer,{},函数(){
var vjsPlayer=this;
$('iframe').contents().find('video').prop('controls','true');
$('iframe').contents().find('div.vjs大播放按钮').html(“”);
$('iframe').contents().find('div.vjs控制栏').html(“”);
$('iframe').contents().find('div.vjs caption settings').html(“”);
var currentTime=0;
vjsPlayer.on(“搜索”),函数(事件){
if(currentTime
我的网络服务器是Apache2

对于如何启用内容类型video/mp4(或解决此错误的其他方法)的任何建议,我们将不胜感激


我在和中的视频播放/暂停功能方面也有问题。如果您有任何想法,请查看这些问题。

我在申请中遇到的相同错误。经过几天的研究,我发现 safari只能为视频运行H264编解码器格式。以及音频的MP3、AAC

检查视频格式和服务器响应


仅供参考:

(即使经过很长时间,也可能对其他人有所帮助)如果来自服务器的标题与文件扩展名不同,则浏览器在呈现时可能会出现问题。例如,如果要从渲染文件http://.../some_name.mp4 并且“内容类型”报头是“视频/mpeg”而不是“视频/mp4”,那么该视频可能被认为已损坏。(在IE11上发生在我身上)