现在如何知道在 SHAKA PLAYER 中传递 ContentProtectionCallback?

Posted

技术标签:

【中文标题】现在如何知道在 SHAKA PLAYER 中传递 ContentProtectionCallback?【英文标题】:How to know now to pass ContentProtectionCallback in SHAKA PLAYER? 【发布时间】:2018-10-16 12:31:04 【问题描述】:

谁能帮我知道现在通过ContentProtectionCallback,以便我可以在shaka播放器中处理drm许可证网址的preProcessor

[http://v1-6-2.shaka-player-demo.appspot.com/docs/tutorial-network.html][1]

var manifestUri =
    '<mpd url>';

function initApp() 
    // 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()) 
        // Everything looks good!
        initPlayer();
     else 
        // This browser does not have the minimum set of APIs we need.
        console.error('Browser not supported!');
    


function initPlayer() 
    // Create a Player instance.
    var video = document.getElementById('video');

    var player = new shaka.Player(video);
    player.configure(
        drm: 
            servers: 
                'com.widevine.alpha': '<server url>',
            
        
    );

    // Attach player to the window to make it easy to access in the JS console.
    window.player = player;

    // Listen for error events.
    player.addEventListener('error', onErrorEvent);

    // Try to load a manifest.
    // This is an asynchronous process.
    player.load(manifestUri).then(function () 
        // This runs if the asynchronous load is successful.
        console.log('The video has now been loaded!');
    ).catch(onError);  // onError is executed if the asynchronous load fails.


function onErrorEvent(event) 
    // Extract the shaka.util.Error object from the event.
    onError(event.detail);


function onError(error) 
    // Log the error.
    console.error('Error code', error.code, 'object', error);


document.addEventListener('DOMContentLoaded', initApp);

  [1]: http://v1-6-2.shaka-player-demo.appspot.com/docs/tutorial-network.html

【问题讨论】:

【参考方案1】:

请阅读此tutorial。在此页面中,解释了如何在请求之前或之后处理许可证。我假设 ContentProtectionCallback 是一个处理程序,用于在向服务器发出许可证请求之前对其进行操作。对于这种情况:

  player.getNetworkingEngine().registerRequestFilter(function(type, request) 
    // Manipulate request before is sent.
    if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) 
      const body = request.body;
      // Do something with the body. Then, assign it back.
      request.body = manipulateBody(body)
    
  );

您也可以使用registerResponseFilter 方法对响应应用相同的过程

【讨论】:

以上是关于现在如何知道在 SHAKA PLAYER 中传递 ContentProtectionCallback?的主要内容,如果未能解决你的问题,请参考以下文章

在 Shaka Player 中更改字幕的文本大小

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

在 Chrome 上使用 Shaka Player 播放 HLS m3u8

如何正确向 Shaka 播放器提供 MPEG-DASH 清单?

shaka configure 选择你想玩的表示和适应集

保存到离线而不使用 shaka 播放器创建播放器对象