Compare commits

...

2 commits

Author SHA1 Message Date
72c8507126 catch end_file errors 2024-10-18 22:13:28 +02:00
d43857646d remove unused class 2024-10-18 21:54:12 +02:00
2 changed files with 47 additions and 17 deletions

View file

@ -4,15 +4,6 @@ enum PlaybinState {
PLAYING,
}
private class SourceFuncWrapper {
public SourceFunc inner;
public SourceFuncWrapper () {
this.inner = null;
}
}
class Playbin : GLib.Object {
private Mpv.Handle mpv = new Mpv.Handle ();
@ -22,8 +13,12 @@ class Playbin : GLib.Object {
public int volume {
get { return _volume; }
set {
_volume = value;
assert (mpv.set_property_int64 ("volume", value) >= 0);
var ret = mpv.set_property_int64 ("volume", value);
if (ret >= 0) {
_volume = value;
} else {
warning ("failed to set volume: %s", ret.to_string ());
}
}
}
@ -31,8 +26,12 @@ class Playbin : GLib.Object {
public bool mute {
get { return _mute; }
set {
_mute = value;
assert (mpv.set_property_flag ("mute", value) >= 0);
var ret = mpv.set_property_flag ("mute", value);
if (ret >= 0) {
_mute = value;
} else {
warning ("failed to set mute status: %s", ret.to_string ());
}
}
}
@ -130,6 +129,13 @@ class Playbin : GLib.Object {
this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position);
this.now_playing ();
break;
case Mpv.EventId.END_FILE:
var data = event.parse_end_file ();
if (data.error < 0) {
warning ("playback of track aborted: %s", data.error.to_string ());
}
break;
default:
// ignore by default
@ -162,7 +168,7 @@ class Playbin : GLib.Object {
// TODO: abstract away this handling around mpv api a bit for auto debug printing
var ret = this.mpv.set_property_flag("pause", true);
if (ret != 0) {
GLib.debug ("failed to set state to paused (%d): %s\n", ret, ret.to_string());
GLib.debug ("failed to set state to paused (%d): %s", ret, ret.to_string());
}
}
@ -172,7 +178,7 @@ class Playbin : GLib.Object {
GLib.debug ("setting state to playing");
var ret = this.mpv.set_property_flag("pause", false);
if (ret != 0) {
GLib.debug ("failed to set state to playing (%d): %s\n", ret, ret.to_string());
GLib.debug ("failed to set state to playing (%d): %s", ret, ret.to_string());
}
}

View file

@ -48,7 +48,7 @@ namespace Mpv {
}
[CCode (cname = "mpv_set_property")]
public Error set_property (string name, Format format, void *data);
private Error set_property (string name, Format format, void *data);
[CCode (cname = "mpv_set_property_string")]
public Error set_property_string (string name, string value);
@ -115,7 +115,14 @@ namespace Mpv {
requires (event_id == EventId.PROPERTY_CHANGE)
requires (error >= 0)
{
return (Mpv.EventProperty?) data;
return (EventProperty?) data;
}
public unowned EventEndFile? parse_end_file ()
requires (event_id == EventId.END_FILE)
requires (error >= 0)
{
return (EventEndFile?) data;
}
}
@ -138,4 +145,21 @@ namespace Mpv {
}
}
[CCode (cname = "mpv_event_end_file", destroy_function = "", has_type_id = false, has_copy_function = false)]
public struct EventEndFile {
EndFileReason reason;
Error error;
int64 playlist_entry_id;
int playlist_insert_num_entries;
}
[CCode (cname = "mpv_end_file_reason", cprefix = "MPV_END_FILE_REASON_", has_type_id = false)]
public enum EndFileReason {
EOF,
STOP,
QUIT,
ERROR,
REDIRECT,
}
}