function Player (playerNum) {
    this.paused = true;
    this.stoped = true;
    this.sound = new Sound();
    this.position = 0;
    this.frequency = 1000;
    this.isLoaded = false;
    this.duration = 0;
    this.bytesTotal = 0;
    this.playerWidth = 252;
    this.registerCallback(); 
    this.playerId = playerNum;
 }

Player.prototype.onPlayButtonClick = function(itemId) {
    if(this.paused) {
       //$('button_play').className ='button_pause';
       this.paused = false;
       if(this.stoped) {
           this.sound.loadSound(this.track, true);
       }
       this.sound.start(0, 1);
       this.stopped = false;
       //alert('player'+itemId);
       document.getElementById('player'+this.playerId).className = "buttonPlaying";
    } else {
       //$('button_play').className ='button_play';
       this.position = this.sound.getPosition();
       this.sound.stop();         
       this.paused = true;      
       this.stopped = true;
       document.getElementById('player'+this.playerId).className = "buttonStopped";
       //this.onPause();
    }
 }
Player.prototype.onStopButtonClick = function() {
    this.paused = true;
    this.stoped = true;
    this.position = 0;
    this.duration = 0;
    this.sound.start(this.duration/1000, 1);
    this.sound.stop();      
    document.getElementById('player'+this.playerId).className = "buttonStopped";
    //$('button_play').className ='button_play';
    //$('display').innerHTML = "stoped";  
} 
Player.prototype.loadTrack = function(track,itemId) {
    //this.watch("this.currentTrack",304);
    this.track = track;
    this.onPlayButtonClick(itemId);
 };
Player.prototype.onTimerEvent = function() {
    var isDurationOk = false;
    if(!this.paused) {
    
        var position = this.sound.getPosition();
        if(!position) position = 0;
        /*if(position != this.position && position != 0) {
           this.onPlaying();
        } else {
           this.onBuffering();
        }*/
        this.position = position;
        
        var duration = 0;
        
        duration = this.sound.getDuration();
        if(!duration) duration = 0;
        if(duration == this.duration && duration != 0) {
           isDurationOk = true;
           
        }
        this.duration = duration;
        var progress = position/duration;
       
        if (progress == 1 && duration != 0 && position != 0) {
          //this.onSoundComplete();
            document.getElementById('player'+this.playerId).className = "buttonStopped";
        }
    }
 }

Player.prototype.registerCallback = function() {
   setInterval(this.onTimerEvent.bind(this), this.frequency);
}