| author | ymh <ymh.work@gmail.com> |
| Fri, 18 Oct 2024 10:24:57 +0200 | |
| changeset 1074 | 231ea5ea7de4 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
1 |
import jQuery from "jquery"; |
| 958 | 2 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
3 |
const PopcornPlayer = function (ns) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
4 |
return class extends ns.Widgets.Widget { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
5 |
constructor(player, config) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
6 |
super(player, config); |
| 958 | 7 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
8 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
9 |
/* A Popcorn-based player for HTML5 Video, Youtube and Vimeo */ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
10 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
11 |
static defaults = {}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
12 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
13 |
draw() { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
14 |
if (typeof this.video === "undefined") { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
15 |
this.video = this.media.video; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
16 |
} |
|
1069
2409cb4cebaf
getting various changes from github
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
17 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
18 |
if (this.url_transform) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
19 |
this.video = this.url_transform(this.video); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
20 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
21 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
22 |
var _url = this.video; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
23 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
24 |
if (/^(https?:\/\/)?(www\.)?youtube\.com/.test(this.video)) { |
| 959 | 25 |
/* YOUTUBE */ |
26 |
var _urlparts = this.video.split(/[?&]/), |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
27 |
_params = {}; |
| 959 | 28 |
for (var i = 1; i < _urlparts.length; i++) { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
29 |
var _ppart = _urlparts[i].split("="); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
30 |
_params[_ppart[0]] = decodeURIComponent(_ppart[1]); |
| 959 | 31 |
} |
32 |
_params.controls = 0; |
|
33 |
_params.modestbranding = 1; |
|
| 967 | 34 |
if (this.autostart || this.autoplay) { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
35 |
_params.autoplay = 1; |
| 967 | 36 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
37 |
_url = _urlparts[0] + "?" + jQuery.param(_params); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
38 |
} // else { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
39 |
// /* DEFAULT HTML5 */ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
40 |
// var _tmpId = ns._.uniqueId("popcorn"), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
41 |
// _videoEl = jQuery('<video>'); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
42 |
// _videoEl.attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
43 |
// id : _tmpId, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
44 |
// width : this.width, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
45 |
// height : this.height || undefined |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
46 |
// }); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
47 |
// if(typeof this.video === "string"){ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
48 |
// _videoEl.attr("src",this.video); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
49 |
// } else { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
50 |
// for (var i = 0; i < this.video.length; i++) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
51 |
// var _srcNode = jQuery('<source>'); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
52 |
// _srcNode.attr({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
53 |
// src: this.video[i].src, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
54 |
// type: this.video[i].type |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
55 |
// }); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
56 |
// _videoEl.append(_srcNode); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
57 |
// } |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
58 |
// } |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
59 |
// this.$.html(_videoEl); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
60 |
// } |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
61 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
62 |
var _popcorn = global.Popcorn.smart("#" + this.container, _url); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
63 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
64 |
if (this.autostart || this.autoplay) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
65 |
_popcorn.autoplay(true); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
66 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
67 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
68 |
var _media = this.media; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
69 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
70 |
// Binding functions to Popcorn |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
71 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
72 |
_media.on("setcurrenttime", function (_milliseconds) { |
| 970 | 73 |
_popcorn.currentTime(_milliseconds / 1000); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
74 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
75 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
76 |
_media.on("setvolume", function (_vol) { |
| 970 | 77 |
_popcorn.volume(_vol); |
78 |
_media.volume = _vol; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
79 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
80 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
81 |
_media.on("setmuted", function (_muted) { |
| 970 | 82 |
_popcorn.muted(_muted); |
83 |
_media.muted = _muted; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
84 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
85 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
86 |
_media.on("setplay", function () { |
| 970 | 87 |
_popcorn.play(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
88 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
89 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
90 |
_media.on("setpause", function () { |
| 970 | 91 |
_popcorn.pause(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
92 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
93 |
_media.on("settimerange", function (_timeRange) { |
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
94 |
_media.timeRange = _timeRange; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
95 |
try { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
96 |
if ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
97 |
_media.getCurrentTime() > _timeRange[0] || |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
98 |
_media.getCurrentTime() < _timeRange |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
99 |
) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
100 |
_popcorn.currentTime(_timeRange[0] / 1000); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
101 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
102 |
} catch (err) {} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
103 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
104 |
_media.on("resettimerange", function () { |
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1013
diff
changeset
|
105 |
_media.timeRange = false; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
106 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
107 |
// Binding Popcorn events to media |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
108 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
109 |
function getVolume() { |
| 970 | 110 |
_media.muted = _popcorn.muted(); |
111 |
_media.volume = _popcorn.volume(); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
112 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
113 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
114 |
_popcorn.on("loadedmetadata", function () { |
| 970 | 115 |
getVolume(); |
116 |
_media.trigger("loadedmetadata"); |
|
117 |
_media.trigger("volumechange"); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
118 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
119 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
120 |
_popcorn.on("timeupdate", function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
121 |
_media.trigger( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
122 |
"timeupdate", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
123 |
new ns.Model.Time(1000 * _popcorn.currentTime()) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
124 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
125 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
126 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
127 |
_popcorn.on("volumechange", function () { |
| 970 | 128 |
getVolume(); |
129 |
_media.trigger("volumechange"); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
130 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
131 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
132 |
_popcorn.on("play", function (e) { |
| 970 | 133 |
_media.trigger("play"); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
134 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
135 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
136 |
_popcorn.on("pause", function () { |
| 970 | 137 |
_media.trigger("pause"); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
138 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
139 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
140 |
_popcorn.on("seeked", function () { |
| 970 | 141 |
_media.trigger("seeked"); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
142 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
143 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
144 |
}; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
145 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
146 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
147 |
export { PopcornPlayer }; |