当前位置: 首页 > 知识库问答 >
问题:

在AngularJS指令中包装shaka-player不工作(this.target.addEventListener不是一个函数)

乌翰学
2023-03-14

我想在AngularJS指令中包装shaka-player示例。

该示例播放器本身运行良好,可以播放Akamai CDN上托管的大羚羊兔的MPEG-DASH版本。

但是,当试图在AngularJS指令中使用shaka-player时,player.load(url)失败,this.target.addEventListener不是一个函数

它还报告TypeError:无法读取null的属性“textTracks”。(根据浏览器的不同,这些错误的顺序有时会颠倒)

我不知道为什么它可以独立运行,但不能在AngularJS指令中运行。。。

该指令的超文本标记语言片段如下所示:

<tq-video-player
  tqsrc="source"
  poster="somePicture"
  id="my-video"
  width="640"
  height="360">
</tq-video-player>

指令代码本身几乎是示例代码的复制粘贴。(我还尝试了几种变体来处理promise,而不是async函数。它们都有相同的错误。

var TqUiLib = TqUiLib || angular.module('tqUiLib', []);

TqUiLib.directive("tqVideoPlayer", 
function($timeout, $parse)
{ 
    var directive =
    {
        restrict: 'E',
        template: '<video controls width="640"></video>',
        scope: 
        {
            tqsrc:  '=', 
            poster: '=',
            width:  '=', 
            height: '='
        },
    
        link: function(scope, element, attrs)
        {
            console.log("tqVideoPlayer link. nodename", element[0].nodeName, element);
        
            // Install built-in polyfills to patch browser incompatibilities.
            shaka.polyfill.installAll();

            // Check to see if the browser supports the basic APIs Shaka needs.
            if (!shaka.Player.isBrowserSupported())
            {
                // This browser does not have the minimum set of APIs we need.
                console.error('Browser not supported!');
            
                let errDiv = angular.element("<p class='tqVidPlayerErrDiv'>Video player not supported in this browser</p>");
                element.append(errDiv);
            
                throw new Error('Video player not supported in this browser');
            }
    
            let videoTag = angular.element(element).find("video");
            shaka.log.setLevel(shaka.log.DEBUG);
        
            var player = new shaka.Player(videoTag);
            player.addEventListener('error', errorEventHandler);
        
            let srcUrl = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
            console.log("Loading...", srcUrl);
        
            loadPlayer(srcUrl);
        
            async function loadPlayer(srcUrl)
            {
                console.log("loadPlayer()");
                try
                {
                    await player.load(srcUrl);
                    console.log("Video is loaded");                 
                }
                catch (e)
                {
                    console.log("player.load failed: ", e);
                }
            };
        
            // Error event handler
            function errorEventHandler(evt)
            {
                console.log("Error Event ", evt.detail);    
            };
        
            // Destructor.  Unbind non-angular listeners
            scope.$on('$destroy', function()
            {
                player.removeEventListener('error');
            });
        }
    };

    return directive;
});

错误日志

[Log] tqVideoPlayer link. nodename – "TQ-VIDEO-PLAYER" – k [<tq-video-player id="my-video">]
[Log] mathRound.install (shaka-player.compiled.debug.js, line 1670)
[Log] MediaSource.install (shaka-player.compiled.debug.js, line 1675)
[Info] Patching Safari 11 & 12 MSE bugs. (shaka-player.compiled.debug.js, line 1675)
[Info] Using Apple-prefixed EME (shaka-player.compiled.debug.js, line 1685)
[Log] PiPWebkit.install (shaka-player.compiled.debug.js, line 1777)
[Log] VideoPlayPromise.install (shaka-player.compiled.debug.js, line 1783)
[Info] Using native VTTCue. (shaka-player.compiled.debug.js, line 1785)
[Log] MediaCapabilities: install (shaka-player.compiled.debug.js, line 1671)
[Debug] EmeEncryptionSchemePolyfill: Waiting to detect encryptionScheme support. (shaka-player.compiled.debug.js, line 1882)
[Debug] McEncryptionSchemePolyfill: Waiting to detect encryptionScheme support. (shaka-player.compiled.debug.js, line 1888)
[Log] Loading... – "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd" (tqVideoPlayer.js, line 61)
[Log] loadPlayer() (tqVideoPlayer.js, line 67)

[Warning] Factories requiring new has been deprecated and will be removed in v4.0 . We are currently at version v3.1 . Additional information: Factories should be plain functions (shaka-player.compiled.debug.js, line 181)

[Log] player.load failed:  – TypeError: null is not an object (evaluating 'a.textTracks') — simple_text_displayer.js:37 (tqVideoPlayer.js, line 75)
TypeError: null is not an object (evaluating 'a.textTracks') — simple_text_displayer.js:37SimpleTextDisplayer — simple_text_displayer.js:37textDisplayFactory — player.js:4512callFactory — functional.js:110(anonymous function) — player.js:1494nextStep_ — generator_engine]:795next_ — generator_engine]:699next — generator_engine]:833(anonymous function) — execute_async_generator]:72initializePromisePromiseasyncExecutePromiseGenerator — execute_async_generator]:59asyncExecutePromiseGeneratorProgram — execute_async_generator]:117onInitializeMediaSourceEngine_ — player.js:1469(anonymous function) — player.js:563enterNode — player.js:602(anonymous function) — walker.js:342nextStep_ — generator_engine]:795next_ — generator_engine]:699next — generator_engine]:833(anonymous function) — execute_async_generator]:72initializePromisePromiseasyncExecutePromiseGenerator — execute_async_generator]:59asyncExecutePromiseGeneratorProgram — execute_async_generator]:117takeNextStep_ — walker.js:321doOneThing_ — walker.js:228(anonymous function) — walker.js:209nextStep_ — generator_engine]:795next_ — generator_engine]:699next — generator_engine]:833b — execute_async_generator]:52promiseReactionJob

