设计Chromecast自定义接收器媒体播放器

时间:2014-08-21 19:58:30

标签: javascript css chromecast

我正在使用媒体播放器库来投射我的HLS流,我正在尝试设计它。我想在加载之前放置动画等。这就是我在媒体管理器的onLoad方法中所做的事情;

  window.onload = function ()
  {
     mediaElement = document.querySelector('video');
     mediaElement.autoplay = true;
     ...
  }

 mediaManager.onLoad = function (event)
 {
  var title = event.data['media']['metadata']['title'];

  var titleElement = this.receiverelement.querySelector('.media-title');
  videoplayer.setInnerText_(titleElement, title);

  var subtitle = event.data['media']['metadata']['subtitle'];
  var subtitleElement = this.receiverelement.querySelector('.media-subtitle');
  videoplayer.setInnerText_(subtitleElement, subtitle);

  var artwork = videoplayer.getValue_(event.data, ['media', 'metadata',
      'images', 0, 'url']);
  var artworkElement = this.receiverelement.querySelector('.media-artwork');
  videoplayer.setBackgroundImage_(artworkElement, artwork);

  var autoplay = videoplayer.getValue_(event.data, ['autoplay']);
  var contentId = videoplayer.getValue_(event.data, ['media', 'contentId']);
  var contentType = videoplayer.getValue_(event.data, ['media', 'contentType']
      );
  this.videoType(contentType);
  this.currentState(videoplayer.State.LOADING, false);
  this.videoElement.autoplay = autoplay || true;
  this.videoElement.src = contentId || '';
  if (event.data['media'] && event.data['media']['contentId']) {
    var url = event.data['media']['contentId'];
    var mediaHost = new cast.player.api.Host({
                    'mediaElement': this.videoElement,
                    'url': url
               });

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

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

    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)
    {
        this.load.bind(this);
    }
    else
    {
        mediaPlayer = new cast.player.api.Player(mediaHost);
        mediaPlayer.load(protocol, initialTimeIndexSeconds);
    }

  }

我还在使用媒体播放器库(我需要DRM)吗? videoElement变量引用HTML中的视频标记。在媒体管理器onload函数中,我将其源设置为视频URL。通过这样做,我仍然使用媒体播放器库,我仍然可以为DRM等设置licenseURL吗?如果没有,我该如何设置媒体播放器的样式?

1 个答案:

答案 0 :(得分:0)

Styled Media Receiver也使用MPL。如果许可证URL嵌入在清单中,那么这应该适用于DRM​​。如果您需要任何类型的身份验证,则需要创建自定义接收器。