VideoPlayer: Use LibFileSystemAccessClient

This commit is contained in:
Caoimhe 2023-05-11 12:28:05 +01:00 committed by Andrew Kaster
parent 465fa3460f
commit 8bcf5b72eb
Notes: sideshowbarker 2024-07-16 23:57:20 +09:00
3 changed files with 31 additions and 13 deletions

View File

@ -121,16 +121,21 @@ void VideoPlayerWidget::close_file()
m_playback_manager = nullptr;
}
void VideoPlayerWidget::open_file(StringView filename)
void VideoPlayerWidget::open_file(FileSystemAccessClient::File file)
{
auto load_file_result = Video::PlaybackManager::from_file(filename);
auto mapped_file_result = Core::MappedFile::map_from_file(file.release_stream(), file.filename());
if (mapped_file_result.is_error()) {
GUI::MessageBox::show_error(window(), String::formatted("Failed to read file: {}", file.filename()).release_value_but_fixme_should_propagate_errors());
return;
}
auto load_file_result = Video::PlaybackManager::from_mapped_file(mapped_file_result.release_value());
if (load_file_result.is_error()) {
on_decoding_error(load_file_result.release_error());
return;
}
m_path = filename;
m_path = file.filename();
update_title();
close_file();
@ -292,7 +297,8 @@ void VideoPlayerWidget::drop_event(GUI::DropEvent& event)
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path());
if (response.is_error())
return;
open_file(response.value().filename());
open_file(response.release_value());
}
}
@ -343,7 +349,7 @@ void VideoPlayerWidget::update_title()
if (m_path.is_empty()) {
string_builder.append("No video"sv);
} else {
string_builder.append(m_path.view());
string_builder.append(m_path);
}
string_builder.append("[*] - Video Player"sv);
@ -378,9 +384,11 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
// File menu
auto file_menu = TRY(window.try_add_menu("&File"_short_string));
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<DeprecatedString> path = GUI::FilePicker::get_open_filepath(&window, "Open video file...");
if (path.has_value())
open_file(path.value());
auto response = FileSystemAccessClient::Client::the().open_file(&window, "Open video file...");
if (response.is_error())
return;
open_file(response.release_value());
})));
TRY(file_menu->try_add_separator());
TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) {

View File

@ -8,6 +8,7 @@
#include <AK/FixedArray.h>
#include <AK/NonnullRefPtr.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Forward.h>
#include <LibGUI/Widget.h>
@ -26,7 +27,7 @@ public:
static ErrorOr<NonnullRefPtr<VideoPlayerWidget>> try_create();
virtual ~VideoPlayerWidget() override = default;
void close_file();
void open_file(StringView filename);
void open_file(FileSystemAccessClient::File filename);
void resume_playback();
void pause_playback();
void toggle_pause();
@ -55,7 +56,7 @@ private:
virtual void drop_event(GUI::DropEvent&) override;
DeprecatedString m_path;
String m_path;
RefPtr<VideoFrameWidget> m_video_display;
RefPtr<GUI::HorizontalSlider> m_seek_slider;

View File

@ -6,6 +6,7 @@
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Window.h>
@ -29,15 +30,23 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->resize(640, 480);
window->set_resizable(true);
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
auto main_widget = TRY(window->set_main_widget<VideoPlayer::VideoPlayerWidget>());
main_widget->update_title();
TRY(main_widget->initialize_menubar(window));
if (!filename.is_empty())
main_widget->open_file(filename);
window->show();
window->set_icon(GUI::Icon::default_icon("app-video-player"sv).bitmap_for_size(16));
if (!filename.is_empty()) {
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, filename);
if (!response.is_error()) {
main_widget->open_file(response.release_value());
}
}
return app->exec();
}