diff options
-rw-r--r-- | include/VideoPlayer.hpp | 14 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 58 |
2 files changed, 10 insertions, 62 deletions
diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index 0d1203b..1d15aff 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -20,7 +20,6 @@ namespace QuickMedia { OK, FAIL_TO_LAUNCH_PROCESS, FAIL_TO_CREATE_SOCKET, - FAIL_TO_GENERATE_IPC_FILENAME, FAIL_TO_CONNECT_TIMEOUT, FAIL_NOT_CONNECTED, FAIL_TO_SEND, @@ -45,24 +44,11 @@ namespace QuickMedia { // Should be called every update frame Error update(); - Error toggle_pause(); - - // Progress is in range [0..1] - Error get_progress(double *result); // Returns time in seconds Error get_time_in_file(double *result); - Error get_time_remaining(double *result); - Error set_paused(bool paused); - - // Progress is in range [0..1] - Error set_progress(double progress); - - Error is_seekable(bool *result); Error quit_and_save_watch_later(); - bool is_connected() const { return connected_to_ipc; } - Error set_property(const std::string &property_name, const Json::Value &value); Error get_property(const std::string &property_name, Json::Value *result, Json::ValueType result_type); diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index ed9bbc9..db43ae1 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -86,7 +86,7 @@ namespace QuickMedia { sockets[0] = -1; sockets[1] = -1; perror("Failed to create socketpair to mpv"); - return Error::FAIL_TO_GENERATE_IPC_FILENAME; + return Error::FAIL_TO_CREATE_SOCKET; } Path cookies_filepath; @@ -107,7 +107,8 @@ namespace QuickMedia { //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); + 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; @@ -172,8 +173,14 @@ namespace QuickMedia { args.insert(args.end(), { "--", path, nullptr }); - if(exec_program_async(args.data(), &video_process_id) != 0) + if(exec_program_async(args.data(), &video_process_id) != 0) { + for(int i = 0; i < 2; ++i) { + if(sockets[i] != -1) + close(sockets[i]); + sockets[i] = -1; + } return Error::FAIL_TO_LAUNCH_PROCESS; + } int flags = fcntl(sockets[0], F_GETFL, 0); fcntl(sockets[0], F_SETFL, flags | O_NONBLOCK); @@ -313,21 +320,6 @@ namespace QuickMedia { return Error::OK; } - VideoPlayer::Error VideoPlayer::toggle_pause() { - const char cmd[] = "cycle pause\n"; - return send_command(cmd, sizeof(cmd) - 1); - } - - VideoPlayer::Error VideoPlayer::get_progress(double *result) { - Json::Value percent_pos_json; - Error err = get_property("percent-pos", &percent_pos_json, Json::realValue); - if(err != Error::OK) - return err; - - *result = percent_pos_json.asDouble() * 0.01; - return err; - } - VideoPlayer::Error VideoPlayer::get_time_in_file(double *result) { Json::Value time_pos_json; Error err = get_property("time-pos", &time_pos_json, Json::realValue); @@ -338,16 +330,6 @@ namespace QuickMedia { return err; } - VideoPlayer::Error VideoPlayer::get_time_remaining(double *result) { - Json::Value time_remaining_json; - Error err = get_property("time-remaining", &time_remaining_json, Json::realValue); - if(err != Error::OK) - return err; - - *result = time_remaining_json.asDouble(); - return err; - } - VideoPlayer::Error VideoPlayer::set_property(const std::string &property_name, const Json::Value &value) { Json::Value command_data(Json::arrayValue); command_data.append("set_property"); @@ -417,26 +399,6 @@ namespace QuickMedia { return err; } - VideoPlayer::Error VideoPlayer::set_paused(bool paused) { - return set_property("pause", paused); - } - - VideoPlayer::Error VideoPlayer::set_progress(double progress) { - std::string cmd = "{ \"command\": [\"set_property\", \"percent-pos\", "; - cmd += std::to_string(progress * 100.0) + "] }"; - return send_command(cmd.c_str(), cmd.size()); - } - - VideoPlayer::Error VideoPlayer::is_seekable(bool *result) { - Json::Value seekable_json; - Error err = get_property("seekable", &seekable_json, Json::booleanValue); - if(err != Error::OK) - return err; - - *result = seekable_json.asBool(); - return err; - } - VideoPlayer::Error VideoPlayer::quit_and_save_watch_later() { Json::Value command_data(Json::arrayValue); command_data.append("quit-watch-later"); |