实战入门Tauri-2-流媒体播放器

1,024 阅读1分钟

Tarui从实践中学习二

结构图

image.png

开发知识点

  • 引入 ffpmeg

    1.手工下载或者写shell脚本将官方ffpmeg二进制文件下载到项目内,本例中是将苹果M处理器版本下载到 /src-tauri/bin/,完整路径 /src-tauri/bin/ffmpeg-aarch64-apple-darwin

    2.tauri.conf.json中配置

    "allowlist": {
       "shell": {
         "sidecar": true,
         "execute": true,
         "open": "",
         "scope": [
           { "name": "bin/ffmpeg", "args": true, "sidecar": true }
         ]
       },
    
  • 调用ffmpeg这样就可在js文件中使用

    //引入tauri接口
    import { Command } from '@tauri-apps/api/shell';
    //执行ffmpeg shell命令 例如格式转换 ffmpeg -i "/xx/demo.mp4" -acodec "aac" "/xx/demo.flv"
    const ffmpegCommand = Command.sidecar('bin/ffmpeg',['-i','/xx/demo.mp4','-acodec','aac','/xx/demo.flv']));
     const output = await ffmpegCommand.execute();
     console.log("out:",output.stdout);
     console.log("err:",output.stderr);
    
  • 播放本地文件

    //如果选择/Users/xxx/DownLoads 文件夹里的demo.mp4
    const downloadPath = await downloadDir();
    const filePath = await join(downloadPath, `demo.mp4`);
    //source提供给vedio使用
    let source = convertFileSrc(filePath);

未完待续