web/static/res/js/incplayer.js
author Edwin Razafimahatratra <edwin@robotalismsoft.com>
Wed, 16 Jan 2013 08:26:00 +0100
changeset 78 8c3f0b94d056
parent 49 cb8403125d4d
child 80 46b897524cc4
permissions -rw-r--r--
big commit after problems
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
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   100
	this.createPopSequence = function(words, videosIndex)
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   111
		this.choosePopSequence(words, videosIndex);
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 = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   120
       	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
   121
       	this.sequences.push(video);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   122
       	this.formatPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   123
		this.initPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   124
		this.singleVideo = true;
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   127
	this.choosePopSequence = function(wordsIndex, videosIndex)
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   131
		if (videosIndex.length == 3) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   132
			// The player got reloded, we use the previously choosen videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   133
			for (var i = 0; i < videosIndex.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   134
				this.sequences.push(this.allSequencesData.videos[videosIndex[i]]);		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   135
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   136
		} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   137
			// We choose new videos
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   138
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   139
			// Get previous used videos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   140
			var var32bits = incChoice.getChoosenVideosFlags();
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   141
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   142
			// Choose videos according to the chosen words
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   143
			for (var i = 0; i < wordsIndex.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   144
				var v = this.getRandomVideos(wordsIndex[i], var32bits, this.sequences);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   145
				if (v == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   146
					// We didn't find free video
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   147
					// 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
   148
					var32bits = incChoice.getChoosenVideosFlags();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   149
					v = this.getRandomVideos(wordsIndex[i], var32bits, this.sequences);
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   150
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   151
					if (v == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   152
						this.loge("We didn't find a free video");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   153
					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   154
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   155
				this.sequences.push(v);		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   156
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   157
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   158
			// Save played videos with cookies
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   159
			this.savePlayedVideos(this.sequences, true);		
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   160
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   161
			// Save chosen video with cookies
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   162
			this.saveChosenVideos(this.sequences);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   163
		}
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   164
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   165
		// Format pop sequence
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   166
		this.formatPopSequence();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   167
		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   168
		// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   169
		this.logi("choosed sequences:");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   170
		for (i = 0; i < this.sequences.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   171
			this.logi(this.sequenceToString(i));
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
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   174
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   175
	this.formatPopSequence = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   176
	{
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   177
		// Set the video file name 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   178
		var i;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   179
		for (i = 0; i < this.sequences.length; ++i) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   180
			var v = this.sequences[i];
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   181
			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   182
			// HD
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   183
			if(!this.hd) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   184
				v.src = v.src.replace("HD", "SD"); 
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   185
			}
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
			// Extention
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   188
			v.src += "." + this.videoExt;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   189
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   190
			// Set the final file
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   191
			this.sequences[i] = v;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   192
		}
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   193
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   194
		for (i = 0; i < this.sequences.length; ++i) {
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   195
			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   196
			// Get the sequence
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   197
			var seq = this.sequences[i];
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   198
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   199
			// Compute time in seconds
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   200
			var integer = Math.floor(seq.duration);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   201
			var decimal = Math.floor((seq.duration - integer) * 100);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   202
			var duration = integer * 60 + decimal;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   203
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   204
			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
   205
		}		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   206
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   207
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   208
	this.getRandomVideos = function(wordIndex, var32bits, otherVideos)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   209
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   210
		var i;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   211
		var index = parseInt(wordIndex);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   212
		var videos = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   213
		var allVideosPlayed = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   214
		var videosMatchWord = [];
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   215
		
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   216
		// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   217
		var freeVideosCount = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   218
		var wordScoreAllVideos = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   219
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   220
		// Get all videos affected by this word
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   221
		for (i = 0; i < this.allSequencesData.videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   222
			var video = this.allSequencesData.videos[i];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   223
			var wordScore = video.scoreWord[index];
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
			if (wordScore <= 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   226
				// This video can't be choosen with this word
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   227
				continue;				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   228
			}
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
			videosMatchWord.push(video); // Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   231
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   232
			video.choosen = incChoice.IsThisVideoWasPlayed(var32bits, video.index);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   233
			if (video.choosen) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   234
				// This video was already played in an another session
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   235
				continue;
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   238
			allVideosPlayed = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   239
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   240
			// Compare categories
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   241
			video.samecat = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   242
			for (var j = 0; j < otherVideos.length; ++j) { 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   243
				if (video.cat == otherVideos[j].cat) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   244
					video.samecat = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   245
					break;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   246
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   247
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   248
			if (video.samecat == true) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   249
				// 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
   250
				continue;
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
			// 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
   254
			for (var j = 0; j < wordScore; ++j) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   255
				videos.push(video);
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
			// Debug
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   259
			wordScoreAllVideos += wordScore;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   260
			++freeVideosCount;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   261
		}
78
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
		if (allVideosPlayed || !videos.length) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   264
			// All the videos asociated with the word have been played
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   265
			// 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
   266
			// 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
   267
			this.savePlayedVideos(videosMatchWord, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   268
			return null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   269
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   270
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   271
		// Choose random video
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   272
		var v = videos[this.random(0, videos.length)];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   273
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   274
		// Debug
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   277
		this.logi("---------------------------------------------------------------------");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   278
		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
   279
		this.logi("---------------------------------------------------------------------");
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
		for (i = 0; i < videosMatchWord.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   282
			var video = videosMatchWord[i];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   283
			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
   284
			if (video.choosen) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   285
				message += this.resizeString("played", 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   286
			} else if (video.samecat) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   287
				message += this.resizeString("same cat", 15);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   288
			} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   289
				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
   290
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   291
			this.logi(message);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   292
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   293
		this.logi("");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   294
		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
   295
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   296
		return v;
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   299
	this.savePlayedVideos = function(videos, markPlayed)
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
		var indexs = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   302
		for (var i = 0; i < videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   303
			indexs.push(videos[i].index);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   304
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   305
		incChoice.savePlayedVideos(indexs, markPlayed);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   306
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   307
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   308
	this.saveChosenVideos = function(videos)
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   309
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   310
		var indexs = [];
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   311
		for (var i = 0; i < videos.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   312
			indexs.push(videos[i].index);
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   313
		}
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   314
		incChoice.saveChosenVideos(indexs);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   315
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   316
	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   317
	this.resizeString = function (str, size)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   318
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   319
		while (str.length < size) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   320
			str += " ";
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
		return str;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   323
	};
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   324
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   325
	this.getWordIndex = function(word)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   326
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   327
		var words = this.allSequencesData.mots;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   328
		for (var i = 0; i < words.length; ++i) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   329
			if (words[i] == word) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   330
				return i;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   331
			}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   332
		}
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   333
		this.loge("getWordIndex erreur");
46
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   334
		return -1;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   335
	};
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 36
diff changeset
   336
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   337
	this.debugDisplayWordsIndex = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   338
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   339
		var words = this.allSequencesData.mots;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   340
		for (var i = 0; i < words.length; ++i) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   341
			this.logi(words[i] + " -> " + i);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   342
		}
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
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   345
	this.initPopSequence = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   346
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   347
		var self = this;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   348
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   349
		// Create the popcorn sequencer
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   350
		self.popSeq = Popcorn.sequence(self.videoDivId, self.sequences);
