/*=======================================================================
*
*   Copyright (C) 2014 Lysine.
*
*   Filename:    Player.js
*   Time:        2014/07/05
*   Author:      Lysine
*
*   Lysine is a student majoring in Software Engineering
*   from the School of Software, SUN YAT-SEN UNIVERSITY.
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.

*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
=========================================================================*/

Player={};

Player.triggers={p:[],r:[]};
Player.triggers.clear=function(){
    Player.triggers.p=[];
    Player.triggers.r=[];
};

Player.play=function(){
    callNative('Player.play');
};

Player.pause=function(){
    callNative('Player.pause');
};

Player.seek=function(time){
    callNative('Player.seek',time);
};

Player.update=function(){
    Player.time=getTimer();
    var clean=function(list){
        for(var i=0;i<list.length;i++){
            var t=list[i];
            if(t.o<=Player.time){
                list.splice(i,1);
            }
            else{
                i++;
            }
        }
    }
    clean(Player.triggers.p);
    clean(Player.triggers.r);
    Player.state =callNative('Player.state');
    Player.width =callNative('Player.width');
    Player.height=callNative('Player.height');
}

Player.keyTrigger=function(f,timeout,up){
    var t={};
    t.f=f;
    t.o=timeout+getTimer();
    (up?Player.triggers.r:Player.triggers.p).push(t);
}

Player.changeKeyState=function(key,up){
    var l=(up?Player.triggers.p:Player.triggers.r);
    for(var i in l){
        l[i].f(key);
    }
}

Player.jump=function(){};

Player.update();
