首页 > 解决方案 > 带有 DRM url 的 Google cast v3 CAF Receiver 应用程序

问题描述

我正在尝试使用v3 CAF接收器应用程序DRM从我的 IOS 应用程序中投射视频。如果我使用基本v3 CAF接收器应用程序(默认接收器)它工作正常,但是当我使用DRM url (dash/.mpd and licenseUrl )它时会抛出错误错误

[ 20.844s] [错误] [INFO] {"type":"LOAD_CANCELLED","re​​questId":0}

请参阅下面的代码。

const playerManager = context.getPlayerManager();
const playbackConfig = new cast.framework.PlaybackConfig();
/** Debug Logger **/
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();

var manifestUri = 'https://example.domain.video/prod/drm/1/7e942940-d705-4417-b552-796e8fd25460/Media_1_20_d2aaec7102dc42c09dd54e4f00cbea412019062801270383196000/dash/manifest.mpd';
var licenseServer = 'https://wv.example.domain.com/hms/wv/rights/?ExpressPlayToken=BQALuGDeKZcAJDE2YzAwYTRkLTYwZWYtNGJiZC1hZmEzLTdhMmZhYTY2NzM5OQAAAHCZzHVjRyfs3AEgxFuwPvZsrqMndjiBPzLQ5_VUx6rJOEDD5noQmXJoVP-Va1gQzxfp9eHux15_pEr6g0RxXNZIjlsN6b7SIfpHPyS9iuPQqgvEgq5I_tV9k1lhQvKuqgpBN0Z5BtxCLwHc8xrnLbuUK6fiThcLMR4He_x38reAsumjFYg';

// setting manually licenseUrl from here 
playbackConfig.licenseUrl = licenseServer;

playbackConfig.manifestRequestHandler = requestInfo => {
  requestInfo.withCredentials = true;
};

playbackConfig.licenseRequestHandler = requestInfo => {
  requestInfo.withCredentials = true;
  requestInfo.headers = {
    // 'Content-type':'application/dash+xml', // trying this also
    'Content-type':'application/octet-stream'
    }
 playbackConfig.licenseUrl = requestInfo.media.customData.licenseUrl;
 return playbackConfig;
};

// MessageInterceptor
playerManager.setMessageInterceptor(
  cast.framework.messages.MessageType.LOAD,
  request => {
    const error = new cast.framework.messages.ErrorData(cast.framework.messages.ErrorType.LOAD_CANCELLED);
    castDebugLogger.info('Error', error);
    if (!request.media) {
      error.reason = cast.framework.messages.ErrorReason.INVALID_PARAM;
      castDebugLogger.info('reason', error.reason);
      return error;
    }
    if (request.media && request.media.entity) {
      request.media.contentId = request.media.entity;
    }

    return new Promise((resolve, reject) => {
      if (!request.media) {
        castDebugLogger.error('MyAPP.LOG', 'Content not found');
        reject();
      } else {

        // I have passed manually data (license Url and content Id etc.) from here for testing purpose
        const item = new cast.framework.messages.QueueItem();
        item.media = new cast.framework.messages.MediaInformation();
        item.media.contentId = manifestUri;
        item.media.streamType = cast.framework.messages.StreamType.BUFFERED;

// Trying all options of contentType

        item.media.contentType = "application/octet-stream";
        //request.media.contentType = 'application/x-mpegurl'; 
        //item.media.contentType = "video/mp4";
        //request.media.contentType = 'video/mp4';
        //request.media.contentType = 'application/dash+xml';
        item.media.metadata = new cast.framework.messages.MovieMediaMetadata();
        item.media.metadata.title = "Example title";
        item.media.metadata.subtitle = "Example subtitle ";
        item.media.metadata.images = [new cast.framework.messages.Image("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg")];
        request.media = item.media;
        playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;

        resolve(request);
      }
    });
  });

// start 
context.start({
  playbackConfig: playbackConfig,
  touchScreenOptimizedApp: true
});

LA_URL并且.mpd url与另一位在线 shaka 播放器合作良好。

标签: javascriptgoogle-castdrmreceivercaf

解决方案


当为编码的破折号流发出加载请求时,是否将网络请求发送给许可人,您是否检查了远程 Web 检查器?这很可能有助于找出问题所在。

可能您必须向您的 licenseRequestHandler 添加一些智能才能添加某种令牌。或者可能存在 CORS 问题。

注意:在你将一些代码发布到 stackoverflow 之前,清理一下它可能是明智的:删除死代码,删除令人困惑的注释代码,提供适当的缩进。您正在浪费每个人阅读您的代码并试图处理您与世界共享的内容的大脑周期!


推荐阅读