18
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
		for (var i = 0; i < self.sequences.length; ++i) {
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
			var pop = self.popSeq.eq(i);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   355
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   356
			// Hide controls
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   357
			pop.controls(false);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   358
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   359
			// Play event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   360
			self.listenEvent(pop, "playing", false, i, function(index) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   361
				self.displayPlayButton(false);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   362
				self.logi("play sequence: " + self.sequenceToString(self.popSeq.active));
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   363
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   364
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   365
			// Pause event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   366
			self.listenEvent(pop, "pause", false, i, function(index) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   367
				self.displayPlayButton(true);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   368
				self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active));
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   369
			});			
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   370
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   371
			// Ended event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   372
			self.listenEvent(pop, "ended", false, i, function(index) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   373
				self.logi("ended sequence: " + self.sequenceToString(self.popSeq.active));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   374
			});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   375
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   376
			// Timeupdate event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   377
			self.listenEvent(pop, "timeupdate", false, i, function(index) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   378
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   379
				var currentTime = self.popSeq.currentTime();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   380
				if (!self.progressCursorDrag) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   381
					// Move timeline and display the time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   382
					self.progressCursorX = self.setCursorPosition(currentTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   383
				}
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
				// Detect the sequence end
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   386
				if (self.popSeq.active == self.sequences.length-1 && currentTime >= self.popSeq.duration() - 1) {
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   387
					setTimeout(function() { 
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   388
								location.href = self.nextPage;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   389
							}, 1500);
48
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 47
diff changeset
   390
				}
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   391
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   392
78
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
			// Canplaythrough event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   395
			self.listenEvent(pop, "canplaythrough", true, i, function(index) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   396
			});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   397
			*/				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   398
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   399
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   400
		if (!this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   401
			self.popSeq.on("canplaythrough", function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   402
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   403
				self.playerIsReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   404
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   405
				// Recompute Duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   406
				self.recomputeDuration();
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
				// Automatic play
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   409
				self.ctrlPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   410
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   411
				// Unlisten event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   412
				self.popSeq.off("canplaythrough");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   413
				self.logi("the player is ready");
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   414
			});
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   415
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   416
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   417
		self.popSeq.on("cycle", function() {
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   418
			console.log("CYCLE");
47
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   419
		});
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   420
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   421
		self.popSeq.on("ended", function() {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   422
		});
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 46
diff changeset
   423
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
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   426
	this.listenEvent = function(pop, event, unlisten, index, func)
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   427
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   428
		pop.on(event, function() {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   429
			// Execute the function
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   430
			func(index);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   431
	
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   432
			if (unlisten) {		
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   433
				// Unlisten event
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   434
				pop.off(event);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   435
			}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   436
		});
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
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   439
	this.recomputeDuration = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   440
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   441
		// Recompute duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   442
		var totalDuration = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   443
		for (var j = 0; j < this.sequences.length; ++j) {			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   444
			var duration = this.popSeq.eq(j).duration();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   445
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   446
			// ofVideos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   447
			this.popSeq.inOuts.ofVideos[j].out = duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   448
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   449
			// ofClips
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   450
			this.popSeq.inOuts.ofClips[j].in = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   451
			totalDuration += duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   452
			this.popSeq.inOuts.ofClips[j].out = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   453
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   454
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   455
		// Set total duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   456
		$(this.progressDuration).html(this.secondsToTime(this.popSeq.duration()));			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   457
	};
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
	this.recomputeDurationNoAutoPlay = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   460
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   461
		// Recompute duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   462
		var totalDuration = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   463
		for (var j = 0; j <= this.popSeq.active; ++j) {			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   464
			var duration = this.popSeq.eq(j).duration();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   465
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   466
			// ofVideos
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   467
			this.popSeq.inOuts.ofVideos[j].out = duration;
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
			// ofClips
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   470
			this.popSeq.inOuts.ofClips[j].in = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   471
			totalDuration += duration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   472
			this.popSeq.inOuts.ofClips[j].out = totalDuration;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   473
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   474
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   475
		// Set total duration
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   476
		$(this.progressDuration).html(this.secondsToTime(this.popSeq.duration()));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   477
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   478
		if (incHideBar !== undefined) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   479
			incHideBar.showBarPointerOnAction(6000);					
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   480
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   481
	};
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   482
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   483
	this.getCurrentPop = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   484
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   485
		var index = this.popSeq.active;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   486
		if (index >= this.sequences.length) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   487
			index = this.sequences.length-1;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   488
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   489
		return this.popSeq.eq(index);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   490
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   491
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   492
	this.setCursorPosition = function(time)
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   493
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   494
		// Display time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   495
		$(this.progressCurrent).html(this.secondsToTime(time));
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   496
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   497
		// Move cursor timeline
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   498
		var progressCursorX = time ? ((time / this.popSeq.duration()) * (240 - 16)) : 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   499
		$(this.progressCursor).css({"left" : progressCursorX });
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   500
		$("#progress").css({"width" : progressCursorX + 8});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   501
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   502
		return progressCursorX;
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   505
	this.forceCheckPlayerIsReady = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   506
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   507
		this.playerIsReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   508
		this.playerWaitForBeingReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   509
		this.checkPlayerIsReady();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   510
	}
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
	this.checkPlayerIsReady = function()
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
		if (this.playerIsReady) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   515
			return true;
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   518
		if (this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   519
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   520
			// 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
   521
			var media = this.popSeq.eq(this.popSeq.active).media;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   522
			media.play();
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 (media.readystate === 4) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   525
				this.playerIsReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   526
				this.recomputeDurationNoAutoPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   527
				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
   528
			}
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
			if (this.playerWaitForBeingReady) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   531
				return false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   532
			}
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
			this.playerWaitForBeingReady = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   535
			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   536
			var self = this;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   537
			var mediaCanPlay = function () {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   538
				// Remove event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   539
				media.removeEventListener('canplaythrough', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   540
				media.removeEventListener('load', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   541
				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   542
				// The video is ready, play
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   543
				media.play();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   544
				self.playerIsReady = true;				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   545
				self.recomputeDurationNoAutoPlay();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   546
				console.log("ipad play event");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   547
			}			
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   548
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   549
			media.addEventListener('canplaythrough', mediaCanPlay, false);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   550
			media.addEventListener('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
			setTimeout(function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   553
				media.pause(); // Block play so it buffers before playing
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   554
			}, 1);				
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   555
		}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   556
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   557
		this.logi("can't play, the player is not ready");
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   558
		return false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   559
	}	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   560
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   561
	this.ctrlSetCursorDragFunction = function()
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   562
	{
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   563
		var self = this;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   564
		var origineX = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   565
		var posX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   566
		var maxX = 240 - 16;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   567
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   568
		var setCursorPositionX = function (x) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   569
			if (x < 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   570
				x = 0;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   571
			} else if (x > maxX) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   572
				x = maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   573
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   574
			var time = self.popSeq.duration() * x / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   575
			self.setCursorPosition(time);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   576
			return x;			
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
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   579
		var setCursorPosition = function (x) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   580
	        self.progressCursorDrag = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   581
			if (origineX == null) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   582
				origineX = x;	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   583
			} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   584
				posX = self.progressCursorX + x - origineX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   585
				posX = setCursorPositionX(posX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   586
			}
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
		this.progressCursor.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   590
	        mousedown: function() {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   591
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   592
				if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   593
					return;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   594
				}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   595
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   596
	        	$(document).on(
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   597
		        	self.ipad ? {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   598
		        		touchmove: function (e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   599
		        			e.preventDefault();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   600
							var touches = ( typeof( event.touches ) != "undefined" ) ? event.touches : event.changedTouches;		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   601
		        			setCursorPosition(touches[0].pageX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   602
	   					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   603
		        	} : {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   604
		        		mousemove: function (e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   605
		        			self.progressCursorDrag = true;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   606
		        			setCursorPosition(e.pageX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   607
	   					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   608
		        	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   609
		        );
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   610
	        }
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   611
	    });
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   612
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   613
		var progressBarX = $(self.progressBar).position().left;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   614
	    if (self.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   615
			this.progressBar.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   616
		        touchdown: function(e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   617
					if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   618
						return;
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
		        	e.preventDefault();
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   622
					var touches = ( typeof( event.touches ) != "undefined" ) ? event.touches : event.changedTouches;		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   623
		        	PosX = touches[0].pageX - progressBarX - 8;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   624
		        	PosX = setCursorPositionX(PosX);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   625
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   626
	        		// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   627
					var jumpTime = self.popSeq.duration() * PosX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   628
					self.popSeq.jumpTo(jumpTime);
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
		} else {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   632
			this.progressBar.on({
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   633
		        mousedown: function(e) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   634
					if (!self.checkPlayerIsReady()) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   635
						return;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   636
					}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   637
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   638
		        	PosX = e.pageX - progressBarX - 8;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   639
		        	PosX = setCursorPositionX(PosX);
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
	        		// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   642
					var jumpTime = self.popSeq.duration() * PosX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   643
					self.popSeq.jumpTo(jumpTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   644
		        }
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   645
		    });
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
		$(document).mouseup(function(){
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   649
			if (self.progressCursorDrag) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   650
		        self.progressCursorDrag = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   651
				origineX = null;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   652
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   653
		        // Remove event
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   654
				$(document).off(self.ipad ? "touchmove" : "mousemove");
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
				// Seek time
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   657
				var jumpTime = self.popSeq.duration() * posX / maxX;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   658
				self.popSeq.jumpTo(jumpTime);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   659
			}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   660
   		});
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   661
	}
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   662
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   663
	this.ctrlPlay = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   664
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   665
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   666
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   667
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   668
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   669
		if (this.getCurrentPop().paused()) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   670
			// Play
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   671
			this.popSeq.play();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   672
		} else {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   673
			// Pause
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   674
			this.popSeq.pause();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   675
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   676
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   677
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   678
	this.ctrlNext = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   679
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   680
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   681
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   682
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   683
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   684
		if (this.popSeq.active == this.sequences.length - 1) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   685
			// We are at the last video
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   686
			location.href = this.nextPage;			
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   687
			return;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   688
		}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   689
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   690
		if (this.ipad) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   691
			this.playerIsReady = false;
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   692
			this.playerWaitForBeingReady = false;	
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   693
		}		
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   694
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   695
		// Go to the next video
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   696
		var jumpTime = this.popSeq.durationSeqs(this.popSeq.active + 1) + 0.001;
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   697
		this.popSeq.jumpTo(jumpTime);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   698
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   699
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   700
	this.ctrlPrev = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   701
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   702
		if (!this.checkPlayerIsReady()) {
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   703
			return;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   704
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   705
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   706
		var videoIndex = this.popSeq.active;
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   707
		if (videoIndex === 0) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   708
			// We jump to the start
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   709
			this.popSeq.jumpTo(0);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   710
		} else {
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   711
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   712
			// 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
   713
			// else we jump to the start of the current sequence
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   714
			var jumpTime = this.popSeq.durationSeqs(videoIndex);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   715
			if (this.popSeq.currentTime() - jumpTime < 1) {
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   716
				jumpTime = this.popSeq.durationSeqs(videoIndex-1);
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   717
			} 
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   718
			this.popSeq.jumpTo(jumpTime + 0.001);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   719
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   720
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   721
	
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   722
	this.ctrlHdSd = function()
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   723
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   724
		// We swape between hd/sd
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   725
		incChoice.setHD(this.hd ? 0 : 1);
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   726
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   727
		// We record the current time		
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   728
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   729
		// Reload
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   730
		location.href = document.URL;
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   731
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   732
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   733
	this.displayPlayButton = function(playIcon)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   734
	{
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   735
		$(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
   736
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   737
		 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   738
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   739
	// Tools Functions
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   740
	// --------------------------------------------------------------------------------------------------------------------
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   741
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   742
	this.logi = function(txt)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   743
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   744
		if (this.logiEnable) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   745
			console.log("info: " + txt);
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
	this.loge = function(txt)
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
		console.log("error: " + txt);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   752
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   753
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   754
	this.loadJson = function(jsonFile)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   755
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   756
		var txt = this.loadTxtFile(jsonFile);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   757
		return JSON.parse(txt);
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
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   760
	this.loadTxtFile = function(jsonFile)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   761
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   762
		var xhr = new XMLHttpRequest();
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   763
		xhr.open("GET", jsonFile, false);  
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   764
		xhr.overrideMimeType('text/plain; charset=x-user-defined');
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
		try {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   767
			xhr.send(null); 
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   768
		} catch(e) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   769
			return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   770
		}
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
		if (xhr.status == 404) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   773
			return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   774
		}
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
		var buffer;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   777
		if (xhr.responseType == "arraybuffer") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   778
			buffer = xhr.response;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   779
		} else if (xhr.mozResponseArrayBuffer === null) {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   780
			buffer = xhr.mozResponseArrayBuffer;  
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   781
		} else {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   782
			buffer = xhr.response;
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   783
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   784
		return buffer;
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
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   787
	this.random = function(min, max)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   788
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   789
		return Math.floor((Math.random()*(max-min))+min);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   790
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   791
36
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   792
	this.secondsToTime = function(sec)
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   793
	{
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   794
		var minutes = Math.floor(sec / 60);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   795
		var seconds = Math.floor(sec - minutes * 60);
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   796
		if (seconds < 10) {
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   797
			seconds = "0" + seconds;
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   798
		}
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   799
		return "" + minutes + "'" + seconds + "''";
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   800
	};
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 19
diff changeset
   801
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   802
	this.sequenceToString = function(index)
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   803
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   804
		return JSON.stringify(this.sequences[index]);
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   805
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   806
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   807
	this.getSupportedVideoExt = function()
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   808
	{
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   809
		var v = document.createElement("video");
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   810
78
8c3f0b94d056 big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents: 49
diff changeset
   811
		if (v.canPlayType) {		    
18
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   812
		    // Check for Webm support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   813
		    if (v.canPlayType('video/webm; codecs="vp8, vorbis"') !== "") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   814
		    	return "webm";
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
		    // Check for MPEG-4 support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   817
		    if (v.canPlayType('video/mp4; codecs="mp4v.20.8"' ) !== "") {
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   818
				return "mp4";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   819
		    }
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   820
		    // Check for h264 support
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   821
		    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
   822
		    	return "mp4";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   823
		    }
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   824
		}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   825
		return "";
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   826
	};
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   827
}
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   828
f6232b308fbd base du player niveau 1
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
diff changeset
   829
var incPlayer = new IncPlayer();