web/static/res/js/incplayer.js
author Edwin Razafimahatratra <edwin@robotalismsoft.com>
Wed, 16 Jan 2013 21:26:15 +0100
changeset 80 46b897524cc4
parent 78 8c3f0b94d056
child 88 eeb0a6f3c07d
permissions -rw-r--r--
resync
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     1
function IncPlayer()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     2
{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     3
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     4
	// Members
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     5
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     6
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     7
	// Global
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     8
	this.initDone = false;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
     9
	this.playerIsReady = false;
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    10
	this.playerWaitForBeingReady = false; // used on ipad
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    11
	this.mobile;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    12
	this.ipad;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    13
	this.nextPage;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    14
	this.reloadPage;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    15
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    16
	// Sequences
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    17
	this.allSequencesData = [];
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    18
	this.sequences = [];
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    19
	this.singleVideo;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    20
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    21
	// Popcorn objects
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    22
	this.videoDivId = "";
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    23
	this.videoExt = "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    24
	this.popSeq = null;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    25
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    26
	// Controls
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    27
	this.playButton = null;
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    28
	this.hdSdButton = null
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    29
	this.progressCurrent = null;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    30
	this.progressDuration = null;
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    31
	this.progressCursor = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    32
	this.progressBar = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    33
	this.progressCursorX = 0; 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    34
	this.progressCursorDrag;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    35
	this.hd;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    36
	this.seekTime = -1;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    37
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    38
	// Tools
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    39
	this.logiEnable = true;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    40
	this.jsonData = [];
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    41
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    42
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    43
	// Functions
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    44
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    45
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    46
	this.init = function(nextPage, videoDivId, playButtonId, hdSdButtonId, progressCurrentId, progressDurationId, progressCursorId, progressBarId, jsonFile)
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    47
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    48
		this.nextPage = nextPage;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    49
		this.videoDivId = videoDivId;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    50
80
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    51
		this.readUrlVideosIndex();
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
    52
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    53
		// Control
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    54
		this.playButton = $("#" + playButtonId).get(0);
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    55
		this.hdSdButton = $("#" + hdSdButtonId).get(0);
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    56
		this.progressCurrent = $("#" + progressCurrentId);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
    57
		this.progressDuration = $("#" + progressDurationId);
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    58
		this.progressCursor = $("#" + progressCursorId);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    59
		this.progressBar = $("#" + progressBarId);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    60
		this.ctrlSetCursorDragFunction();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    61
		this.setCursorPosition(0);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    62
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    63
		// HD ?
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    64
		this.hd = incChoice.getHD();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    65
		$(this.hdSdButton).css({"background-position" : this.hd ? '0 -12px' : '0 0'});			
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    66
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    67
		// Video extention
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    68
		this.videoExt = this.getSupportedVideoExt();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    69
		if (this.videoExt === "") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    70
			this.loge("your browser don't support HTML5 videos");
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    71
			return false;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    72
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    73
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    74
		if (jsonFile !== null & jsonFile !== undefined) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    75
			// Load all sequences data
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    76
			this.allSequencesData = this.loadJson(jsonFile);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    77
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    78
			// Add index to the videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    79
			for (var i = 0; i < this.allSequencesData.videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    80
				this.allSequencesData.videos[i].index = i;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    81
			}			
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    82
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    83
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    84
		this.initDone = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    85
		this.mobile = IsSmartphone();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
    86
		this.ipad = !this.mobile && IsIpad();
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    87
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    88
		return true;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    89
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    90
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    91
	this.destroySequence = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    92
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    93
		if (this.popSeq !== null) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    94
			for (var i = 0; i < this.sequences.length; ++i) {			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    95
				this.popSeq.eq(i).destroy();			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    96
			}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    97
			this.sequences = [];
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    98
			this.popSeq.remove();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
    99
		}		
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   100
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   101
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   102
	this.createPopSequence = function(words, videosIndex)
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   103
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   104
		if (!this.initDone) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   105
			this.loge("incplayer not initialized");
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   106
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   107
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   108
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   109
		// Delete previous popcorn objects
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   110
		this.destroySequence();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   111
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   112
		// Choose the 3 videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   113
		this.choosePopSequence(words, videosIndex);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   114
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   115
		// And init the popcorn sequence
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   116
		this.initPopSequence();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   117
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   118
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   119
	this.playSingleVideo = function(videoUrl)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   120
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   121
		this.sequences = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   122
       	var video = { name : "xxx", src: videoUrl, in: 0, out: "1.44" };
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   123
       	this.sequences.push(video);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   124
       	this.formatPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   125
		this.initPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   126
		this.singleVideo = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   127
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   128
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   129
	this.choosePopSequence = function(wordsIndex, videosIndex)
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   130
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   131
		this.sequences = [];
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   132
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   133
		if (videosIndex.length == 3) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   134
			// The player got reloded, we use the previously choosen videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   135
			for (var i = 0; i < videosIndex.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   136
				this.sequences.push(this.allSequencesData.videos[videosIndex[i]]);		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   137
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   138
		} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   139
			// We choose new videos
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   140
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   141
			// Get previous used videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   142
			var var32bits = incChoice.getChoosenVideosFlags();
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   143
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   144
			// Choose videos according to the chosen words
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   145
			for (var i = 0; i < wordsIndex.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   146
				var v = this.getRandomVideos(wordsIndex[i], var32bits, this.sequences);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   147
				if (v == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   148
					// We didn't find free video
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   149
					// So we mark some as unplayed, we must get flags again and retry
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   150
					var32bits = incChoice.getChoosenVideosFlags();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   151
					v = this.getRandomVideos(wordsIndex[i], var32bits, this.sequences);
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   152
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   153
					if (v == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   154
						this.loge("We didn't find a free video");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   155
					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   156
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   157
				this.sequences.push(v);		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   158
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   159
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   160
			// Save played videos with cookies
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   161
			this.savePlayedVideos(this.sequences, true);		
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   162
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   163
			// Save chosen video with cookies
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   164
			this.saveChosenVideos(this.sequences);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   165
		}
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   166
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   167
		// Format pop sequence
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   168
		this.formatPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   169
		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   170
		// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   171
		this.logi("choosed sequences:");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   172
		for (i = 0; i < this.sequences.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   173
			this.logi(this.sequenceToString(i));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   174
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   175
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   176
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   177
	this.formatPopSequence = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   178
	{
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   179
		// Set the video file name 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   180
		var i;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   181
		for (i = 0; i < this.sequences.length; ++i) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   182
			var v = this.sequences[i];
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   183
			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   184
			// HD
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   185
			if(!this.hd) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   186
				v.src = v.src.replace("HD", "SD"); 
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   187
			}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   188
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   189
			// Extention
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   190
			v.src += "." + this.videoExt;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   191
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   192
			// Set the final file
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   193
			this.sequences[i] = v;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   194
		}
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   195
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   196
		for (i = 0; i < this.sequences.length; ++i) {
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   197
			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   198
			// Get the sequence
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   199
			var seq = this.sequences[i];
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   200
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   201
			// Compute time in seconds
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   202
			var integer = Math.floor(seq.duration);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   203
			var decimal = Math.floor((seq.duration - integer) * 100);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   204
			var duration = integer * 60 + decimal;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   205
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   206
			this.sequences[i] = { src: seq.src, in: 0, out: duration };
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   207
		}		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   208
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   209
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   210
	this.getRandomVideos = function(wordIndex, var32bits, otherVideos)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   211
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   212
		var i;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   213
		var index = parseInt(wordIndex);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   214
		var videos = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   215
		var allVideosPlayed = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   216
		var videosMatchWord = [];
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   217
		
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   218
		// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   219
		var freeVideosCount = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   220
		var wordScoreAllVideos = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   221
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   222
		// Get all videos affected by this word
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   223
		for (i = 0; i < this.allSequencesData.videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   224
			var video = this.allSequencesData.videos[i];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   225
			var wordScore = video.scoreWord[index];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   226
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   227
			if (wordScore <= 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   228
				// This video can't be choosen with this word
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   229
				continue;				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   230
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   231
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   232
			videosMatchWord.push(video); // Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   233
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   234
			video.choosen = incChoice.IsThisVideoWasPlayed(var32bits, video.index);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   235
			if (video.choosen) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   236
				// This video was already played in an another session
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   237
				continue;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   238
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   239
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   240
			allVideosPlayed = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   241
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   242
			// Compare categories
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   243
			video.samecat = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   244
			for (var j = 0; j < otherVideos.length; ++j) { 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   245
				if (video.cat == otherVideos[j].cat) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   246
					video.samecat = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   247
					break;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   248
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   249
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   250
			if (video.samecat == true) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   251
				// This video have the same cat that an other selected video
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   252
				continue;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   253
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   254
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   255
			// We push has many time the video that the score for the word
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   256
			for (var j = 0; j < wordScore; ++j) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   257
				videos.push(video);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   258
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   259
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   260
			// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   261
			wordScoreAllVideos += wordScore;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   262
			++freeVideosCount;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   263
		}
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   264
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   265
		if (allVideosPlayed || !videos.length) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   266
			// All the videos asociated with the word have been played
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   267
			// or there is no videos to choose because we skipped the one with the same cat
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   268
			// We must mark the videos asociated with the word as unplayed
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   269
			this.savePlayedVideos(videosMatchWord, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   270
			return null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   271
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   272
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   273
		// Choose random video
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   274
		var v = videos[this.random(0, videos.length)];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   275
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   276
		// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   277
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   278
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   279
		this.logi("---------------------------------------------------------------------");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   280
		this.logi("The word " + this.allSequencesData.mots[index] + "(" + index + ")" +" give us " + videosMatchWord.length + " videos, we can choose " + freeVideosCount);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   281
		this.logi("---------------------------------------------------------------------");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   282
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   283
		for (i = 0; i < videosMatchWord.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   284
			var video = videosMatchWord[i];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   285
			var message = this.resizeString(video.name, 15) + this.resizeString(" cat:" + video.cat, 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   286
			if (video.choosen) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   287
				message += this.resizeString("played", 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   288
			} else if (video.samecat) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   289
				message += this.resizeString("same cat", 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   290
			} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   291
				message += this.resizeString("OK", 15) + this.resizeString("proba:" + video.scoreWord[index] + "/" + wordScoreAllVideos, 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   292
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   293
			this.logi(message);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   294
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   295
		this.logi("");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   296
		this.logi("We choose " + v.name + "(" + v.index + ")" + " cat:" + v.cat + " proba: " + v.scoreWord[index] + "/" + wordScoreAllVideos +  "\n\n");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   297
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   298
		return v;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   299
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   300
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   301
	this.savePlayedVideos = function(videos, markPlayed)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   302
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   303
		var indexs = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   304
		for (var i = 0; i < videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   305
			indexs.push(videos[i].index);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   306
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   307
		incChoice.savePlayedVideos(indexs, markPlayed);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   308
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   309
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   310
	this.saveChosenVideos = function(videos)
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   311
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   312
		var indexs = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   313
		for (var i = 0; i < videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   314
			indexs.push(videos[i].index);
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   315
		}
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   316
		incChoice.saveChosenVideos(indexs);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   317
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   318
	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   319
	this.resizeString = function (str, size)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   320
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   321
		while (str.length < size) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   322
			str += " ";
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   323
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   324
		return str;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   325
	};
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   326
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   327
	this.getWordIndex = function(word)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   328
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   329
		var words = this.allSequencesData.mots;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   330
		for (var i = 0; i < words.length; ++i) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   331
			if (words[i] == word) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   332
				return i;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   333
			}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   334
		}
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   335
		this.loge("getWordIndex erreur");
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   336
		return -1;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   337
	};
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   338
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   339
	this.debugDisplayWordsIndex = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   340
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   341
		var words = this.allSequencesData.mots;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   342
		for (var i = 0; i < words.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   343
			this.logi(words[i] + " -> " + i);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   344
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   345
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   346
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   347
	this.initPopSequence = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   348
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   349
		var self = this;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   350
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   351
		// Create the popcorn sequencer
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   352
		self.popSeq = Popcorn.sequence(self.videoDivId, self.sequences);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   353
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   354
		for (var i = 0; i < self.sequences.length; ++i) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   355
			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   356
			var pop = self.popSeq.eq(i);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   357
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   358
			// Hide controls
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   359
			pop.controls(false);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   360
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   361
			// Play event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   362
			self.listenEvent(pop, "playing", false, i, function(index) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   363
				self.displayPlayButton(false);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   364
				self.logi("play sequence: " + self.sequenceToString(self.popSeq.active));
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   365
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   366
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   367
			// Pause event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   368
			self.listenEvent(pop, "pause", false, i, function(index) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   369
				self.displayPlayButton(true);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   370
				self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active));
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   371
			});			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   372
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   373
			// Ended event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   374
			self.listenEvent(pop, "ended", false, i, function(index) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   375
				self.logi("ended sequence: " + self.sequenceToString(self.popSeq.active));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   376
			});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   377
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   378
			// Timeupdate event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   379
			self.listenEvent(pop, "timeupdate", false, i, function(index) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   380
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   381
				var currentTime = self.popSeq.currentTime();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   382
				if (!self.progressCursorDrag) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   383
					// Move timeline and display the time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   384
					self.progressCursorX = self.setCursorPosition(currentTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   385
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   386
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   387
				// Detect the sequence end
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   388
				if (self.popSeq.active == self.sequences.length-1 && currentTime >= self.popSeq.duration() - 1) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   389
					setTimeout(function() { 
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   390
								location.href = self.nextPage;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   391
							}, 1500);
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   392
				}
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   393
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   394
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   395
			/*
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   396
			// Canplaythrough event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   397
			self.listenEvent(pop, "canplaythrough", true, i, function(index) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   398
			});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   399
			*/				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   400
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   401
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   402
		if (!this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   403
			self.popSeq.on("canplaythrough", function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   404
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   405
				self.playerIsReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   406
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   407
				// Recompute Duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   408
				self.recomputeDuration();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   409
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   410
				// Automatic play
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   411
				self.ctrlPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   412
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   413
				// Unlisten event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   414
				self.popSeq.off("canplaythrough");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   415
				self.logi("the player is ready");
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   416
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   417
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   418
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   419
		self.popSeq.on("cycle", function() {
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   420
			console.log("CYCLE");
47
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   421
		});
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   422
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   423
		self.popSeq.on("ended", function() {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   424
		});
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   425
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   426
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   427
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   428
	this.listenEvent = function(pop, event, unlisten, index, func)
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   429
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   430
		pop.on(event, function() {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   431
			// Execute the function
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   432
			func(index);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   433
	
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   434
			if (unlisten) {		
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   435
				// Unlisten event
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   436
				pop.off(event);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   437
			}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   438
		});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   439
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   440
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   441
	this.recomputeDuration = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   442
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   443
		// Recompute duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   444
		var totalDuration = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   445
		for (var j = 0; j < this.sequences.length; ++j) {			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   446
			var duration = this.popSeq.eq(j).duration();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   447
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   448
			// ofVideos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   449
			this.popSeq.inOuts.ofVideos[j].out = duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   450
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   451
			// ofClips
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   452
			this.popSeq.inOuts.ofClips[j].in = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   453
			totalDuration += duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   454
			this.popSeq.inOuts.ofClips[j].out = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   455
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   456
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   457
		// Set total duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   458
		$(this.progressDuration).html(this.secondsToTime(this.popSeq.duration()));			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   459
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   460
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   461
	this.recomputeDurationNoAutoPlay = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   462
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   463
		// Recompute duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   464
		var totalDuration = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   465
		for (var j = 0; j <= this.popSeq.active; ++j) {			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   466
			var duration = this.popSeq.eq(j).duration();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   467
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   468
			// ofVideos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   469
			this.popSeq.inOuts.ofVideos[j].out = duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   470
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   471
			// ofClips
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   472
			this.popSeq.inOuts.ofClips[j].in = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   473
			totalDuration += duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   474
			this.popSeq.inOuts.ofClips[j].out = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   475
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   476
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   477
		// Set total duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   478
		$(this.progressDuration).html(this.secondsToTime(this.popSeq.duration()));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   479
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   480
		if (incHideBar !== undefined) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   481
			incHideBar.showBarPointerOnAction(6000);					
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   482
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   483
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   484
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   485
	this.getCurrentPop = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   486
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   487
		var index = this.popSeq.active;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   488
		if (index >= this.sequences.length) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   489
			index = this.sequences.length-1;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   490
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   491
		return this.popSeq.eq(index);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   492
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   493
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   494
	this.setCursorPosition = function(time)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   495
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   496
		// Display time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   497
		$(this.progressCurrent).html(this.secondsToTime(time));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   498
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   499
		// Move cursor timeline
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   500
		var progressCursorX = time ? ((time / this.popSeq.duration()) * (240 - 16)) : 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   501
		$(this.progressCursor).css({"left" : progressCursorX });
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   502
		$("#progress").css({"width" : progressCursorX + 8});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   503
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   504
		return progressCursorX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   505
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   506
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   507
	this.forceCheckPlayerIsReady = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   508
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   509
		this.playerIsReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   510
		this.playerWaitForBeingReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   511
		this.checkPlayerIsReady();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   512
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   513
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   514
	this.checkPlayerIsReady = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   515
	{		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   516
		if (this.playerIsReady) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   517
			return true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   518
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   519
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   520
		if (this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   521
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   522
			// We "manualy" play the video (we are in a click event handler)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   523
			var media = this.popSeq.eq(this.popSeq.active).media;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   524
			media.play();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   525
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   526
			if (media.readystate === 4) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   527
				this.playerIsReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   528
				this.recomputeDurationNoAutoPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   529
				return false; // Ready but we don't want to do anything after
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   530
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   531
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   532
			if (this.playerWaitForBeingReady) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   533
				return false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   534
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   535
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   536
			this.playerWaitForBeingReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   537
			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   538
			var self = this;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   539
			var mediaCanPlay = function () {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   540
				// Remove event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   541
				media.removeEventListener('canplaythrough', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   542
				media.removeEventListener('load', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   543
				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   544
				// The video is ready, play
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   545
				media.play();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   546
				self.playerIsReady = true;				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   547
				self.recomputeDurationNoAutoPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   548
				console.log("ipad play event");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   549
			}			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   550
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   551
			media.addEventListener('canplaythrough', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   552
			media.addEventListener('load', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   553
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   554
			setTimeout(function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   555
				media.pause(); // Block play so it buffers before playing
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   556
			}, 1);				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   557
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   558
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   559
		this.logi("can't play, the player is not ready");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   560
		return false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   561
	}	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   562
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   563
	this.ctrlSetCursorDragFunction = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   564
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   565
		var self = this;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   566
		var origineX = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   567
		var posX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   568
		var maxX = 240 - 16;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   569
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   570
		var setCursorPositionX = function (x) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   571
			if (x < 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   572
				x = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   573
			} else if (x > maxX) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   574
				x = maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   575
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   576
			var time = self.popSeq.duration() * x / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   577
			self.setCursorPosition(time);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   578
			return x;			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   579
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   580
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   581
		var setCursorPosition = function (x) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   582
	        self.progressCursorDrag = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   583
			if (origineX == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   584
				origineX = x;	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   585
			} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   586
				posX = self.progressCursorX + x - origineX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   587
				posX = setCursorPositionX(posX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   588
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   589
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   590
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   591
		this.progressCursor.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   592
	        mousedown: function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   593
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   594
				if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   595
					return;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   596
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   597
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   598
	        	$(document).on(
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   599
		        	self.ipad ? {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   600
		        		touchmove: function (e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   601
		        			e.preventDefault();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   602
							var touches = ( typeof( event.touches ) != "undefined" ) ? event.touches : event.changedTouches;		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   603
		        			setCursorPosition(touches[0].pageX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   604
	   					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   605
		        	} : {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   606
		        		mousemove: function (e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   607
		        			self.progressCursorDrag = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   608
		        			setCursorPosition(e.pageX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   609
	   					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   610
		        	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   611
		        );
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   612
	        }
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   613
	    });
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   614
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   615
		var progressBarX = $(self.progressBar).position().left;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   616
	    if (self.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   617
			this.progressBar.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   618
		        touchdown: function(e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   619
					if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   620
						return;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   621
					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   622
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   623
		        	e.preventDefault();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   624
					var touches = ( typeof( event.touches ) != "undefined" ) ? event.touches : event.changedTouches;		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   625
		        	PosX = touches[0].pageX - progressBarX - 8;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   626
		        	PosX = setCursorPositionX(PosX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   627
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   628
	        		// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   629
					var jumpTime = self.popSeq.duration() * PosX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   630
					self.popSeq.jumpTo(jumpTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   631
		        }
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   632
		    });				    	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   633
		} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   634
			this.progressBar.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   635
		        mousedown: function(e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   636
					if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   637
						return;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   638
					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   639
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   640
		        	PosX = e.pageX - progressBarX - 8;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   641
		        	PosX = setCursorPositionX(PosX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   642
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   643
	        		// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   644
					var jumpTime = self.popSeq.duration() * PosX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   645
					self.popSeq.jumpTo(jumpTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   646
		        }
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   647
		    });
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   648
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   649
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   650
		$(document).mouseup(function(){
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   651
			if (self.progressCursorDrag) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   652
		        self.progressCursorDrag = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   653
				origineX = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   654
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   655
		        // Remove event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   656
				$(document).off(self.ipad ? "touchmove" : "mousemove");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   657
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   658
				// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   659
				var jumpTime = self.popSeq.duration() * posX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   660
				self.popSeq.jumpTo(jumpTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   661
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   662
   		});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   663
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   664
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   665
	this.ctrlPlay = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   666
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   667
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   668
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   669
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   670
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   671
		if (this.getCurrentPop().paused()) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   672
			// Play
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   673
			this.popSeq.play();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   674
		} else {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   675
			// Pause
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   676
			this.popSeq.pause();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   677
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   678
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   679
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   680
	this.ctrlNext = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   681
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   682
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   683
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   684
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   685
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   686
		if (this.popSeq.active == this.sequences.length - 1) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   687
			// We are at the last video
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   688
			location.href = this.nextPage;			
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   689
			return;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   690
		}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   691
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   692
		if (this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   693
			this.playerIsReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   694
			this.playerWaitForBeingReady = false;	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   695
		}		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   696
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   697
		// Go to the next video
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   698
		var jumpTime = this.popSeq.durationSeqs(this.popSeq.active + 1) + 0.001;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   699
		this.popSeq.jumpTo(jumpTime);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   700
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   701
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   702
	this.ctrlPrev = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   703
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   704
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   705
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   706
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   707
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   708
		var videoIndex = this.popSeq.active;
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   709
		if (videoIndex === 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   710
			// We jump to the start
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   711
			this.popSeq.jumpTo(0);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   712
		} else {
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   713
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   714
			// If we are a less than 1 sec from the sequence start, we jump to the prev sequence
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   715
			// else we jump to the start of the current sequence
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   716
			var jumpTime = this.popSeq.durationSeqs(videoIndex);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   717
			if (this.popSeq.currentTime() - jumpTime < 1) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   718
				jumpTime = this.popSeq.durationSeqs(videoIndex-1);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   719
			} 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   720
			this.popSeq.jumpTo(jumpTime + 0.001);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   721
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   722
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   723
	
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   724
	this.ctrlHdSd = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   725
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   726
		// We swape between hd/sd
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   727
		incChoice.setHD(this.hd ? 0 : 1);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   728
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   729
		// We record the current time		
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   730
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   731
		// Reload
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   732
		location.href = document.URL;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   733
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   734
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   735
	this.displayPlayButton = function(playIcon)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   736
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   737
		$(this.playButton).css({"background-position" : playIcon ? '-77px 0' : '-77px -17px'});
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   738
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   739
		 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   740
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   741
	// Tools Functions
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   742
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   743
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   744
	this.logi = function(txt)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   745
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   746
		if (this.logiEnable) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   747
			console.log("info: " + txt);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   748
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   749
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   750
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   751
	this.loge = function(txt)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   752
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   753
		console.log("error: " + txt);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   754
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   755
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   756
	this.loadJson = function(jsonFile)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   757
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   758
		var txt = this.loadTxtFile(jsonFile);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   759
		return JSON.parse(txt);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   760
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   761
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   762
	this.loadTxtFile = function(jsonFile)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   763
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   764
		var xhr = new XMLHttpRequest();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   765
		xhr.open("GET", jsonFile, false);  
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   766
		xhr.overrideMimeType('text/plain; charset=x-user-defined');
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   767
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   768
		try {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   769
			xhr.send(null); 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   770
		} catch(e) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   771
			return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   772
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   773
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   774
		if (xhr.status == 404) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   775
			return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   776
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   777
		
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   778
		var buffer;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   779
		if (xhr.responseType == "arraybuffer") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   780
			buffer = xhr.response;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   781
		} else if (xhr.mozResponseArrayBuffer === null) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   782
			buffer = xhr.mozResponseArrayBuffer;  
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   783
		} else {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   784
			buffer = xhr.response;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   785
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   786
		return buffer;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   787
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   788
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   789
	this.random = function(min, max)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   790
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   791
		return Math.floor((Math.random()*(max-min))+min);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   792
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   793
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   794
	this.secondsToTime = function(sec)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   795
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   796
		var minutes = Math.floor(sec / 60);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   797
		var seconds = Math.floor(sec - minutes * 60);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   798
		if (seconds < 10) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   799
			seconds = "0" + seconds;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   800
		}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   801
		return "" + minutes + "'" + seconds + "''";
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   802
	};
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   803
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   804
	this.sequenceToString = function(index)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   805
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   806
		return JSON.stringify(this.sequences[index]);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   807
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   808
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   809
	this.getSupportedVideoExt = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   810
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   811
		var v = document.createElement("video");
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   812
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   813
		if (v.canPlayType) {		    
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   814
		    // Check for Webm support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   815
		    if (v.canPlayType('video/webm; codecs="vp8, vorbis"') !== "") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   816
		    	return "webm";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   817
		    }
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   818
		    // Check for MPEG-4 support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   819
		    if (v.canPlayType('video/mp4; codecs="mp4v.20.8"' ) !== "") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   820
				return "mp4";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   821
		    }
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   822
		    // Check for h264 support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   823
		    if ((v.canPlayType('video/mp4; codecs="avc1.42E01E"' ) !== "" || v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'))) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   824
		    	return "mp4";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   825
		    }
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   826
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   827
		return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   828
	};
80
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   829
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   830
	this.createUrlVideosIndex = function(index1, index2, index3)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   831
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   832
		return ((index1 << 16) | (index2 << 8) | index3) << 4;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   833
	}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   834
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   835
	this.readUrlVideosIndex = function()
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   836
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   837
		var query = window.location.search.substring(1);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   838
		if (query.length < 0) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   839
			return;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   840
		}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   841
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   842
		var number = parseInt(query);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   843
		number = this.createUrlVideosIndex(20, 30, 44);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   844
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   845
		console.log("query: " + number);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   846
		console.log(n);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 78
diff changeset
   847
	};
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   848
}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   849
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   850
var incPlayer = new IncPlayer();