Skip to content

Instantly share code, notes, and snippets.

@vixalien
Created October 26, 2023 01:34
Show Gist options
  • Save vixalien/d0a1b0e9919a0ee97fb1dbfd80540e55 to your computer and use it in GitHub Desktop.
Save vixalien/d0a1b0e9919a0ee97fb1dbfd80540e55 to your computer and use it in GitHub Desktop.
import Gst from "gi://Gst";
import GstPlay from "gi://GstPlay";
import GLib from "gi://GLib";
Gst.init(null);
const player = GstPlay.Play.new(null);
player.set_uri("file:///home/alien/Music/horizon.mp3");
const bus = player.get_message_bus();
bus.add_signal_watch();
bus.connect("message", (_, message) => {
const play_message = GstPlay.play_message_parse_type(message);
if (play_message != null) {
switch (play_message) {
case GstPlay.PlayMessage.URI_LOADED:
console.log("uri loaded");
player.play();
break;
case GstPlay.PlayMessage.ERROR:
console.log(
"error",
GstPlay.play_message_parse_error(message)[0].toString(),
);
break;
default:
console.log("message", GstPlay.play_message_get_name(play_message));
break;
}
}
});
const loop = new GLib.MainLoop(null, false);
loop.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment