EMBEDDING INTO OTHER PROGRAMS (LIBMPV)(嵌入其他程序)
libmpv 是 mpv 的 C API,可用于将 mpv 嵌入到其他程序中。
头文件
c
#include <mpv/client.h>基本用法
c
mpv_handle *ctx = mpv_create();
mpv_initialize(ctx);
// 播放视频
mpv_command(ctx, (const char*[]){"loadfile", "video.mp4", NULL});
// 事件循环
while (1) {
mpv_event *event = mpv_wait_event(ctx, 1000);
if (event->event_id == MPV_EVENT_SHUTDOWN)
break;
}
mpv_terminate_destroy(ctx);常用函数
mpv_create()- 创建 mpv 实例mpv_initialize()- 初始化 mpvmpv_command()- 执行命令mpv_get_property()- 获取属性mpv_set_property()- 设置属性mpv_wait_event()- 等待事件