aboutsummaryrefslogtreecommitdiff
path: root/video_player
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-05 07:16:25 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-05 07:23:15 +0100
commit63d18f733602f9b7381a03b72a17662a99c44fc2 (patch)
tree01992222bf601f8398b330a4bb08f9f0a98f4383 /video_player
parent8923e0d8f268462b2a7dfabe2545e1d6bda5615a (diff)
Fix video fullscreen button, double-click fullscreen
Fix video seekbar mouse collision not working for the top of the seekbar
Diffstat (limited to 'video_player')
-rw-r--r--video_player/README.md27
-rw-r--r--video_player/src/main.cpp34
2 files changed, 56 insertions, 5 deletions
diff --git a/video_player/README.md b/video_player/README.md
index 9a74c9c..0d0adeb 100644
--- a/video_player/README.md
+++ b/video_player/README.md
@@ -56,9 +56,34 @@ Add a subtitle file/url that is loaded asynchronously
"request_id": 233 // Optional. Its provided if request_id was provided in the request
}
```
+## cycle-fullscreen
+Return seeking position in file in seconds
+### request
+```
+{
+ "command": "cycle-fullscreen",
+ "request_id": 232 // Optional
+}
+```
+### response on success
+```
+{
+ "status": "success",
+ "request_id": 232, // Optional. Its provided if request_id was provided in the request
+}
+```
+### response on error
+```
+{
+ "status": "error",
+ "message": "error message",
+ "request_id": 233 // Optional. Its provided if request_id was provided in the request
+}
+```
# IPC event
```
{
- "event": "file-loaded"
+ "event": "file-loaded",
+ "args": [] // A list of strings
}
``` \ No newline at end of file
diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp
index 03acd93..33c4d96 100644
--- a/video_player/src/main.cpp
+++ b/video_player/src/main.cpp
@@ -101,6 +101,20 @@ static Json::Value handle_json_command_sub_add(mpv_handle *mpv_ctx, const Json::
return response_json;
}
+static Json::Value handle_json_command_cycle_fullscreen(mpv_handle *mpv_ctx) {
+ const char *args[] = { "cycle", "fullscreen", nullptr };
+ const int res = mpv_command_async(mpv_ctx, 0, args);
+
+ Json::Value response_json(Json::objectValue);
+ if(res < 0) {
+ response_json["status"] = "error";
+ response_json["message"] = mpv_error_string(res);
+ } else {
+ response_json["status"] = "success";
+ }
+ return response_json;
+}
+
static void send_error(const std::string &err_msg, std::optional<int64_t> request_id, int fd) {
fprintf(stderr, "Error: %s\n", err_msg.c_str());
@@ -151,10 +165,12 @@ static void handle_json_command(mpv_handle *mpv_ctx, const Json::Value &json_roo
response_json = handle_json_command_time_pos(mpv_ctx);
} else if(strcmp(command_json.asCString(), "sub-add") == 0) {
response_json = handle_json_command_sub_add(mpv_ctx, json_root);
+ } else if(strcmp(command_json.asCString(), "cycle-fullscreen") == 0) {
+ response_json = handle_json_command_cycle_fullscreen(mpv_ctx);
} else {
response_json = Json::Value(Json::objectValue);
response_json["status"] = "error";
- response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos or sub-add";
+ response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos, sub-add or cycle-fullscreen";
}
if(request_id)
@@ -193,9 +209,16 @@ static void handle_request_commands_line_by_line(mpv_handle *mpv_ctx, int fd, ch
command_buffer_size = 0;
}
-static void send_event(const char *event_name, int fd) {
+static void send_event(const char *event_name, int fd, const std::vector<std::string> &args = {}) {
Json::Value json_root(Json::objectValue);
json_root["event"] = event_name;
+ if(!args.empty()) {
+ Json::Value args_json(Json::arrayValue);
+ for(const std::string &arg : args) {
+ args_json.append(arg);
+ }
+ json_root["args"] = std::move(args_json);
+ }
Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
@@ -292,6 +315,7 @@ int main(int argc, char **argv) {
check_error(mpv_command(mpv_ctx, cmd), "loadfile");
check_error(mpv_observe_property(mpv_ctx, 0, "idle-active", MPV_FORMAT_FLAG), "observe idle-active");
+ check_error(mpv_observe_property(mpv_ctx, 0, "fullscreen", MPV_FORMAT_FLAG), "observe fullscreen");
char command_buffer[COMMAND_BUFFER_MAX_SIZE];
size_t command_buffer_size = 0;
@@ -325,12 +349,14 @@ int main(int argc, char **argv) {
} else if(event->event_id == MPV_EVENT_SHUTDOWN) {
running = false;
break;
- } else if(event->event_id == MPV_EVENT_PROPERTY_CHANGE && file_started) {
+ } else if(event->event_id == MPV_EVENT_PROPERTY_CHANGE) {
// End of file (idle)
mpv_event_property *property = (mpv_event_property*)event->data;
- if(strcmp(property->name, "idle-active") == 0 && *(int*)property->data == 1) {
+ if(file_started && strcmp(property->name, "idle-active") == 0 && *(int*)property->data == 1) {
running = false;
break;
+ } else if(args.ipc_fd && strcmp(property->name, "fullscreen") == 0) {
+ send_event("fullscreen", args.ipc_fd_num, { *(bool*)property->data ? "yes" : "no" });
}
}