Note: download any sample OGG video, e.g. from https://commons.wikimedia.org/wiki/File:Examplevideo.ogv, and rename it to video.ogx
.
-
-
Save ptomato/e180132d2313d07102d2 to your computer and use it in GitHub Desktop.
<video> via custom scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- Uncomment this and comment out the <source> element to make the video work--> | |
<!--script type="text/javascript"> | |
// http://stackoverflow.com/questions/5997839/xhr-to-load-video | |
window.onload = function() { | |
var elem = document.getElementById('video-player'); | |
var req = new XMLHttpRequest(); | |
req.onload = function () { | |
var blob_uri = URL.createObjectURL(this.response); | |
elem.appendChild(document.createElement('source')) | |
.src = blob_uri; | |
}; | |
req.responseType = 'blob'; | |
req.open('GET', 'video.ogx'); | |
req.send(null); | |
}; | |
</script--> | |
</head> | |
<body> | |
<video autoplay controls width="400" height="300" id="video-player"> | |
<source src="video.ogx" type="application/ogg"> | |
<track src="subtitles.vtt" kind="subtitle" srclang="es" label="Spanish"/> | |
</video> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WEBVTT | |
00:00:00.500 --> 00:00:02.000 | |
The Web is always changing | |
00:00:02.500 --> 00:00:04.300 | |
and the way we access it is changing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Gio from 'gi://Gio'; | |
import GLib from 'gi://GLib'; | |
import GObject from 'gi://GObject'; | |
import Gtk from 'gi://Gtk?version=4.0'; | |
import WebKit from 'gi://WebKit?version=6.0'; | |
Gtk.init(); | |
let loop = GLib.MainLoop.new(null, false); | |
let context = WebKit.WebContext.get_default(); | |
context.register_uri_scheme('custom', (request) => { | |
let path = request.get_path(); | |
let file = Gio.File.new_for_path(path); | |
let [content_type, certain] = Gio.content_type_guess(path, null); | |
printerr(path, content_type, certain); | |
try { | |
let stream = file.read(null); | |
request.finish(stream, -1, content_type); | |
} catch (error) { | |
logError(error); | |
request.finish_error(error); | |
} | |
}); | |
let w = new Gtk.Window({ | |
default_width: 450, | |
default_height: 350, | |
title: 'URI Scheme', | |
}); | |
let v = new WebKit.WebView({ | |
settings: new WebKit.Settings({ enable_developer_extras: true }), | |
}); | |
w.child = v; | |
w.connect('close-request', () => loop.quit()); | |
v.get_inspector().show(); | |
// Delay 5 seconds so you have time to start recording network requests | |
GLib.timeout_add_seconds(GLib.PRIORITY_HIGH, 5, () => { | |
v.load_uri('custom:///PATH/TO/index.html'); | |
return GLib.SOURCE_REMOVE; | |
}); | |
w.present(); | |
loop.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment