From b9a5d95635a2f0094cd919f0b11f37336012dc24 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 14 Nov 2020 06:15:06 +0100 Subject: Resume video when navigating back from related/channel videos --- src/VideoPlayer.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/VideoPlayer.cpp') diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index c7d2697..157d2b8 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -18,11 +18,12 @@ const int MAX_RETRIES_CONNECT = 20; const int READ_TIMEOUT_MS = 200; namespace QuickMedia { - VideoPlayer::VideoPlayer(bool use_tor, bool no_video, bool use_system_mpv_config, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root) : + VideoPlayer::VideoPlayer(bool use_tor, bool no_video, bool use_system_mpv_config, bool resume_playback, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root) : exit_status(0), use_tor(use_tor), no_video(no_video), use_system_mpv_config(use_system_mpv_config), + resume_playback(resume_playback), video_process_id(-1), ipc_socket(-1), connected_to_ipc(false), @@ -83,20 +84,29 @@ namespace QuickMedia { create_directory_recursive(video_cache_dir); std::string cache_dir = "--cache-dir=" + video_cache_dir.data; + Path mpv_watch_later_dir = get_storage_dir().join("mpv").join("watch_later"); + create_directory_recursive(mpv_watch_later_dir); + std::string watch_later_dir = "--watch-later-directory=" + mpv_watch_later_dir.data; + // TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched args.insert(args.end(), { - "mpv", "--keep-open=yes", input_ipc_server_arg.c_str(), - "--no-resume-playback", + "mpv", "--keep-open=yes", + input_ipc_server_arg.c_str(), "--cursor-autohide=no", /* "--no-input-default-bindings", "--input-vo-keyboard=no", "--no-input-cursor", */ "--no-terminal", + "--save-position-on-quit=yes", "--profile=pseudo-gui", // For gui when playing audio, requires a version of mpv that isn't ancient cache_dir.c_str(), + watch_later_dir.c_str(), "--cache-on-disk=yes", "--ytdl-raw-options=sub-lang=\"en,eng,enUS,en-US\",write-sub=", input_conf.c_str(), wid_arg.c_str() }); + if(!resume_playback) + args.push_back("--no-resume-playback"); + if(!use_system_mpv_config) { args.insert(args.end(), { "--no-config", /*"--demuxer-max-bytes=40M", "--demuxer-max-back-bytes=20M",*/ @@ -413,6 +423,19 @@ namespace QuickMedia { return err; } + VideoPlayer::Error VideoPlayer::quit_and_save_watch_later() { + Json::Value command_data(Json::arrayValue); + command_data.append("quit-watch-later"); + Json::Value command(Json::objectValue); + command["command"] = command_data; + + Json::StreamWriterBuilder builder; + builder["commentStyle"] = "None"; + builder["indentation"] = ""; + const std::string cmd_str = Json::writeString(builder, command) + "\n"; + return send_command(cmd_str.c_str(), cmd_str.size()); + } + VideoPlayer::Error VideoPlayer::send_command(const char *cmd, size_t size) { if(!connected_to_ipc) return Error::FAIL_NOT_CONNECTED; -- cgit v1.2.3