【问题标题】:Chromecast DRM exampleChromecast DRM 示例
【发布时间】:2014-09-11 21:53:46
【问题描述】:

我指的是 Google 给出的这个例子(特别是 sender.js 文件)(https://github.com/googlecast/CastMediaPlayerStreamingDRM/blob/master/sender.js)。我正在尝试播放作为 DRM 的 http://storage.googleapis.com/wvmedia/cenc/tears.mpd 文件,并且我正在传递定义的许可证 URL http://widevine-proxy.appspot.com/proxy在示例中的 sender.js 文件中。

我的发件人是 Android(我正在使用 CastCompanionLibrary)。这就是我在 Android 中发送它的方式:

mCastManager.sendDataMessage("http://playready.directtaps.net/pr/svc/rightsmanager.asmx");
mCastManager.startCastControllerActivity(LocalPlayerActivity.this, media, 0, true);

这是我在自定义接收器中接收许可证 URL 的方式:

messageBus = castReceiverManager.getCastMessageBus(--NAME SPACE--);

messageBus.onMessage = function(event) {

        console.log(event['data']);
        licenseURL = event['data'];
        console.log(licenseURL);

    }

到目前为止,我已调试并将 licenseURL 设置为 Android 发送者发送的许可证 URL。它正在接收器中正确接收 licenseURL。然后在我的 onLoad 方法中,我执行以下操作。

 mediaManager.onLoad = function(event) {

        if(mediaPlayer !== null) {
            mediaPlayer.unload(); // Ensure unload before loading again
        }

        if (event.data['media'] && event.data['media']['contentId']) {
            var url = event.data['media']['contentId'];

            mediaHost = new cast.player.api.Host({
                'mediaElement': mediaElement,
                'url': url
            });

            mediaHost.onError = function (errorCode) {
                console.error('### HOST ERROR - Fatal Error: code = ' + errorCode);

                if (mediaPlayer !== null) {
                    mediaPlayer.unload();
                }
            }

            if(licenseURL){

                console.log("##License URL is not null");
                mediaHost.licenseURL = licenseURL;
            }
            var initialTimeIndexSeconds = event.data['media']['currentTime'] || 0;

            var protocol = null;

            var parser = document.createElement('a');
            parser.href = url;

            var ext = ext = parser.pathname.split('.').pop();
            if (ext === 'm3u8') {
                protocol =  cast.player.api.CreateHlsStreamingProtocol(mediaHost);
            } else if (ext === 'mpd') {
                protocol = cast.player.api.CreateDashStreamingProtocol(mediaHost);
            } else if (ext === 'ism/') {
                protocol = cast.player.api.CreateSmoothStreamingProtocol(mediaHost);
            }
            console.log('### Media Protocol Identified as ' + ext);


            if (protocol === null) {

                mediaManager['onLoadOrig'](event); // Call on the original callback
            } else {

                mediaPlayer = new cast.player.api.Player(mediaHost);
                mediaPlayer.load(protocol, initialTimeIndexSeconds);
            }
        }
    }

但是当我这样做时,我得到了错误:

XMLHttpRequest cannot load http://storage.googleapis.com/wvmedia/cenc/tears.mpd. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://dl.dropboxusercontent.com' is therefore not allowed access.
### HOST ERROR - Fatal Error: code = 3 

我将接收器临时托管在保管箱公用文件夹上。关于我做错了什么有什么想法吗?

【问题讨论】:

    标签: javascript android chromecast


    【解决方案1】:

    托管媒体的服务器未发送所需的 CORS 标头。您需要添加这些,请参阅 document,使用跨域资源共享 (CORS) 部分。

    【讨论】:

    • 媒体是 Google 在该 github 存储库中给出的示例。我没有访问权限?我们应该如何在没有 CORS 标头的情况下运行该示例?
    • 我假设 storage.googleapis.com 在我提到的示例中托管媒体。 (我想要这个特别的,因为我需要媒体和许可证 URL 来测试 DRM)。无论如何,我可以向其中添加 CORS 标头?
    • Google 的 Cloud Storage 允许您轻松地将 CORS 标头添加到您的存储桶中(只要您有权在相关项目上执行此操作)。以下是说明:developers.google.com/storage/docs/cross-origin
    • 感谢您的链接。正如我在原帖中提到的,我使用的是给出的 CastMediaPlayerStreamingDRM 示例。我想用 sender.js 中的第三个 mpd 文件进行测试。由于 CORS 问题,我将视频链接发送为“corsproxy.com/storage.googleapis.com/wvmedia/cenc/tears.mpd”,并且未在接收方的 onLoad 方法中设置任何凭据,但仍设置 licenseURL(在 CastMediaPlayerStreamingDRM 示例中给出)。
    • 它似乎有效(尽管流在 5-10 秒内崩溃)。但是无论是否设置 licenseURL,流似乎都可以工作(5-10 秒)。如果我不设置 licenseURL,它不应该不会在 5-10 秒内流式传输吗?我们应该如何使用 CastMediaPlayerStreamingDRM 示例?
    猜你喜欢
    • 2016-12-28
    • 2019-06-22
    • 2014-10-21
    • 2018-07-11
    • 2017-08-14
    • 2021-05-13
    • 2014-04-15
    • 2014-12-14
    • 2011-12-16
    相关资源
    最近更新 更多