代码之家  ›  专栏  ›  技术社区  ›  SeaBass

从表内容生成videojs播放列表?

  •  0
  • SeaBass  · 技术社区  · 7 年前

    var playlist_content = [{
      sources: [{
        src: 'http://media.w3.org/2010/05/sintel/trailer.mp4',
        type: 'video/mp4'
      }],
      poster: 'http://media.w3.org/2010/05/sintel/poster.png'
    }, {
      sources: [{
        src: 'http://media.w3.org/2010/05/bunny/trailer.mp4',
        type: 'video/mp4'
      }],
      poster: 'http://media.w3.org/2010/05/bunny/poster.png'
    }];
    
    player.playlist(playlist_content);
    

    通过从此表中获取数据:

    <table>
        <tr data-src="http://media.w3.org/2010/05/sintel/trailer.mp4" data-type="video/mp4" data-poster="http://media.w3.org/2010/05/sintel/poster.png"><td>Video 1</td></tr>
        <tr data-src="http://media.w3.org/2010/05/bunny/trailer.mp4" data-type="video/mp4" data-poster="http://media.w3.org/2010/05/bunny/poster.png"><td>Video 2</td></tr>
    </table>
    

    我的非工作尝试:

    var playlist_content = {};
    $("table tr").each(function() {
        playlist_content[]["sources"]["src"]    = $(this).data('src');
        playlist_content[]["sources"]["type"]   = $(this).data('type');
        playlist_content[]["poster"]            = $(this).data('poster');
    });
    player.playlist(playlist_content);
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   SeaBass    7 年前

    var playlist_content = [];
    var index = 0;
    $("table tr").each(function() {
        playlist_content[index]                      = {};
        playlist_content[index]["sources"]           = [];
        playlist_content[index]["sources"][0]        = {};
        playlist_content[index]["sources"][0]["src"] = $(this).data('src');
        playlist_content[index]["sources"][0]["type"]= $(this).data('type');
        playlist_content[index]["poster"]            = $(this).data('poster');
        index++;
    });
    player.playlist(playlist_content);