开发者

how to load json in separate method

开发者 https://www.devze.com 2022-12-23 03:44 出处:网络
I need to generate the playlistdynamically. What is the best way to extract the playlist so that the playlist json below is separated into a different method or variable.

I need to generate the playlist dynamically. What is the best way to extract the playlist so that the playlist json below is separated into a different method or variable.

Mypage.foo
            <script type='text/javascript'>      
                var videoid = '1413';
                var videoUrl = 'myflv.flv';
            </script> 
## /scripts/flowplayer/init.js
$f(videoid, "/swf/flowplayer-3.1.5.swf", {

    playlist: [
        {
            url: videoUrl
        },
        {
            url: '59483.flv',
            title: 'Palm trees and the sun'
        },
        {
            url: '58192.flv',
            title: 'Happy f开发者_运维百科eet in a car'
        },
        {
            url: '63617.flv',
            title: 'People jogging'
        }
    ],
    wmode: 'opaque',
    plugins: {
        gatracker: {
            url: "/swf/flowplayer.analytics-3.1.5.swf",
            trackingMode: "Bridge",
            debug: false
        }
    }
}); 


I think you want something like this:

  var list1 = getPlayList();

  $f(videoid, "../flowplayer-3.1.5.swf", {
      playlist: list1,
      wmode: 'opaque'
  });

...where getPlayList() returns an array formatted the way you need:

  function getPlayList() {
      return [
      {
          title: 'scooter race',
          url: 'http://www.mediacollege.com/video-gallery/testclips/20051210-w50s.flv'
      },
      {
          title: 'Promo',
          url: 'http://e1h13.simplecdn.net/flowplayer/flowplayer.flv'
      }
      ];
  }


Simply extract it:

var f=function(param1,param2,...){
  return [
    // dynamic playlist data
  ];
}

Then call it:

$f(videoid, "/swf/flowplayer-3.1.5.swf", {
  playlist: function(){
    return f(param1,param2,...);
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消