diff options
Diffstat (limited to 'src/VideoPlayer.cpp')
-rw-r--r-- | src/VideoPlayer.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 3d3fcc7..5e34c8e 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -28,12 +28,12 @@ static ssize_t read_eintr(int fd, void *buffer, size_t size) { } } -static ssize_t write_all(int fd, const void *buffer, size_t size) { +static ssize_t write_all_blocking(int fd, const void *buffer, size_t size) { ssize_t bytes_written = 0; while((size_t)bytes_written < size) { ssize_t written = write(fd, (char*)buffer + bytes_written, size - bytes_written); if(written == -1) { - if(errno != EINTR) + if(errno != EINTR && errno != EWOULDBLOCK) return -1; } else { bytes_written += written; @@ -451,6 +451,19 @@ namespace QuickMedia { return err; } + VideoPlayer::Error VideoPlayer::get_duration_in_file(double *result) { + Json::Value json_root(Json::objectValue); + json_root["command"] = "duration"; + + Json::Value duration_json; + Error err = send_command(json_root, &duration_json, Json::ValueType::realValue); + if(err != Error::OK) + return err; + + *result = duration_json.asDouble(); + return err; + } + VideoPlayer::Error VideoPlayer::add_subtitle(const std::string &url, const std::string &title, const std::string &lang) { Json::Value data_json(Json::objectValue); data_json["file"] = url; @@ -496,7 +509,7 @@ namespace QuickMedia { builder["indentation"] = ""; const std::string cmd_str = Json::writeString(builder, json_root) + "\n"; - if(write_all(ipc_socket, cmd_str.data(), cmd_str.size()) == -1) { + if(write_all_blocking(ipc_socket, cmd_str.data(), cmd_str.size()) == -1) { fprintf(stderr, "Failed to send to ipc socket, error: %s, command: %.*s\n", strerror(errno), (int)cmd_str.size(), cmd_str.c_str()); return Error::FAIL_TO_SEND; } |