Chromecast v3接收器应用程序不起作用

问题描述 投票:1回答:1

我运行了示例自定义接收器。我正在使用ngrok运行它,但在控制台中看到它未连接到Web套接字。感谢您的帮助:这是我的接收方代码和屏幕截图

const context = cast.framework.CastReceiverContext.getInstance();
const playerManager = context.getPlayerManager();


const playbackConfig = new cast.framework.PlaybackConfig();
// Customize the license url for playback
playbackConfig.licenseUrl = 'https://wv-keyos.licensekeyserver.com/';
playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
playbackConfig.licenseRequestHandler = requestInfo => {
  requestInfo.withCredentials = true;
  requestInfo.headers = {
    'customdata': '<custom data>'
  };
};


// Update playback config licenseUrl according to provided value in load request.
context.getPlayerManager().setMediaPlaybackInfoHandler((loadRequest, playbackConfig) => {
  if (loadRequest.media.customData && loadRequest.media.customData.licenseUrl) {
    playbackConfig.licenseUrl = loadRequest.media.customData.licenseUrl;
  }
  return playbackConfig;
});


function makeRequest (method, url) {
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.open(method, url);
    xhr.onload = function () {
      if (this.status >= 200 && this.status < 300) {
        resolve(JSON.parse(xhr.response));
      } else {
        reject({
          status: this.status,
          statusText: xhr.statusText
        });
      }
    };
    xhr.onerror = function () {
      reject({
        status: this.status,
        statusText: xhr.statusText
      });
    };
    xhr.send();
  });
}

playerManager.setMessageInterceptor(
  cast.framework.messages.MessageType.LOAD,
  request => {
    castDebugLogger.info('MyAPP.LOG', 'Intercepting LOAD request');

    if (request.media && request.media.entity) {
      request.media.contentId = request.media.entity;
    }

    return new Promise((resolve, reject) => {

      if(request.media.contentType == 'video/mp4') {
        return resolve(request);
      }

      // Fetch content repository by requested contentId
      makeRequest('GET', 'https://tse-summit.firebaseio.com/content.json?orderBy=%22$key%22&equalTo=%22'+ request.media.contentId + '%22')
        .then(function (data) {
          var item = data[request.media.contentId];
          if(!item) {
            // Content could not be found in repository
            castDebugLogger.error('MyAPP.LOG', 'Content not found');
            reject();
          } else {
            // Adjusting request to make requested content playable
            request.media.contentId = item.stream.hls;
            request.media.contentType = 'application/x-mpegurl';
            castDebugLogger.warn('MyAPP.LOG', 'Playable URL:', request.media.contentId);

            // Add metadata
            var metadata = new cast.framework.messages.MovieMediaMetadata();
            metadata.metadataType = cast.framework.messages.MetadataType.MOVIE;
            metadata.title = item.title;
            metadata.subtitle = item.author;

            request.media.metadata = metadata;
            resolve(request);
          }
      });
    });
  });

/** Debug Logger **/
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();

// Enable debug logger and show a warning on receiver
// NOTE: make sure it is disabled on production
castDebugLogger.setEnabled(true);

playerManager.addEventListener(
  cast.framework.events.category.CORE,
  event => {
      castDebugLogger.info('ANALYTICS', 'CORE EVENT:', event);
});

// Set verbosity level for custom tags
castDebugLogger.loggerLevelByTags = {
  'MyAPP.LOG': cast.framework.LoggerLevel.WARNING,
  'ANALYTICS': cast.framework.LoggerLevel.INFO,
};

/** Optimizing for smart displays **/
const playerData = new cast.framework.ui.PlayerData();
const playerDataBinder = new cast.framework.ui.PlayerDataBinder(playerData);
const touchControls = cast.framework.ui.Controls.getInstance();

let browseItems = getBrwoseItems();

function getBrwoseItems() {
  let data = '"video": { \
    "author": "The Blender Project", \
    "description": "Grumpy Bunny is grumpy", \
    "poster": "https://storage.googleapis.com/tse-summit.appspot.com/bbb/poster.png", \
    "prog": "https://storage.googleapis.com/tse-summit.appspot.com/bbb/bbb-prog.mp4", \
    "stream": { \
      "dash": "https://d8dbsji255dut.cloudfront.net/drm-test/4K-Gaming-Sample.mpd", \
      "hls": "https://d8dbsji255dut.cloudfront.net/drm-test/4K-Gaming-Sample.m3u8" \
    }, \
    "title": "Big Buck Bunny" \
  }';


  let browseItems = [];

  for (let key in data) {
    let item = new cast.framework.ui.BrowseItem();
    item.entity = key;
    item.title = data[key].title;
    item.subtitle = data[key].description;
    item.image = new cast.framework.messages.Image(data[key].poster);
    item.imageType = cast.framework.ui.BrowseImageType.MOVIE;
    browseItems.push(item);
  }
  return browseItems;
}

let browseContent = new cast.framework.ui.BrowseContent();
browseContent.title = 'Up Next';
browseContent.items = browseItems;
browseContent.targetAspectRatio =
  cast.framework.ui.BrowseImageAspectRatio.LANDSCAPE_16_TO_9;

playerDataBinder.addEventListener(
  cast.framework.ui.PlayerDataEventType.MEDIA_CHANGED,
  (e) => {
    if (!e.value) return;

    // Clear default buttons and re-assign
    touchControls.clearDefaultSlotAssignments();
    touchControls.assignButton(
      cast.framework.ui.ControlsSlot.SLOT_1,
      cast.framework.ui.ControlsButton.SEEK_BACKWARD_30
    );

    // Media browse
    touchControls.setBrowseContent(browseContent);
  });

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

context.start({playbackConfig: playbackConfig});


enter image description here

我已经注册了Google Cast SDK开发者控制台,并创建了未发布的应用程序,还添加了我的chrome Cast设备。

chromecast google-cast
1个回答
0
投票

您会看到这些错误,因为您是直接通过Web浏览器加载接收器的。强制转换会话的通常流程是,“发送者”(Web浏览器,iOS设备,Android设备)将与托管接收方发起强制转换会话,从而开始套接字连接。现在,您只有一个接收器加载,没有任何启动会话。

一种测试方法是插入Chromecast或支持投射功能的设备(大多数Android TV也内置了Chromecast !,然后使用有效的发送者连接到您的接收器。


Google已建立了一个很棒的工具来帮助Chromecast开发,可惜的是它没有得到更多公开。您可以在这里找到它:https://casttool-1287.appspot.com/cactesttool/index.html

如果您想真正掌握自己的Chromecast开发技能,我个人建议您结帐:

  1. Google Cast Cast实验室,其中有一些非常有用的演练。 https://codelabs.developers.google.com/?cat=Cast
  2. Google Cast github存储库,有一些很好的例子。 https://github.com/googlecast

注意:这绝不是关于如何实际启动强制转换会话的详细说明,一些非常聪明的人已经深入研究了Chromecast会话的工作方式,如果您有兴趣在https://blog.oakbits.com/google-cast-protocol-overview.html处查看罗曼·皮卡德(Romain Picard)的文章,>

© www.soinside.com 2019 - 2024. All rights reserved.