vapi changes
This commit is contained in:
parent
d053e68744
commit
d17c538ccb
2 changed files with 41 additions and 58 deletions
|
@ -55,16 +55,20 @@ class Playbin : GLib.Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_play_queue_items_changed (ListModel play_queue, uint position, uint removed, uint added) {
|
private void on_play_queue_items_changed (ListModel play_queue, uint position, uint removed, uint added) {
|
||||||
try {
|
for (uint i = 0; i < removed; i += 1) {
|
||||||
for (uint i = 0; i < removed; i += 1) {
|
assert (this.mpv.command ({
|
||||||
assert (this.mpv.command ({"playlist-remove", position.to_string ()}) >= 0);
|
"playlist-remove",
|
||||||
}
|
position.to_string (),
|
||||||
|
}) >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < added; i += 1) {
|
for (uint i = 0; i < added; i += 1) {
|
||||||
assert (this.mpv.command ({"loadfile", this.api.stream_uri (((Subsonic.Song) play_queue.get_item (position+i)).id), "insert-at-play", (position+i).to_string ()}) >= 0);
|
assert (this.mpv.command ({
|
||||||
}
|
"loadfile",
|
||||||
} catch (Error e) {
|
this.api.stream_uri (((Subsonic.Song) play_queue.get_item (position+i)).id),
|
||||||
error ("could not update mpv playlist: %s\n", e.message);
|
"insert-at-play",
|
||||||
|
(position+i).to_string (),
|
||||||
|
}) >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +82,6 @@ class Playbin : GLib.Object {
|
||||||
assert (this.mpv.observe_property (1, "duration", Mpv.Format.DOUBLE) >= 0);
|
assert (this.mpv.observe_property (1, "duration", Mpv.Format.DOUBLE) >= 0);
|
||||||
assert (this.mpv.observe_property (2, "playlist-pos", Mpv.Format.INT64) >= 0);
|
assert (this.mpv.observe_property (2, "playlist-pos", Mpv.Format.INT64) >= 0);
|
||||||
|
|
||||||
|
|
||||||
this.mpv.wakeup_callback = () => {
|
this.mpv.wakeup_callback = () => {
|
||||||
Idle.add (() => {
|
Idle.add (() => {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -87,37 +90,32 @@ class Playbin : GLib.Object {
|
||||||
|
|
||||||
switch (event.event_id) {
|
switch (event.event_id) {
|
||||||
case Mpv.EventId.PROPERTY_CHANGE:
|
case Mpv.EventId.PROPERTY_CHANGE:
|
||||||
|
var data = event.parse_property ();
|
||||||
switch (event.reply_userdata) {
|
switch (event.reply_userdata) {
|
||||||
case 0:
|
case 0:
|
||||||
var data = (Mpv.EventProperty *) event.data;
|
|
||||||
assert (data.name == "time-pos");
|
assert (data.name == "time-pos");
|
||||||
if (data.format == Mpv.Format.NONE) {
|
if (data.format == Mpv.Format.NONE) {
|
||||||
this.position = 0.0;
|
this.position = 0.0;
|
||||||
} else {
|
} else {
|
||||||
assert (data.format == Mpv.Format.DOUBLE);
|
this.position = data.parse_double ();
|
||||||
this.position = * (double *) data.data;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
var data = (Mpv.EventProperty *) event.data;
|
|
||||||
assert (data.name == "duration");
|
assert (data.name == "duration");
|
||||||
if (data.format == Mpv.Format.NONE) {
|
if (data.format == Mpv.Format.NONE) {
|
||||||
this.duration = 0.0;
|
this.duration = 0.0;
|
||||||
} else {
|
} else {
|
||||||
assert (data.format == Mpv.Format.DOUBLE);
|
this.duration = data.parse_double ();
|
||||||
this.duration = * (double *) data.data;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
var data = (Mpv.EventProperty *) event.data;
|
|
||||||
assert (data.name == "playlist-pos");
|
assert (data.name == "playlist-pos");
|
||||||
if (data.format == Mpv.Format.NONE) {
|
if (data.format == Mpv.Format.NONE) {
|
||||||
this.play_queue_position = 0;
|
this.play_queue_position = 0;
|
||||||
} else {
|
} else {
|
||||||
assert (data.format == Mpv.Format.INT64);
|
this.play_queue_position = (uint) data.parse_int64 ();
|
||||||
this.play_queue_position = (uint) * (int64 *) data.data;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -127,36 +125,13 @@ class Playbin : GLib.Object {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mpv.EventId.START_FILE:
|
|
||||||
// ignore
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mpv.EventId.FILE_LOADED:
|
case Mpv.EventId.FILE_LOADED:
|
||||||
this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position);
|
this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position);
|
||||||
this.now_playing ();
|
this.now_playing ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mpv.EventId.PLAYBACK_RESTART:
|
|
||||||
// ignore
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mpv.EventId.SEEK:
|
|
||||||
// ignore
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mpv.EventId.END_FILE:
|
|
||||||
// ignore
|
|
||||||
break;
|
|
||||||
|
|
||||||
// deprecated, ignore
|
|
||||||
case Mpv.EventId.IDLE:
|
|
||||||
case Mpv.EventId.TICK:
|
|
||||||
// uninteresting, ignore
|
|
||||||
case Mpv.EventId.AUDIO_RECONFIG:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print ("got unimplemented %s\n", event.event_id.to_string ());
|
// ignore by default
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Mpv {
|
||||||
public Error initialize ();
|
public Error initialize ();
|
||||||
|
|
||||||
[CCode (cname = "mpv_wait_event")]
|
[CCode (cname = "mpv_wait_event")]
|
||||||
public unowned Event *wait_event (double timeout);
|
public unowned Event? wait_event (double timeout);
|
||||||
|
|
||||||
public WakeupCallback wakeup_callback {
|
public WakeupCallback wakeup_callback {
|
||||||
[CCode (cname = "mpv_set_wakeup_callback")] set;
|
[CCode (cname = "mpv_set_wakeup_callback")] set;
|
||||||
|
@ -63,9 +63,7 @@ namespace Mpv {
|
||||||
}
|
}
|
||||||
|
|
||||||
[CCode (cname = "mpv_command")]
|
[CCode (cname = "mpv_command")]
|
||||||
public Error command (
|
public Error command ([CCode (array_length = false)] string[] args);
|
||||||
[CCode (array_length = false)]
|
|
||||||
string[] args);
|
|
||||||
|
|
||||||
[CCode (cname = "mpv_observe_property")]
|
[CCode (cname = "mpv_observe_property")]
|
||||||
public Error observe_property (uint64 reply_userdata, string name, Format format);
|
public Error observe_property (uint64 reply_userdata, string name, Format format);
|
||||||
|
@ -104,30 +102,40 @@ namespace Mpv {
|
||||||
PROPERTY_CHANGE,
|
PROPERTY_CHANGE,
|
||||||
QUEUE_OVERFLOW,
|
QUEUE_OVERFLOW,
|
||||||
HOOK,
|
HOOK,
|
||||||
|
|
||||||
// deprecated
|
|
||||||
IDLE,
|
|
||||||
TICK,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CCode (cname = "mpv_event")]
|
[CCode (cname = "mpv_event", destroy_function = "", has_type_id = false, has_copy_function = false)]
|
||||||
public struct Event {
|
public struct Event {
|
||||||
EventId event_id;
|
EventId event_id;
|
||||||
Error error;
|
Error error;
|
||||||
uint64 reply_userdata;
|
uint64 reply_userdata;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
|
public unowned EventProperty? parse_property ()
|
||||||
|
requires (event_id == EventId.PROPERTY_CHANGE)
|
||||||
|
requires (error >= 0)
|
||||||
|
{
|
||||||
|
return (Mpv.EventProperty?) data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[CCode (cname = "mpv_event_start_file")]
|
[CCode (cname = "mpv_event_property", destroy_function = "", has_type_id = false, has_copy_function = false)]
|
||||||
public struct EventStartFile {
|
|
||||||
int64 playlist_entry_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
[CCode (cname = "mpv_event_property")]
|
|
||||||
public struct EventProperty {
|
public struct EventProperty {
|
||||||
string name;
|
string name;
|
||||||
Format format;
|
Format format;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
|
public int64 parse_int64 ()
|
||||||
|
requires (format == Format.INT64)
|
||||||
|
{
|
||||||
|
return * (int64 *) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double parse_double ()
|
||||||
|
requires (format == Format.DOUBLE)
|
||||||
|
{
|
||||||
|
return * (double *) data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue