简体   繁体   中英

Styling Chromecast Custom Receiver Media Player

I am using the Media Player library to cast my HLS stream and I am trying to style it. I want to put animations before loading etc. This what I am doing in the Media Manager's onLoad method;

  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);
    }

  }

Here am I still using the Media Player library (which I need for DRM)? videoElement variable refers to the video tag in the HTML. In the media manager onload function I set the source of that to the video url. By doing this, am I still using the Media Player library and can I still set the licenseURL for DRM etc? If not, how can I style the media player?

The Styled Media Receiver also uses MPL. If the license URL is embedded in the manifest then that should work for DRM. If you need any kind of authentication then you would need to create a custom receiver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM