aboutsummaryrefslogtreecommitdiff
path: root/src/VideoPlayer.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-14 07:22:05 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-14 07:23:14 +0200
commitd37b3a7aac87e5f60c49202c824d985e53b7b544 (patch)
tree165fec322b0166b48e298ebcae0e5015578d6a4a /src/VideoPlayer.cpp
parent977547ff7f0b609291da56df32e5642d10c530cd (diff)
Rework around mpv issue: reload video if frozen after seek. Add f5 to reload video, readd video cache
Diffstat (limited to 'src/VideoPlayer.cpp')
-rw-r--r--src/VideoPlayer.cpp49
1 files changed, 10 insertions, 39 deletions
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 0df4108..fe4643e 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -20,11 +20,10 @@ const int MAX_RETRIES_CONNECT = 1000;
const int READ_TIMEOUT_MS = 200;
namespace QuickMedia {
- VideoPlayer::VideoPlayer(bool no_video, bool use_system_mpv_config, bool resume_playback, bool keep_open, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root, int monitor_height) :
+ VideoPlayer::VideoPlayer(bool no_video, bool use_system_mpv_config, bool keep_open, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root, int monitor_height) :
exit_status(0),
no_video(no_video),
use_system_mpv_config(use_system_mpv_config),
- resume_playback(resume_playback),
keep_open(keep_open),
video_process_id(-1),
connected_to_ipc(false),
@@ -67,7 +66,7 @@ namespace QuickMedia {
XCloseDisplay(display);
}
- VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title, const std::string &start_time) {
+ VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, const char *audio_path, sf::WindowHandle _parent_window, bool is_youtube, const std::string &title, const std::string &start_time) {
parent_window = _parent_window;
if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) {
@@ -77,10 +76,6 @@ namespace QuickMedia {
return Error::FAIL_TO_CREATE_SOCKET;
}
- Path cookies_filepath;
- if(get_cookies_filepath(cookies_filepath, plugin_name) != 0)
- fprintf(stderr, "Failed to create %s cookies filepath\n", plugin_name.c_str());
-
const std::string parent_window_str = std::to_string(parent_window);
std::vector<const char*> args;
@@ -91,19 +86,12 @@ namespace QuickMedia {
std::string input_conf = "--input-conf=" + resource_root + "input.conf";
- Path mpv_watch_later_dir = get_storage_dir().join("mpv").join("watch_later");
- if(create_directory_recursive(mpv_watch_later_dir) != 0)
- fprintf(stderr, "Failed to create %s watch later directory\n", mpv_watch_later_dir.data.c_str());
- std::string watch_later_dir = "--watch-later-directory=" + mpv_watch_later_dir.data;
-
std::string ytdl_format;
if(no_video)
ytdl_format = "--ytdl-format=bestaudio/best";
else
ytdl_format = "--ytdl-format=bestvideo[height<=?" + std::to_string(monitor_height) + "]+bestaudio/best";
- std::string cookies_file_arg = "--cookies-file=" + cookies_filepath.data;
-
// TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched
args.insert(args.end(), {
"mpv",
@@ -112,13 +100,11 @@ namespace QuickMedia {
"--no-terminal",
"--save-position-on-quit=yes",
"--profile=pseudo-gui", // For gui when playing audio, requires a version of mpv that isn't ancient
- watch_later_dir.c_str(),
ytdl_format.c_str(),
+ "--no-resume-playback",
// TODO: Disable hr seek on low power devices?
"--hr-seek=yes",
- "--cache=no",
- "--cookies",
- cookies_file_arg.c_str(),
+ //"--cache=no",
input_conf.c_str(),
wid_arg.c_str()
});
@@ -131,10 +117,8 @@ namespace QuickMedia {
if(keep_open)
args.push_back("--keep-open=yes");
- if(resume_playback)
- args.push_back("--resume-playback");
- else
- args.push_back("--no-resume-playback");
+ if(is_youtube)
+ args.push_back("--no-ytdl");
if(!use_system_mpv_config) {
args.insert(args.end(), {
@@ -161,7 +145,7 @@ namespace QuickMedia {
}
std::string start_time_arg;
- if(!resume_playback && !start_time.empty()) {
+ if(!start_time.empty()) {
start_time_arg = "--start=" + start_time;
args.push_back(start_time_arg.c_str());
}
@@ -184,16 +168,16 @@ namespace QuickMedia {
return Error::OK;
}
- VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &plugin_name, const std::string &title, const std::string &start_time) {
+ VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, bool is_youtube, const std::string &title, const std::string &start_time) {
// This check is to make sure we dont change window that the video belongs to. This is not a usecase we will have so
// no need to support it for now at least.
assert(parent_window == 0 || parent_window == _parent_window);
assert(path);
fprintf(stderr, "Playing video: %s, audio: %s\n", path ? path : "", audio_path ? audio_path : "");
if(video_process_id == -1)
- return launch_video_process(path, audio_path, _parent_window, plugin_name, title, start_time);
+ return launch_video_process(path, audio_path, _parent_window, is_youtube, title, start_time);
- // TODO: When these are used, add audio_path, title and start_time. Also handle plugin_name
+ // TODO: When these are used, add audio_path, title and start_time. Also handle is_youtube
Json::Value command_data(Json::arrayValue);
command_data.append("loadfile");
command_data.append(path);
@@ -399,19 +383,6 @@ 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;