Video.js无法在Safari中运行(代码:4 MEDIA_ERR_SRC_NOT_SUPPORTED)

tin*_*kis 6 javascript safari html5 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 supported."
Run Code Online (Sandbox Code Playgroud)

我见过一个建议改变的Content-Type头的MP4,但由于某种原因,我iframe不会生成head所有代码(仅在Safari;在所有其他浏览器,iframe包含html有两个标签headbody).而且,事实证明,我被阻止将head标签添加到iframe html.我试着把它扔进一个meta标签,但这对错误信息没有影响

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

<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>
Run Code Online (Sandbox Code Playgroud)

我的Web服务器是Apache2.

有关如何启用Content-Type video/mp4(或其他解决此错误的方法)的任何建议将不胜感激.

我也遇到了FirefoxMicrosoft Edge中视频播放/暂停功能的问题.如果您有任何想法,请查看这些问题.

小智 1

我在我的应用程序中遇到了同样的错误。经过几天的研究,我发现 safari 只能运行H264编解码器格式的视频。音频为MP3 、AAC 。

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

供参考: https ://docs.videojs.com/tutorial-troubleshooting.html#problems-when-hosting-media