Skip to content

Commit

Permalink
新增默认配置default_video,可以在配置文件定义默认视频,不需要改源码了
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Apr 21, 2024
1 parent 629577b commit 6348a9e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ log/*.txt

static/videos/*.mp4

pkg/
pkg/

video_player.py

static/test
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ python:3.10.10
| msg | string | 响应消息,描述请求的处理结果 |

# 更新日志
- v0.1.6
- 新增默认配置`default_video`,可以在配置文件定义默认视频,不需要改源码了

- v0.1.5
- 生成的视频将在播放完毕后直接删除,节省存储

Expand Down
4 changes: 4 additions & 0 deletions api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ async def ws():
if data_json['type'] == "videoEnded":
# 在这里添加删除视频文件的逻辑
await delete_video_file(data_json['video_path'])
elif data_json['type'] == "get_default_video":
logging.info(f"发送默认配置 视频路径: {config.get('default_video')}")
# 在这里添加发送消息到客户端的逻辑
await send_to_all_websockets(json.dumps({"type": "set_default_video", "video_path": config.get("default_video")}))
finally:
connected_websockets.remove(websocket)

Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"server_ip": "127.0.0.1",
"server_port": 8091,
"default_video": "./videos/2.mp4",
"easy_wav2lip": {
"api_ip_port": "http://127.0.0.1:7860",
"video_file": "E:\\GitHub_pro\\digital_human_video_player\\static\\imgs\\1.png",
Expand Down
18 changes: 17 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

// 视频播放队列
let videoQueue = [];
let defaultVideo = './videos/2.mp4'; // 默认视频路径
let defaultVideo = './videos/1.mp4'; // 默认视频路径
let currentVideo = video1; // 当前播放的视频元素
let nextVideo = video2; // 下一个将要播放的视频元素
let isWaitingForNextVideo = false; // 是否正在等待下一个视频加载
Expand Down Expand Up @@ -84,6 +84,20 @@

// WebSocket接收视频路径并添加到队列
const ws = new WebSocket('ws://localhost:8091/ws');
ws.onopen = function(event) {
console.log('WebSocket连接成功!');
// 在这里可以发送数据或执行其他操作
// 假设data是要发送的JSON数据对象
const data = {
type: 'get_default_video'
};

// 将JSON对象转换为字符串
const jsonData = JSON.stringify(data);

// 发送JSON数据
ws.send(jsonData);
};
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
if (data.type === 'show') {
Expand All @@ -98,6 +112,8 @@
if ((currentVideo.paused || currentVideo.ended) && !isWaitingForNextVideo) {
prepareNextVideo(videoQueue.shift()); // 如果当前没有视频播放,且没有在等待,则立即准备下一个视频
}
} else if (data.type === 'set_default_video') {
defaultVideo = data.video_path;
}
};

Expand Down

0 comments on commit 6348a9e

Please sign in to comment.