Skip to content

Commit 1f5edb9

Browse files
committed
Make Graphics._playVideo work with VFS
1 parent 320c32e commit 1f5edb9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

www/mods/oneloader/oneloader-fix-videos.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
let old = PIXI.VideoBaseTexture.fromUrl;
33
PIXI.VideoBaseTexture.fromUrl = function fromUrl(videoSrc, scaleMode, crossorigin, autoPlay) {
44
if (typeof videoSrc === "string" && videoSrc.startsWith("movies/")) {
5+
window._logLine("YANFLY VIDEO " + videoSrc);
56
let videoData = _vfs_resolve_file_sync(videoSrc);
67
let b = new Blob([videoData], {type:"video/" + videoSrc.split(".")[videoSrc.split(".").length - 1]});
78
let objectURL = URL.createObjectURL(b);
89
let vidObj = old.call(this, {src: objectURL, mime: "video/" + videoSrc.split(".")[videoSrc.split(".").length - 1]}, scaleMode, crossorigin, autoPlay);
910
let a = setInterval(function( ){
1011
if (vidObj.source.readyState === 4 && (vidObj.source.buffered.end(0) >= vidObj.source.duration) && vidObj.source.ended) {
11-
window._logLine("Revoking object url");
12+
window._logLine("YANFLY VIDEO Revoking object url");
1213
URL.revokeObjectURL(objectURL);
1314
clearInterval(a);
1415
}
@@ -18,3 +19,31 @@ PIXI.VideoBaseTexture.fromUrl = function fromUrl(videoSrc, scaleMode, crossorigi
1819
old.call(this, ...arguments);
1920
}
2021
};
22+
23+
let old_stock_playvideo = Graphics._playVideo;
24+
let old_onvideoend = Graphics._onVideoEnd;
25+
let ourl = Symbol("ObjectURL");
26+
let hasRevoked = Symbol("hasRevoked");
27+
28+
Graphics._playVideo = function(src) {
29+
window._logLine("MV VIDEO " + src);
30+
let videoData = _vfs_resolve_file_sync(src);
31+
let b = new Blob([videoData], {type:"video/" + src.split(".")[src.split(".").length - 1]});
32+
if (this[ourl] && !this[hasRevoked]) URL.revokeObjectURL(this[ourl]);
33+
34+
this[ourl] = URL.createObjectURL(b);
35+
this[hasRevoked] = false;
36+
37+
old_stock_playvideo.call(this, this[ourl]);
38+
}
39+
40+
Graphics._onVideoEnd = function() {
41+
if (!this[hasRevoked]) {
42+
URL.revokeObjectURL(this[ourl]);
43+
this[hasRevoked] = true;
44+
45+
window._logLine("MV VIDEO END");
46+
window._logLine("Revoking object url");
47+
}
48+
old_onvideoend.call(this);
49+
}

0 commit comments

Comments
 (0)