Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
310 lines (259 sloc) 11.7 KB
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends Sprite {
public var player0:VimeoPlayer = null;
public var player1:VimeoPlayer = null;
public var players:Array = new Array(null, null);
public var LOOP:Boolean = true;
public var container:Sprite = new Sprite();
public var videos:Array;
public var cur_video_index:int;
public var cur_player:int = 1; // 0 = player0, 1 = player1
public var player0_playing:int = -1; // video id of cur vid
public var player1_playing:int = -1; // video id of cur vid
public var is_playing:int = -1;
public var autoload:Boolean = false;
public var is_fullscreen:Boolean = false;
public var timeline:Timeline;
public var timeline_timer:Timer = new Timer(1500, 1);
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var clip_ids:String = root.loaderInfo.parameters.clip_ids;
this.videos = clip_ids.split(',');
/*this.videos = new Array(1,14170984,6027821,5977520,11270100,6635199,7014969,6945410,6472883,7511762,7316874, 6725772,
8036420,7166048,8623308,7718789,8483986,6549001,5889333,5834412,8535557,5955796,6748732,6896470,
6684605,6361897,7511559,6505959,6198144,7333995,5795270,5894232,6214681,6923077,5690537,6882551
,6859476,7339580,7631796,5960348,6101892,5856047,5674503,5715225,5549929,7345852,6016077,5773960,
6879130,7109490,5843224,6026542,6151934,9790179,6455535,5901371,6243371,6685728,7247292,6884441,
7614671,5897458,8665342,6415613,5833561,6332641,6975278,6494619,6458112,8279394,6431319,6875977,
6228138,7357634,7106978,8057285,5833801,5890514,7443986,7699976,6456682,7379864,6223001,6348849,
6602584,5918666,7583575,7513690,8190015,6884818,6109936,6596766,8093095,7344211,5904999,5716837,
7239872,6138298,5825197,7649891,8648660,8145357,6215887,6875483,5655443,6012423,7362331,5668193,
6280094,7380249,6281161,9553368,7751255,7654375,7178454,6720764,7806125,7303107,5730490,6999601,
6202340,7196112,5777461,6939986,6027394,7329803,7713269,7408042,5964279,8070747,6119534,6024331,
6461227,7029558,9182007,6611650,5689657,6424967,5755135,5890980,6105854,6421193,5678469,6953289,
6998025,6060529,5811823,7252321,7250558,6028146,6494682,6827367,8329113,6608677,8524705,7203944,
7354790,5752096,6861928,7755883,5960549,6469056,6149148,5715703,8686967,7015999,7317762,8632741,
6001928,6920069,7267100,8097626,8311346,6473529,7078610,8007276,6443910,7388847,7019839,6527759,
6133519,6260789,7014472,9080628,6670876,7456307,6000974,6656387,6077398,6650244,5994666,7728329,
8164251,7322701,6257723,5755458,6174830,6005033,5758794,8519414,6013878,8406953,6441971,5659934,
6915564,8327249,6873216,6186440,5960485,6333790,6789066,9200594,8230256,7034042,7422794,5626842,
7606610,6888168,6211190,8086472,6032292,8663052,6449054,8212516,7321495,7469469,6289323,7401554,
6587509,6448350,8208261,6274534,5704536,5939194,7050383,5683244,7219190,5914171,5778061,5814790,
7386838,7243384,5815185,8495303,5789109,8088979,6955513,5999023,6453281,6182058,5907616,6177797,
8068902,7303470,6096364,6863361,8923263,8271766,8136076,6293348,6462718,8925638,7389804,7824992,
7214614, 6292280,8062061,7432092,8147382,7356962,7565805,7922523,9674703,7888857,6178748,7258847,
6172535,7569458,8164649,8905702,7372883,7228006,6744911,7494285,8208263,6266223,6199412,5728499,
7371761,6893029,7508925,7677809,7509363,7843953,7316435,5796868,5665775,7123959,6303442,5554759,
8279488,7466959,5849728,10005438,7254892,7028745,8078505,6450144,6059975,7018124,5689978,5891064
,6902629,7163525,9157598,7453297,8688531,7504723,7346045,7129779,7930950,5863089,5880801,8230204,
8230233,7385912,7387246,6899963,5963944,6903652,6959569,5966058,8108334,7162375,6003638,7810804,
6954168,8663701,7115636,7184307,7675880,5898447,7004385,7428650,6002369,6745647,7263941,6896137,
8639087,7192854,6662654,6918722,6746122,6252156,5852059,6463873,7091249,5938041,6561904,7235570,
8831517,5972746,6638357,6452198,7183183,7322183,5752429,5833923,5685239,7589860,6212548,7186407
,5983150,6724696,6549216,8304010,7576540,7459095,6833063,6849110,6421410,6643077,8080467,7666690,
5626626,5725742,6755836,8029157,6074066,6686244,7824140,7370655,7003531, 6879512,9317130,6796217,
6880790,5762024,6005611,5568592,6602012,6018515,7017819,7844947,8869524,7387130,7248115,8271895,
6058829,7905547,7384195,6456034,6323582,7468543,6111327,6055326,6998683,6384525,6987758,5775171,
5756105,5966282,6209631,7115554,6553748,6332199,5867405,7108368,6295552,7570472,5946902,7609354,
6379927,7075248,6876312,6101501,5740625,5794585,6346359,6045072,6472547,8968335,5669002,7139704,
7037410,8786082,6988101,6909164,8132690,6522756,7287104,7176840,6619669,6056945,6175524,8379790,
7171589,6637241,6570160,7467084,6139108,8231061,6353080,5767428,6491900,6491997,6986902,6175249,
7509731,6805222,6231966,6804795,7128881);*/
this.cur_video_index = 0;
this.addEventListener(Event.ADDED_TO_STAGE, this.play);
stage.addEventListener(Event.RESIZE, resize);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
this.addEventListener(MouseEvent.CLICK, onClick);
// TODO: stop keyboard events
addChild(this.container);
this.timeline = new Timeline(this.videos.length);
this.timeline.x = this.timeline.y = 10;
addChild(this.timeline);
timeline_timer.addEventListener("timer", hideTimeline);
timeline_timer.start();
this.timeline.addEventListener('SCENE_CHANGE', onSceneChange);
}
public function mouseLeave(e:Event):void
{
this.timeline.visible = false;
}
public function mouseMove(e:MouseEvent):void
{
this.timeline.visible = true;
timeline_timer.reset();
timeline_timer.start();
}
public function hideTimeline(e:TimerEvent):void
{
this.timeline.visible = false;
}
public function play(e:Event = null):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, this.play);
if (this.player0_playing === cur_video_index) {
trace('Playing player 0')
this.players[1].pause();
this.is_playing = 0;
this.showVideo(0);
}
else if (this.player1_playing === cur_video_index) {
trace('Playing player 1')
this.players[0].pause();
this.is_playing = 1;
this.showVideo(1);
}
else {
if (this.is_playing == 1) {
trace('Playing player 0')
this.is_playing = 0;
this.player0_playing = this.cur_video_index;
this.loadPlayer(0, this.videos[this.cur_video_index]);
this.showVideo(0);
}
else {
trace('Playing player 1')
this.is_playing = 1;
this.player1_playing = this.cur_video_index;
this.loadPlayer(1, this.videos[this.cur_video_index]);
this.showVideo(1);
}
}
this.queueNext();
}
public function showVideo(id:int):void
{
try {
this.players[id].x = 0;
this.players[id == 1 ? 0 : 1].x = stage.stageWidth;
}
catch (ex) { }
}
public function queueNext():void
{
var next_vid:int = this.cur_video_index + 1;
if (next_vid >= this.videos.length && this.LOOP)
next_vid = 0;
else if (next_vid >= this.videos.length && !this.LOOP)
return;
if (this.is_playing == 0) {
this.player1_playing = next_vid;
this.loadPlayer(1, this.videos[this.player1_playing]);
}
else if (this.is_playing == 1) {
this.player0_playing = next_vid;
this.loadPlayer(0, this.videos[this.player0_playing]);
}
}
public function playNext():void
{
this.cur_video_index++;
if (this.cur_video_index >= this.videos.length && this.LOOP)
this.cur_video_index = 0;
else if (this.cur_video_index >= this.videos.length && !this.LOOP)
return;
if (this.cur_player == 0)
this.cur_player = 1;
else
this.cur_player = 0;
this.timeline.updateTimeline(this.cur_video_index / this.videos.length);
this.play();
}
public function loadPlayer(player_id, clip_id:int):void
{
trace('Loading video #' + clip_id + ' into player ' + player_id);
// Unload it first
if (this.players[player_id] != null) {
trace('Unloading');
this.players[player_id].removeEventListener('FINISHED', this.onFinish);
this.players[player_id].removeEventListener('PROGRESS', this.onProgress);
this.players[player_id].removeEventListener(Event.COMPLETE, this.onComplete);
this.players[player_id].unload();
this.container.removeChild(this.players[player_id]);
this.players[player_id] = null;
}
this.players[player_id] = new VimeoPlayer('094cec064b431ea4b68212a185b01b3d', clip_id, stage.stageWidth, stage.stageHeight);
this.players[player_id].x = stage.stageWidth;
this.players[player_id].addEventListener('FINISHED', this.onFinish);
this.players[player_id].addEventListener('PROGRESS', this.onProgress);
this.players[player_id].addEventListener(Event.COMPLETE, this.onComplete);
this.container.addChild(this.players[player_id]);
}
public function onSceneChange(e:Event):void
{
this.cur_video_index = this.timeline.cur_pos * this.videos.length;
this.play();
}
public function onClick(e:MouseEvent):void
{
if (e.stageX >= stage.stageWidth - 101 && // left
e.stageX <= stage.stageWidth - 80 &&
e.stageY >= stage.stageHeight - 40 &&
e.stageY <= stage.stageHeight - 13)
{
if (this.is_fullscreen) {
this.is_fullscreen = false;
stage.displayState = "normal";
}
else {
this.is_fullscreen = true;
stage.displayState = "fullScreen";
}
}
}
public function resize(e:Event):void
{
this.players[0].setSize(stage.stageWidth, stage.stageHeight);
this.players[1].setSize(stage.stageWidth, stage.stageHeight);
this.showVideo(this.is_playing);
}
public function onProgress(e:Event):void
{
var diff:Number = this.players[this.cur_player].getDuration() - this.players[this.cur_player].getCurrentTime();
// need at least 2 seconds so that the playbar disappears on the other vimeo player
var FADEOUT_TIME:Number = 2;
if (diff <= FADEOUT_TIME) {
var other:int = this.cur_player == 1 ? 0 : 1;
trace(this.players[other].getCurrentTime());
// Fail safe if for some reason it didnt switch
if (this.players[other].getCurrentTime() > 3 && this.cur_player != other)
this.playNext();
this.players[other].setVolume(100 * ((FADEOUT_TIME - diff) / FADEOUT_TIME)); // Fade in next video
if (!this.players[other].is_playing) {
this.players[other].play();
}
this.players[this.cur_player].setVolume(100 * (diff / FADEOUT_TIME)); // Fade out the volume in the last X seconds
}
else {
this.players[this.cur_player].setVolume(100);
}
}
public function onComplete(e:Event):void
{
this.showVideo(this.is_playing);
if (this.autoload) {
try {
this.videos[this.is_playing].play();
this.videos[this.is_playing].pause();
} catch(e) { }
}
else {
this.autoload = true;
}
}
public function onFinish(e:Event):void
{
trace('Playing next video...')
this.playNext();
}
}
}
Something went wrong with that request. Please try again.