[Error] Unhandled Promise Rejection: TypeError: this.target.addEventListener is not a function. (In 'this.target.addEventListener(b,c,this.options)', 'this.target.addEventListener' is undefined)
    Binding_ (shaka-player.compiled.debug.js:367:297)
    listen (shaka-player.compiled.debug.js:364:698)
    onAttach_ (shaka-player.compiled.debug.js:845:273)
    (anonymous function) (shaka-player.compiled.debug.js:824:356)
    enterNode (shaka-player.compiled.debug.js:826:404)
    (anonymous function) (shaka-player.compiled.debug.js:764:496)
    nextStep_ (shaka-player.compiled.debug.js:37:114)
    next_ (shaka-player.compiled.debug.js:33:244)
    next (shaka-player.compiled.debug.js:38)
    (anonymous function) (shaka-player.compiled.debug.js:39:235)
    initializePromise
    Promise
    asyncExecutePromiseGenerator (shaka-player.compiled.debug.js:39:135)
    asyncExecutePromiseGeneratorProgram (shaka-player.compiled.debug.js:39:448)
    takeNextStep_ (shaka-player.compiled.debug.js:764:123)
    doOneThing_ (shaka-player.compiled.debug.js:761:151)
    (anonymous function) (shaka-player.compiled.debug.js:760:193)
    nextStep_ (shaka-player.compiled.debug.js:37:114)
    next_ (shaka-player.compiled.debug.js:33:244)
    next (shaka-player.compiled.debug.js:38)
    b (shaka-player.compiled.debug.js:39)
    promiseReactionJob

MacOS 10.12上的Chrome、Safari和Firefox也出现同样的故障。

AngularJS 1.6.9沙卡球员3.1.0

共有1个答案

裴星洲
2023-03-14

有角度。元素函数返回jQuery元素,jQuery find函数也是如此。因此,videoTag变量引用了jQuery对象。

另一方面,shaka。播放器构造函数需要一个HTMLMediaElement。所以传递videoTag[0]应该可以。

 类似资料:
  • Shaka Player 是一个 JavaScript 库,它实现了 DASH 客户端的功能。它的播放功能基于 HTML5 video、MediaSource Extensions,和 Encrypted Media Extensions 。 一般的 DASH 客户端功能很难实现,并且 DASH 标准不总是与 DASH 客户端建立的新浏览器 API 接口对齐,我们的目标是减少之间的摩擦,使之在没有

  • 你好,我是这个reactjs的新手,我目前在Egghead尝试了一些课程,当我尝试使用map从数据数组创建React组件时,我遇到了一些错误,我不理解,因为我已经有了相同的代码 当我尝试过滤它时,会出现这个错误,就像我不能用键名调用数组项一样,该数组是从api获取的

  • 从git在Angular 4 cli中创建指令 /Angular/projectName$ng生成指令DirectiveName 应该管用 [注意:DirectiveName是唯一的,与组件名称或模块名称不匹配] 但我犯了一个错误 错误:多个模块匹配。使用跳过导入选项跳过将组件导入最近的模块。多个模块匹配。使用跳过导入选项跳过将组件导入最近的模块。

  • 我有两个include文件(fill_boxMain.php和fill_boxBottom.php)。这两个都包含在my index.php中,用于按顺序填充两个div的内容。 例如: 第一个(fill_boxMain.php)工作正常。无论我如何安排或更改代码,第二个都会失败,并且会出现相同的可重复错误。i、 e.mysqli_查询($dbc,$q)失败。 选择查询在phpMyAdmin中运行良

  • 我正在尝试在我全新的项目中使用TailWind,每个应用程序都很好,但是@应用程序甚至不能编译。 以下是错误消息: 我的顺风。css文件: 我已经安装了POSTSS cli并使用POSTSS。配置。就像这样: 但这些都不管用。

  • 问题内容: 我正在尝试制定一条会影响元素宽度/高度的指令。通过示例,我已经看到可以通过引用适当的函数来获取/设置宽度/高度。例如,在指令的链接功能中,我尝试执行以下操作: 但是,在我的代码中,我得到“错误:element.height不是函数”。 我是否缺少对angular.js模块/库的引用,或者文档不是最新的? 问题答案: 如果您不包括jQuery angular替代品,则使用它自己的较小的库