mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:38:10 +00:00
VideoPlayer: Use LibFileSystemAccessClient
This commit is contained in:
parent
465fa3460f
commit
8bcf5b72eb
3 changed files with 31 additions and 13 deletions
|
@ -121,16 +121,21 @@ void VideoPlayerWidget::close_file()
|
||||||
m_playback_manager = nullptr;
|
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()) {
|
if (load_file_result.is_error()) {
|
||||||
on_decoding_error(load_file_result.release_error());
|
on_decoding_error(load_file_result.release_error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_path = filename;
|
m_path = file.filename();
|
||||||
update_title();
|
update_title();
|
||||||
close_file();
|
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());
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path());
|
||||||
if (response.is_error())
|
if (response.is_error())
|
||||||
return;
|
return;
|
||||||
open_file(response.value().filename());
|
|
||||||
|
open_file(response.release_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +349,7 @@ void VideoPlayerWidget::update_title()
|
||||||
if (m_path.is_empty()) {
|
if (m_path.is_empty()) {
|
||||||
string_builder.append("No video"sv);
|
string_builder.append("No video"sv);
|
||||||
} else {
|
} else {
|
||||||
string_builder.append(m_path.view());
|
string_builder.append(m_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
string_builder.append("[*] - Video Player"sv);
|
string_builder.append("[*] - Video Player"sv);
|
||||||
|
@ -378,9 +384,11 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
|
||||||
// File menu
|
// File menu
|
||||||
auto file_menu = TRY(window.try_add_menu("&File"_short_string));
|
auto file_menu = TRY(window.try_add_menu("&File"_short_string));
|
||||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||||
Optional<DeprecatedString> path = GUI::FilePicker::get_open_filepath(&window, "Open video file...");
|
auto response = FileSystemAccessClient::Client::the().open_file(&window, "Open video file...");
|
||||||
if (path.has_value())
|
if (response.is_error())
|
||||||
open_file(path.value());
|
return;
|
||||||
|
|
||||||
|
open_file(response.release_value());
|
||||||
})));
|
})));
|
||||||
TRY(file_menu->try_add_separator());
|
TRY(file_menu->try_add_separator());
|
||||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/FixedArray.h>
|
#include <AK/FixedArray.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
#include <LibFileSystemAccessClient/Client.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
#include <LibGUI/Forward.h>
|
#include <LibGUI/Forward.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
|
@ -26,7 +27,7 @@ public:
|
||||||
static ErrorOr<NonnullRefPtr<VideoPlayerWidget>> try_create();
|
static ErrorOr<NonnullRefPtr<VideoPlayerWidget>> try_create();
|
||||||
virtual ~VideoPlayerWidget() override = default;
|
virtual ~VideoPlayerWidget() override = default;
|
||||||
void close_file();
|
void close_file();
|
||||||
void open_file(StringView filename);
|
void open_file(FileSystemAccessClient::File filename);
|
||||||
void resume_playback();
|
void resume_playback();
|
||||||
void pause_playback();
|
void pause_playback();
|
||||||
void toggle_pause();
|
void toggle_pause();
|
||||||
|
@ -55,7 +56,7 @@ private:
|
||||||
|
|
||||||
virtual void drop_event(GUI::DropEvent&) override;
|
virtual void drop_event(GUI::DropEvent&) override;
|
||||||
|
|
||||||
DeprecatedString m_path;
|
String m_path;
|
||||||
|
|
||||||
RefPtr<VideoFrameWidget> m_video_display;
|
RefPtr<VideoFrameWidget> m_video_display;
|
||||||
RefPtr<GUI::HorizontalSlider> m_seek_slider;
|
RefPtr<GUI::HorizontalSlider> m_seek_slider;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibFileSystemAccessClient/Client.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
@ -29,15 +30,23 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
window->resize(640, 480);
|
window->resize(640, 480);
|
||||||
window->set_resizable(true);
|
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>());
|
auto main_widget = TRY(window->set_main_widget<VideoPlayer::VideoPlayerWidget>());
|
||||||
main_widget->update_title();
|
main_widget->update_title();
|
||||||
TRY(main_widget->initialize_menubar(window));
|
TRY(main_widget->initialize_menubar(window));
|
||||||
|
|
||||||
if (!filename.is_empty())
|
|
||||||
main_widget->open_file(filename);
|
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
window->set_icon(GUI::Icon::default_icon("app-video-player"sv).bitmap_for_size(16));
|
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();
|
return app->exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue