some async
This commit is contained in:
parent
f436557bf5
commit
2b2ace0f5c
3 changed files with 40 additions and 1 deletions
|
@ -4,6 +4,11 @@ public enum PlaybinState {
|
|||
PLAYING,
|
||||
}
|
||||
|
||||
private struct CommandCallback {
|
||||
unowned SourceFunc callback;
|
||||
int error;
|
||||
}
|
||||
|
||||
public class Playbin : GLib.Object {
|
||||
private Mpv.Handle mpv = new Mpv.Handle ();
|
||||
|
||||
|
@ -55,6 +60,16 @@ public class Playbin : GLib.Object {
|
|||
// try to prevent wait_event to be called twice
|
||||
private bool is_handling_event = false;
|
||||
|
||||
private async Mpv.Error mpv_command_async (string[] args) {
|
||||
CommandCallback cc = {};
|
||||
|
||||
this.mpv.command_async ((uint64) &cc, args);
|
||||
|
||||
cc.callback = this.mpv_command_async.callback;
|
||||
yield;
|
||||
return cc.error;
|
||||
}
|
||||
|
||||
public Playbin () {
|
||||
this._play_queue = new ListStore (typeof (Subsonic.Song));
|
||||
|
||||
|
@ -169,6 +184,12 @@ public class Playbin : GLib.Object {
|
|||
|
||||
break;
|
||||
|
||||
case Mpv.EventId.COMMAND_REPLY:
|
||||
unowned CommandCallback *cc = (CommandCallback *) event.reply_userdata;
|
||||
cc.error = event.error;
|
||||
cc.callback ();
|
||||
break;
|
||||
|
||||
default:
|
||||
// ignore by default
|
||||
break;
|
||||
|
@ -268,7 +289,7 @@ public class Playbin : GLib.Object {
|
|||
}
|
||||
|
||||
public void append_track (Subsonic.Song song) {
|
||||
assert (this.mpv.command({
|
||||
assert (this.mpv.command ({
|
||||
"loadfile",
|
||||
this.api.stream_uri (song.id),
|
||||
"append",
|
||||
|
@ -277,6 +298,18 @@ public class Playbin : GLib.Object {
|
|||
this._play_queue.append (song);
|
||||
}
|
||||
|
||||
public async void append_track_async (Subsonic.Song song) {
|
||||
var err = yield this.mpv_command_async ({
|
||||
"loadfile",
|
||||
this.api.stream_uri (song.id),
|
||||
"append",
|
||||
});
|
||||
assert (err >= 0);
|
||||
|
||||
if (this.state == STOPPED) this.play_queue_position += 1;
|
||||
this._play_queue.append (song);
|
||||
}
|
||||
|
||||
public void move_track (uint from, uint to)
|
||||
requires (from < this._play_queue.get_n_items ())
|
||||
requires (to < this._play_queue.get_n_items ())
|
||||
|
|
|
@ -224,6 +224,9 @@ public class Subsonic.Client : Object {
|
|||
reader.read_element (i);
|
||||
callback (new Song (reader));
|
||||
reader.end_element ();
|
||||
|
||||
Idle.add (this.get_random_songs.callback);
|
||||
yield;
|
||||
}
|
||||
|
||||
assert (reader.get_error () == null);
|
||||
|
|
|
@ -65,6 +65,9 @@ namespace Mpv {
|
|||
[CCode (cname = "mpv_command")]
|
||||
public Error command ([CCode (array_length = false)] string[] args);
|
||||
|
||||
[CCode (cname = "mpv_command_async")]
|
||||
public Error command_async (uint64 reply_userdata, [CCode (array_length = false)] string[] args);
|
||||
|
||||
[CCode (cname = "mpv_observe_property")]
|
||||
public Error observe_property (uint64 reply_userdata, string name, Format format);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue