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

Commit

Permalink
fix: crashing on files with undefined duration.
Browse files Browse the repository at this point in the history
addresses #21
  • Loading branch information
vixalien committed Jan 31, 2024
1 parent 0a49c37 commit 57aa61b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export class APMediaStream extends Gtk.MediaStream {
get_duration() {
if (!this._play.media_info) return 0;

return this._play.media_info.get_duration() / Gst.USECOND;
return get_safe_duration(this._play.media_info.get_duration()) / Gst.USECOND;
}

// property: error
Expand Down Expand Up @@ -622,7 +622,7 @@ export class APMediaStream extends Gtk.MediaStream {
info.get_number_of_audio_streams() > 0,
info.get_number_of_video_streams() > 0,
info.is_seekable(),
this._play.get_duration() / Gst.USECOND,
get_safe_duration(info.get_duration()) / Gst.USECOND,
);

if (info.get_number_of_audio_streams() <= 0) {
Expand All @@ -634,6 +634,8 @@ export class APMediaStream extends Gtk.MediaStream {
),
);
}
} else {
this.notify("duration");
}
}

Expand Down Expand Up @@ -761,3 +763,11 @@ export function get_cubic_volume(value: number) {
value,
);
}

function get_safe_duration(value: number) {
if (value >= GLib.MAXUINT64) {
return 100 * Gst.SECOND;
}

return value;
}

0 comments on commit 57aa61b

Please sign in to comment.