Video.js does not work in Safari (CODE: 4 MEDIA_ERR_SRC_NOT_SUPPORTED)

I am trying to use video.js to prevent fast-forward, but to allow fast-forward, for mp4 video on the Moodle site. It works correctly in Chrome and Opera, but when I try in Safari, I get the following error message:

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."

I saw a proposal to change the Content-Type header to mp4, but for some reason mine iframedoes not generate a tag head(only in Safari, in all other browsers it iframecontains a tag htmlwith headand body). Also, it turns out I'm blocked from adding the tag headto iframe html. I tried to throw it into the tag meta, but this did not affect the error message

The following is the script used to prevent fast forward:

<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>

My web server is Apache2.

Any advice on how to enable video / mp 4 Content-Type (or another way to resolve this error) is welcome.

I'm also having issues with play / pause features for videos in Firefox and Microsoft Edge . Please check out these questions if you have any ideas.

+4
source share

Source: https://habr.com/ru/post/1625221/


All Articles