Skip to content

Commit

Permalink
do not display video if it cannot be played
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Aug 12, 2023
1 parent 25ddee9 commit 4a5d849
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/component/file_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum FilePreview {
Image(gio::File),

/// Video preview.
Video(gio::File),
Video(gtk::MediaFile),

/// PDF document.
Pdf(Pdf),
Expand Down Expand Up @@ -120,7 +120,13 @@ impl FilePreviewModel {
FilePreview::Image(file.file.clone())
}
(mime::VIDEO, _) => {
FilePreview::Video(file.file.clone())
let media_file = gtk::MediaFile::for_file(&file.file);

if media_file.has_video() {
FilePreview::Video(media_file)
} else {
FilePreview::Error("Unable to play video format.".into())
}
}
(_, mime::PDF) => {
// TODO: This should be async.
Expand Down Expand Up @@ -257,7 +263,8 @@ impl Component for FilePreviewModel {

#[name = "video"]
gtk::Video {

set_hexpand: true,
set_vexpand: false,
},

#[name = "pdf_container"]
Expand Down Expand Up @@ -493,8 +500,8 @@ impl Component for FilePreviewModel {

widgets.stack.set_visible_child(&widgets.text_container);
}
Some(FilePreview::Video(file)) => {
widgets.video.set_file(Some(file));
Some(FilePreview::Video(media_file)) => {
widgets.video.set_media_stream(media_file.into());
widgets.stack.set_visible_child(&widgets.video);
}
Some(FilePreview::Pdf(pdf)) => {
Expand Down

0 comments on commit 4a5d849

Please sign in to comment.