javascript - 现在如何知道在 SHAKA PLAYER 中传递内容保护回调?

标签 javascript html mpeg-dash media-source shaka

谁能帮我知道现在要传递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

最佳答案

请阅读此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 方法对响应应用相同的过程

关于javascript - 现在如何知道在 SHAKA PLAYER 中传递内容保护回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52835532/

相关文章:

java - Java 服务器的奇怪输出 - 我的网站是否被黑客入侵了?

ios - HTML5 视频 iOS 播放按钮消失

ffmpeg - MXF 到使用 FFMPEG 的破折号转换

ffmpeg - 直播多比特率视频

javascript - 道场:使用 registry.byID 返回 "undefined"

javascript - 根据特定属性的值获取元素的类或 ID 名称

html - 需要根据不同的屏幕尺寸为 DIV 更改 CSS 中的类

javascript - 错误 : Cannot find module 'jade~'

javascript - 我在使用 ES6 的导入和导出功能时遇到问题

javascript - 强制 Firefox 在后退按钮上重新加载页面