正在停止Google TV模板随机化缩略图ID

Stopping Google TV template from randomizing Thumbnail IDs

本文关键字:随机化 略图 ID TV Google      更新时间:2023-09-26

我正在尝试建立一个使用HTML5谷歌电视模板2的网页,可以在https://developers.google.com/tv/web/docs/gtv-templates#template2.但我很困惑,因为模板会随机化缩略图ID(出于某种奇怪的原因)。

我有11个视频,我想把每个视频绑定到一个特定的缩略图。有什么建议吗?

在http://pastebin.com/L2U54DPZ是为模板提供动力的"dataprovider.js"。非常感谢您的帮助。感谢

在第46行更改:var num=getRandom(15);到var num=小;

在线168更改:var videoInfo=sources[getRandom(sources.length)];到var videoInfo=源[j];

在线170更改:

    thumb: 'images/thumbs/thumb' + getThumbId() + '.jpg',

至thumb:'images/tumbs/thumb'+getThumbId(j)+'.jpg',

请记住,Google示例是为了说明功能。我怀疑这就是随机性的来源。他们只是为这个例子生成了一些数据。

我更改了dataprovider.js以使其更易于理解,并具有更多的控制权。

以下是更改后的版本:

 var gtv = gtv || {
  jq: {}
};
/**
 * DataProvider class. Defines a provider for all data (Categories, Images & Videos) shown in the template.
 */
gtv.jq.DataProvider = function() {
};
/**
 * Returns all data shown in the template..
 * @return {object} with the following structure:
 *    - categories -> [category1, category2, ..., categoryN].
 *    - category -> {name, videos}.
 *    - videos -> {thumb, title, subtitle, description, sources}
 *    - sources -> [source1, source2, ..., sourceN]
 *    - source -> string with the url | {src, type, codecs}
 */
gtv.jq.DataProvider.prototype.getData = function() {
  var event_videos = [
    {
      sources: ['http://commondatastorage.googleapis.com/gtv_template_assets/IO2010-Keynote-day1.mp4'],
      title: '2010 Day 1 Keynote',
      thumb: 'images/thumbs/thumb01.jpg',
      description: ['With Vic Gundotra'],
      subtitle: 'Moscone Center'
    },
    {
      sources:['http://commondatastorage.googleapis.com/gtv_template_assets/IO2010-Keynote-day2-android.mp4'],
      title: '2010 Day 2 Keynote',
      thumb: 'images/thumbs/thumb02.jpg',
      description: ['Spider - what spider?'],
      subtitle: 'Moscone Center'
    }
];
 var buck_videos = [
    {
      sources:['http://bffmedia.com/trailer_400p.ogg'],
      title: 'Big Buck 400p Video Trailer',
      thumb: 'http://www.bffmedia.com/buck1.png',
      description: ['Common Creative Project Movie'],
      subtitle: 'Smaller Version'
    },
    {
      sources:['http://bffmedia.com/trailer_1080p.ogg'],
      title: 'Big Buck 1080p Video Trailer',
      thumb: 'http://www.bffmedia.com/buck2.png',
      description:['Common Creative Project Movie'],
      subtitle: 'Big Buck is a Rabbit'
    }
];

 var data = {
    categories: [
    {
      name: 'Dev Events',
      videos: event_videos
    },
    {
      name: 'Big Buck',
      videos: buck_videos
   }
   ]
 };
  return data;
};