javascript - VideoJS 播放器无法在 iPad 上使用 AngularJS 播放

标签 javascript html ipad angularjs video

我们最近从直接的 PHP(Laravel) 应用程序切换到 AngularJS 应用程序。我在 MP4 文件的两个实例中都使用了 VideoJS。

PHP 版本有效,现在 AngularJS 版本无效。 HTML5 给我一个错误代码 4 MEDIA_ERR_SRC_NOT_SUPPORTED。

这不是编码问题,因为我可以直接在 iPad 上的 Chrome 和 Safari 中播放该文件,并且它以前基于 PHP 时有效。

我相信这是因为 javascript 在通过指令加载视频后动态加载视频。

这在桌面上工作正常,iPad/iPhone 是唯一有这个问题的。

如何让这个东西播放?

HTML

<video
    ui-if='upload.filename'
    class="video-js vjs-default-skin"
    ng-src='{{ main.videoUrl }}{{ upload.filename }}'
    height='400'
    width='100%'
    poster='/image/resize/{{ upload.image }}/400/400'
    videojs
    controls></video>

VideoJS 指令

directives.directive('videojs', [function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            attrs.type = attrs.type || "video/mp4";
            attrs.id = attrs.id || "videojs" + Math.floor(Math.random() * 100);
            attrs.setup = attrs.setup || {};
            var setup = {
                'techOrder': ['html5', 'flash'],
                'controls': true,
                'preload': 'auto',
                'autoplay': false,
                'height': 400,
                'width': "100%",
                'poster': '',
            };

            setup = angular.extend(setup, attrs.setup);
            l(setup)
            element.attr('id', attrs.id);

            var player = videojs(attrs.id, setup, function() {
                this.src({
                    type: attrs.type,
                    src: attrs.src
                });
            });
        }
    };
}]);

更新1

Videogular 是一个出色的解决方案 https://github.com/2fdevs/videogular

最佳答案

媒体元素

http://mediaelementjs.com/


HTML

<video
    src='{{ main.videoUrl }}{{ upload.filename }}'
    height='400'
    width='100%'
    preload='auto'
    poster='/image/resize/{{ upload.image }}/400/400'
    mediaelement>
</video>

AngularJS 指令

directives.directive('mediaelement', function($parse) {
    return {
        restrict: 'A',
        link: function(scope, element, attrs, controller) {
            attrs.$observe('src', function() {
                element.mediaelementplayer();
            });
        }
    }
});

关于javascript - VideoJS 播放器无法在 iPad 上使用 AngularJS 播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19041168/

相关文章:

javascript - 如何根据所选的选择选项动态更改输入值属性?

javascript - 在类中的任何元素上更改元素 ID onmouseover/onmouseout

ios - 使用 Xcode 构建 IPA 文件

iphone - 使用ARC的最低要求

javascript - Nuxt.js 和 Vue-i18next : Error: Cannot resolve "vue-i18next"

javascript - 如何在使用 jQuery 关闭下拉菜单时触发事件?

html - 如何在动态大小的绝对 div 中包含 "overflow: auto;"滚动条的宽度?

javascript - 不同 '&lt;script&gt;' 标签中的相同变量不会发生冲突吗?

javascript - 通过 jQuery.get() 读取 markdown 文件

ipad - 更改 iOS8 中的操作表弹出箭头