-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwplayerInterface.js
executable file
·163 lines (138 loc) · 3.95 KB
/
jwplayerInterface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (c) 2016, Philippe Brouard. All rights reserved. Use of this source code
// is governed by a GNU V3 license that can be found in the LICENSE file.
window.addEventListener('complexAction', eventHandlerComplexAction, false);
window.addEventListener('setupAction', eventHandlerSetup, false);
function eventHandlerSetup(e) {
//alert('detail: ' + e.detail.imageFileIn + ' ' + e.detail.videoFile + ' ' + e.detail.imageFileOut);
//repéré un problème avec CustomEvent dans Dart qui est sérialisé, il faut ensuite le désérialiser (dart 1.15)
var s = e.detail.toString();
var d = JSON.parse(s);
//console.log(d.imageFileIn + " " + d.videoFile + " " + d.imageFileOut);
JwplayerControl.init(d.imageFileIn, d.videoFile, d.imageFileOut);
JwplayerControl.setup();
}
function eventHandlerComplexAction(e) {
//alert('detail: ' + e.detail.imageFileIn + ' ' + e.detail.videoFile + ' ' + e.detail.imageFileOut);
//repéré un problème avec CustomEvent dans Dart qui est sérialisé, il faut ensuite le désérialiser (dart 1.15)
var s = e.detail.toString();
var d = JSON.parse(s);
JwplayerControl.init(d.imageFileIn, d.videoFile, d.imageFileOut);
if (d.autostart == "false")
{
var mode = JwplayerControl.getMode();
if (mode == "flash")
{
JwplayerControl.load();
} else {
JwplayerControl.unset();
JwplayerControl.setup();
}
}
else {
JwplayerControl.loadandplay();
}
var theEle = document.getElementById('interactions');
theEle.className = 'hide';
}
/* ---------------------- */
/* -------------------------- */
var JwplayerControl = function () {
var imageFileIn = "";
var videoFile = "";
var imageFileOut = "";
var autostart = "";
var mode = "";
var mediaFolder = "";
function complete() {
//alert("complete");
autostart = "false";
jwplayer("thePlayer").load([{
image: imageFileOut,
sources: [{
file: videoFile
}]
}]);
window.dispatchEvent(new CustomEvent("videoComplete", {"detail":{"ended":true}}));
}
function playlistLoaded() {
//alert("playlist: " + autostart);
//if (autostart == "false") jwplayer("thePlayer").stop();
//var state = jwplayer("thePlayer").getState();
//alert("playlistLoaded state: " + state);
//if (autostart != "true") jwplayer("thePlayer").pause(true);
//if (autostart == "false") jwplayer("thePlayer").pause(true);
}
return {
init: function(i, v, o) {
mediaFolder = "medias/";
imageFileIn = mediaFolder+i;
videoFile = mediaFolder+v;
imageFileOut = mediaFolder+o;
},
setup: function() {
var playerInstance = jwplayer("thePlayer");
playerInstance.setup({
playlist: [{
image: imageFileIn,
sources: [{
file: videoFile
}]
}],
height: "100%",
primary: "html5",
width: "100%",
analytics: {
enabled: false
},
events:{
onComplete: function() {
complete();
},
onPlaylist: function() {
playlistLoaded();
}
},
skin: "skins/sixalt.xml",
logo: {
hide: false,
file: "images/mylogo.png"
}
});
},
unset: function() {
var playerInstance = jwplayer("thePlayer");
playerInstance.remove();
},
load: function() {
autostart = "false";
var playerInstance = jwplayer("thePlayer");
playerInstance.load([{
image: imageFileIn,
sources: [{
file: videoFile
}]
}]);
//jwplayer("thePlayer").play();
},
loadandplay: function() {
autostart = "true";
var playerInstance = jwplayer("thePlayer");
playerInstance.load([{
image: imageFileIn,
sources: [{
file: videoFile
}]
}]);
playerInstance.play();
},
play: function() {
var playerInstance = jwplayer("thePlayer");
playerInstance.play();
},
getMode: function() {
var playerInstance = jwplayer("thePlayer");
mode = playerInstance.getRenderingMode();
return mode;
}
};
}();