惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
D
Docker
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
美团技术团队
博客园 - 叶小钗
I
InfoQ
Jina AI
Jina AI
博客园 - 司徒正美
雷峰网
雷峰网
B
Blog
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
V
V2EX
N
Netflix TechBlog - Medium

博客园 - wgscd

Git 无法访问 GitHub(unable to access ‘https://github.com/.../.git‘)问题解决教程 RapidOcrNet文字识别OCR C#+Audio绘制麦克风波形 一共免费大模型API AI聊天对话界面的HTML代码。 纯JavaScript代码实现保存Canvas图片到电脑 WPF鼠标拖动改变图片透明度 Fiddler自定义规则保存图片和提示The system proxy was changed自动重连 缩放 div 浏览器语音识别-webkitSpeechRecognition HTML获取摄像头画面,拍照截图保存 JS摄像头手势识别-Handsfree.js HTML,JS 模拟聊天界面UI JS获取元素相对窗口的位置和大小 C# 判断是否安装了ffmpeg shadow-root中的元素定位方法 JS MutationObserver监听DOM元素改变 C# 文件分割和文件合并 WPF刮刮乐 JS利用浏览器进行语言识别 WPF设置默认语言地区CultureInfo VS2022推送代码 到github错误: CertGetCertificateChain trust error CERT_TRUST_IS_PARTIAL_CHAIN的解决办法 C#正则表达式匹配候选词 使用ffmpeg去除音频静音
Webview2动态设置页面video的Blob进行播放
wgscd · 2025-01-14 · via 博客园 - wgscd

Webview2动态设置页面video的Blob进行播放

<Window
    x:Class="WpfApp2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApp2"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:webview2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
      mc:Ignorable="d"
      Title="MainWindow" Height="720" Width="1280">
    <Grid>
        <webview2:WebView2 x:Name="webview" 
          Source="https://www.baidu.com" Margin="0,272,0,0"></webview2:WebView2>
        <Button VerticalAlignment="Top" Height="148" Margin="235,0,579,0" Click="Button_Click">Play</Button>
    </Grid>
</Window>
 



 public MainWindow()
 {
     InitializeComponent();
     webview.Source = new Uri("http://localhost/play.html");
 }



void testPlay() {


     // 读取视频文件为字节数组
     byte[] videoData = File.ReadAllBytes("111.MP4");

     // 将字节数组转换为 Base64 字符串
     string base64Video = Convert.ToBase64String(videoData);

     // 构建 Blob URL
     string script = $@"
             var byteCharacters = atob('{base64Video}');
             var byteNumbers = new Array(byteCharacters.length);
             for (var i = 0; i < byteCharacters.length; i++) {{
                 byteNumbers[i] = byteCharacters.charCodeAt(i);
             }}
             var byteArray = new Uint8Array(byteNumbers);
             var blob = new Blob([byteArray], {{ type: 'video/mp4' }});
             var video = document.getElementById('myVideo');
             video.src = URL.createObjectURL(blob);
             video.play();
         ";

     // 执行 JavaScript
     webview.ExecuteScriptAsync(script);





 }