Created
May 22, 2024 22:24
-
-
Save pojntfx/9bd131bb0dc55a23ad31f63bf6e7dd11 to your computer and use it in GitHub Desktop.
Play a video from hTorrent with GJS and GtkVideo
This file contains hidden or 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
| using Gtk 4.0; | |
| using Adw 1; | |
| Adw.StatusPage page { | |
| title: _("Video"); | |
| description: _("Display video with media controls"); | |
| Box { | |
| orientation: vertical; | |
| halign: center; | |
| Video video { | |
| autoplay: true; | |
| loop: true; | |
| width-request: 540; | |
| height-request: 540; | |
| } | |
| Button play_pause_button { | |
| label: _("Play/Pause"); | |
| margin-top: 12; | |
| } | |
| Button reset_button { | |
| label: _("Reset"); | |
| margin-top: 12; | |
| } | |
| LinkButton { | |
| label: _("API Reference"); | |
| uri: "https://docs.gtk.org/gtk4/class.Video.html"; | |
| margin-top: 12; | |
| } | |
| } | |
| } |
This file contains hidden or 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 Gtk from "gi://Gtk"; | |
| const video = workbench.builder.get_object("video"); | |
| const playPauseButton = workbench.builder.get_object("play_pause_button"); | |
| const resetButton = workbench.builder.get_object("reset_button"); | |
| // video.file = Gio.File.new_for_uri(workbench.resolve("./workbench-video.mp4")); | |
| video.file = Gio.File.new_for_uri( | |
| "http://admin:myapipassword@localhost:1337/stream?magnet=magnet%3A%3Fxt%3Durn%3Abtih%3A08ada5a7a6183aae1e09d831df6748d566095a10%26dn%3DSintel%26tr%3Dudp%253A%252F%252Fexplodie.org%253A6969%26tr%3Dudp%253A%252F%252Ftracker.coppersurfer.tk%253A6969%26tr%3Dudp%253A%252F%252Ftracker.empire-js.us%253A1337%26tr%3Dudp%253A%252F%252Ftracker.leechers-paradise.org%253A6969%26tr%3Dudp%253A%252F%252Ftracker.opentrackr.org%253A1337%26tr%3Dwss%253A%252F%252Ftracker.btorrent.xyz%26tr%3Dwss%253A%252F%252Ftracker.fastcast.nz%26tr%3Dwss%253A%252F%252Ftracker.openwebtorrent.com%26ws%3Dhttps%253A%252F%252Fwebtorrent.io%252Ftorrents%252F%26xs%3Dhttps%253A%252F%252Fwebtorrent.io%252Ftorrents%252Fsintel.torrent&path=Sintel%2FSintel.mp4", | |
| ); | |
| playPauseButton.connect("clicked", () => { | |
| const media_stream = video.media_stream; | |
| if (media_stream.playing) { | |
| media_stream.pause(); | |
| playPauseButton.label = "Play"; | |
| } else { | |
| media_stream.play(); | |
| playPauseButton.label = "Pause"; | |
| } | |
| }); | |
| resetButton.connect("clicked", () => { | |
| video.mediaStream.seek(0); | |
| }); | |
| setInterval(() => { | |
| console.log(video.mediaStream.timestamp); | |
| }, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment