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