mqtt加入认证,优化视频播放与浏览器

This commit is contained in:
2025-03-07 16:04:19 +08:00
parent c71e8bc13d
commit febcdfdbf7
13 changed files with 60 additions and 82 deletions

View File

@@ -6,7 +6,7 @@ import (
libvlc "github.com/adrg/libvlc-go/v3"
)
func Play(ctx context.Context, file string) error {
func Play(ctx context.Context, path string, local bool) error {
// 1. 初始化 VLC
if err := libvlc.Init("--no-xlib"); err != nil {
return fmt.Errorf("VLC初始化失败: %w", err)
@@ -38,8 +38,14 @@ func Play(ctx context.Context, file string) error {
}
// 4. 加载并播放文件
if _, err := player.LoadMediaFromPath(file); err != nil {
return fmt.Errorf("文件加载失败: %w", err)
if local {
if _, err := player.LoadMediaFromPath(path); err != nil {
return fmt.Errorf("文件加载失败: %w", err)
}
} else {
if _, err := player.LoadMediaFromURL(path); err != nil {
return fmt.Errorf("文件加载失败: %w", err)
}
}
if err := player.Play(); err != nil {
@@ -57,7 +63,7 @@ func Play(ctx context.Context, file string) error {
}
// 5. 等待事件
fmt.Printf("正在播放: %s\n", file)
fmt.Printf("正在播放: %s\n", path)
select {
case <-ctx.Done():
return fmt.Errorf("播放被用户中断")