Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
skip 10 seconds when MPRIS next/previous is pressed
Browse files Browse the repository at this point in the history
fix #28
  • Loading branch information
vixalien committed Dec 16, 2023
1 parent 2981d66 commit cb412a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/mpris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,13 @@ export class MPRIS extends DBusInterface {
}

/** Skips to the next track in the tracklist */
_next() {}
_next() {
this.stream.skip_seconds(10);
}

/** Skips to the previous track in the tracklist */
_previous() {}
_previous() {
this.stream.skip_seconds(-10);}

/** Pauses playback */
_pause() {
Expand Down Expand Up @@ -494,8 +497,8 @@ export class MPRIS extends DBusInterface {
Position: GLib.Variant.new_int64(position_msecond),
MinimumRate: GLib.Variant.new_double(1.0),
MaximumRate: GLib.Variant.new_double(1.0),
CanGoNext: GLib.Variant.new_boolean(false),
CanGoPrevious: GLib.Variant.new_boolean(false),
CanGoNext: GLib.Variant.new_boolean(true),
CanGoPrevious: GLib.Variant.new_boolean(true),
CanPlay: GLib.Variant.new_boolean(true),
CanPause: GLib.Variant.new_boolean(true),
CanSeek: GLib.Variant.new_boolean(true),
Expand Down
10 changes: 7 additions & 3 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ export class APMediaStream extends Gtk.MediaStream {
this.notify("timestamp");
}

skip_seconds(seconds: number) {
this.seek(
Math.max(this.timestamp + seconds * Gst.MSECOND, 0),
);
}

get_action_group() {
const action_group = Gio.SimpleActionGroup.new();

Expand Down Expand Up @@ -708,9 +714,7 @@ export class APMediaStream extends Gtk.MediaStream {
parameter_type: "i",
activate: (_source, param) => {
if (param) {
this.seek(
Math.max(this.timestamp + param.get_int32() * Gst.MSECOND, 0),
);
this.skip_seconds(param.get_int32());
}
},
},
Expand Down

0 comments on commit cb412a0

Please sign in to comment.