Flex 4 “Error #2032: Stream Error. URL: “

本文探讨了在Flex4 Cookbook中遇到的SWFLoader事件处理问题。作者尝试使用Flex编译SWF文件作为加载目标时遇到了运行错误。通过调整编译设置,将资源文件一并编译进SWF,成功解决了“Error#2032: StreamError.URL”错误。
今天研究Flex 4 Cookbook 里面的swfloader的事件处理,就想找一个swf,还没现成的swf就像用Flex正好编译一个swf文件然后当做加载

但是发现编译出来的swf文件居然不能运行,这就奇怪了,在Flex3中是绝对可以运行的,挺好奇
而且报的是
“Error #2032: Stream Error. URL: “ 这个错误
那么我在工程的bin-debug文件夹下运行这个swf还是可以运行的
而变异的bin-debug文件夹里头是有默认的Flex运行库文件,我想应该就是这有问题

那我就想到了应该是编译有问题

在FlashBuilder 里面找了找
发现有这一项

[img]http://dl.iteye.com/upload/attachment/302982/32ec36df-1e7b-3558-a9d3-7a029763b3bc.jpg[/img]

Framework linkage 里面默认是使用SDK默认的方式,而不是把资源文件一通编译进去
所以调整为编译进去就可以了

唯独不是太理解的就是为什么要这样呢,如果说减少swf体积,但是访问的时候一样会访问加载资源文件的啊
不过问题总算是解决了
--------- beginning of system --------- beginning of main ---------------------------- PROCESS STARTED (3330) for package org.cocos2d.demo ---------------------------- 2025-07-15 15:48:35.316 3330-3359 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000082da 2025-07-15 15:48:35.316 3330-3359 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000082e5 2025-07-15 15:48:35.328 3330-3359 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x00008c29 2025-07-15 15:48:35.328 3330-3359 eglCodecCommon org.cocos2d.demo E glUtilsParamSize: unknow param 0x000087fe 2025-07-15 15:48:35.363 3330-3359 EGL_emulation org.cocos2d.demo E tid 3359: eglSurfaceAttrib(1493): error 0x3009 (EGL_BAD_MATCH) 2025-07-15 15:48:36.976 3330-3357 jswrapper org.cocos2d.demo E ScriptEngine::onGetStringFromFile stream not found, possible missing file. 2025-07-15 15:48:36.976 3330-3357 jswrapper org.cocos2d.demo E ScriptEngine::runScript script stream, buffer is empty! 2025-07-15 15:48:36.976 3330-3357 jswrapper org.cocos2d.demo E [ERROR] Failed to invoke require, location: C:/ProgramData/cocos/editors/Creator/2.4.13/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:299 2025-07-15 15:48:37.026 3330-3357 jswrapper org.cocos2d.demo E ScriptEngine::evalString catch exception: 2025-07-15 15:48:37.050 3330-3357 jswrapper org.cocos2d.demo E ERROR: Uncaught ReferenceError: self is not defined, location: src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:0:0 STACK: [0]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:2 [1]anonymous@src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js:3 [2]anonymous@jsb-adapter/jsb-engine.js:2975 [3]download@jsb-adapter/jsb-engine.js:2984 [4]downloadScript@jsb-adapter/jsb-engine.js:2971 [5]a@src/cocos2d-jsb.28d62.js:16668 [6]anonymous@src/cocos2d-jsb.28d62.js:16678 [7]retry@src/cocos2d-jsb.28d62.js:18111 [8]download@src/cocos2d-jsb.28d62.js:16663 [9]load@src/cocos2d-jsb.28d62.js:17318 [10]94.e.exports@src/cocos2d-jsb.28d62.js:17134 [11]_flow@src/cocos2d-jsb.28d62.js:17579 [12]async@src/cocos2d-jsb.28d62.js:17574 [13]anonymous@src/cocos2d-jsb.28d62.js:17261 [14]forEach@src/cocos2d-jsb.28d62.js:18189 [15]94.e.exports@src/cocos2d-jsb.28d62.js:17244 [16]_flow@src/cocos2d-jsb.28d62.js:17579 [17]anonymous@src/cocos2d-jsb.28d62.js:17586 [18]98.e.exports@src/cocos2d-jsb.2 2025-07-15 15:48:37.052 3330-3357 jswrapper org.cocos2d.demo E ScriptEngine::evalString script src/assets/_plugs/lib/gravityengine.mg.cocoscreator.min.dbb97.js, failed! 2025-07-15 15:48:37.053 3330-3357 jswrapper org.cocos2d.demo E [ERROR] Failed to invoke require, location: C:/ProgramData/cocos/editors/Creator/2.4.13/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp:299 2025-07-15 15:48:49.228 1715-2033 bt_btif com.android.bluetooth E register_notification_rsp: Avrcp device is not connected, handle: 0x0 2025-07-15 15:48:49.228 1715-2033 bt_btif com.android.bluetooth E register_notification_rsp: Avrcp device is not connected, handle: 0x0 2025-07-15 15:48:49.241 1452-1763 OMXNodeInstance media.codec E setConfig(0xf5210060:google.mp3.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) 2025-07-15 15:48:49.241 1452-1763 OMXNodeInstance media.codec E getConfig(0xf5210060:google.mp3.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001) 2025-07-15 15:49:00.001 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.015 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.024 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.037 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.045 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.054 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.061 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.071 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.081 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.091 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.107 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.115 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.123 1573-1586 memtrack system_server E Couldn't load memtrack module 2025-07-15 15:49:00.132 1573-1586 memtrack system_server E Couldn't load memtrack module
07-16
<template> <div class="camera-container"> <!-- 视频播放区域 --> <video ref="videoPlayer" controls autoplay muted playsinline></video><!--autoplay是规定一旦视频就绪马上开始播放。muted 输出视频静音,playsinline指明视频将内嵌(inline)播放,controls会在视频底部提供一个控制面板--> <!-- 控制面板 --> <div class="controls"> <input v-model="cameraUrl" placeholder="rtsp://username:password@ip:port/stream" class="url-input" /> <button @click="connectCamera" :disabled="isConnecting"> {{ isConnecting ? &#39;连接中...&#39; : &#39;连接摄像头&#39; }} </button> <button @click="disconnectCamera" :disabled="!isConnected">断开连接</button> <!-- 状态指示器 --> <div class="status-indicator" :class="connectionStatusClass"> {{ connectionStatusText }} </div> </div> <!-- 错误提示 --> <div v-if="errorMessage" class="error-message"> {{ errorMessage }} </div> </div> </template> <script lang="ts"> import { defineComponent, ref, computed, onBeforeUnmount } from &#39;vue&#39;; import flvjs from &#39;flv.js&#39;; // 安装: npm install flv.js // 定义摄像头连接状态类型 type ConnectionStatus = &#39;disconnected&#39; | &#39;connecting&#39; | &#39;connected&#39; | &#39;error&#39;; export default defineComponent({ name: &#39;IpCameraViewer&#39;, setup() { // 使用TypeScript类型声明 const videoPlayer = ref<HTMLVideoElement | null>(null); const flvPlayer = ref<any>(null); const cameraUrl = ref(&#39;rtsp://admin:12345@192.168.1.100:554/Streaming/Channels/101&#39;); const connectionStatus = ref<ConnectionStatus>(&#39;disconnected&#39;); const errorMessage = ref<string>(&#39;&#39;); const reconnectAttempts = ref(0); const maxReconnectAttempts = 3; // 计算属性:连接状态文本 const connectionStatusText = computed(() => { switch (connectionStatus.value) { case &#39;disconnected&#39;: return &#39;未连接&#39;; case &#39;connecting&#39;: return &#39;连接中...&#39;; case &#39;connected&#39;: return &#39;已连接&#39;; case &#39;error&#39;: return &#39;连接错误&#39;; default: return &#39;未知状态&#39;; } }); // 计算属性:连接状态对应的CSS类 const connectionStatusClass = computed(() => { return `status-${connectionStatus.value}`; }); // 计算属性:是否正在连接 const isConnecting = computed(() => { return connectionStatus.value === &#39;connecting&#39;; }); // 计算属性:是否已连接 const isConnected = computed(() => { return connectionStatus.value === &#39;connected&#39;; }); // 连接摄像头 const connectCamera = async () => { try { // 重置状态 errorMessage.value = &#39;&#39;; connectionStatus.value = &#39;connecting&#39;; reconnectAttempts.value = 0; // 断开现有连接 disconnectCamera(); // 验证URL格式 if (!validateCameraUrl(cameraUrl.value)) { throw new Error(&#39;摄像头URL格式无效&#39;); } // 检查FLV支持 if (!flvjs.isSupported()) { throw new Error(&#39;当前浏览器不支持FLV播放&#39;); } // 创建FLV播放器 flvPlayer.value = flvjs.createPlayer({ type: &#39;flv&#39;, isLive: true, url: getStreamProxyUrl(cameraUrl.value) }, { enableStashBuffer: false, // 禁用缓冲以减少延迟 autoCleanupSourceBuffer: true }); // 添加事件监听器 flvPlayer.value.on(flvjs.Events.ERROR, handlePlayerError); flvPlayer.value.on(flvjs.Events.METADATA_ARRIVED, () => { console.log(&#39;流媒体元数据已接收&#39;); }); // 绑定视频元素并播放 if (videoPlayer.value) { flvPlayer.value.attachMediaElement(videoPlayer.value); flvPlayer.value.load(); // 尝试播放 const playPromise = flvPlayer.value.play(); if (playPromise !== undefined) { playPromise.catch((err: unknown) => { handlePlayerError(flvjs.ErrorTypes.NETWORK_ERROR, err); }); } connectionStatus.value = &#39;connected&#39;; } } catch (error) { handleConnectionError(error as Error); } }; // 断开连接 const disconnectCamera = () => { if (flvPlayer.value) { flvPlayer.value.pause(); flvPlayer.value.unload(); flvPlayer.value.detachMediaElement(); flvPlayer.value.destroy(); flvPlayer.value = null; } connectionStatus.value = &#39;disconnected&#39;; }; // 处理播放器错误 const handlePlayerError = (type: string, detail: any) => { console.error(&#39;FLV播放器错误:&#39;, type, detail); // 根据错误类型处理 if (type === flvjs.ErrorTypes.NETWORK_ERROR) { errorMessage.value = &#39;网络错误: 无法连接到视频流&#39;; } else if (type === flvjs.ErrorTypes.MEDIA_ERROR) { errorMessage.value = &#39;媒体错误: 流格式不受支持&#39;; } else { errorMessage.value = `播放器错误: ${detail || &#39;未知错误&#39;}`; } connectionStatus.value = &#39;error&#39;; // 尝试重新连接 if (reconnectAttempts.value < maxReconnectAttempts) { reconnectAttempts.value += 1; setTimeout(() => { if (connectionStatus.value !== &#39;connected&#39;) { connectCamera(); } }, 2000 * reconnectAttempts.value); // 指数退避重连 } }; // 处理连接错误 const handleConnectionError = (error: Error) => { console.error(&#39;摄像头连接错误:&#39;, error); errorMessage.value = error.message || &#39;连接摄像头失败&#39;; connectionStatus.value = &#39;error&#39;; // 尝试重新连接 if (reconnectAttempts.value < maxReconnectAttempts) { reconnectAttempts.value += 1; setTimeout(connectCamera, 3000); } }; // 验证摄像头URL格式 const validateCameraUrl = (url: string): boolean => { try { const rtspRegex = /^rtsp:\/\/.+/i; return rtspRegex.test(url); } catch { return false; } }; // 获取流代理URL(实际项目中应调用后端API) const getStreamProxyUrl = (originalUrl: string): string => { // 在实际应用中,这里应该调用后端服务将RTSP转为HTTP-FLV // 示例中仅做URL编码处理 return `http://your-proxy-server/live?url=${encodeURIComponent(originalUrl)}`; }; // 组件卸载时自动断开连接 onBeforeUnmount(() => { disconnectCamera(); }); return { videoPlayer, cameraUrl, connectionStatus, connectionStatusText, connectionStatusClass, errorMessage, isConnecting, isConnected, connectCamera, disconnectCamera }; } }); </script> <style scoped> .camera-container { max-width: 800px; margin: 0 auto; padding: 20px; background: #f5f5f5; border-radius: 8px; } video { width: 100%; background: #000; border-radius: 4px; } .controls { margin-top: 15px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; } .url-input { flex: 1; min-width: 300px; padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px; } button { padding: 8px 15px; background: #42b983; color: white; border: none; border-radius: 4px; cursor: pointer; transition: background 0.3s; } button:disabled { background: #cccccc; cursor: not-allowed; } button:not(:disabled):hover { background: #359c6f; } .status-indicator { padding: 5px 10px; border-radius: 4px; font-size: 0.9em; } .status-disconnected { background: #ffdddd; color: #cc0000; } .status-connecting { background: #fff8dd; color: #e6b800; } .status-connected { background: #ddffdd; color: #00aa00; } .status-error { background: #ffdddd; color: #cc0000; } .error-message { margin-top: 10px; padding: 10px; background: #ffebee; color: #b71c1c; border-radius: 4px; } </style>
07-10
PDF生成错误:, TypeError: undefined is not a function (near &#39;...webview.contentsToPDF...&#39;) at pages/home/components/webview.vue:76 __ERROR <template> <view class="webview-container"> <cover-view class="webview-wrapper"> <web-view :src="webviewPath" id="targetWebview" ></web-view> </cover-view> <cover-view class="bottom-action-area"> <cover-view class="capture-btn" @click="generatePdfFromWebview"> <cover-view class="btn-text">立即取证</cover-view> </cover-view> </cover-view> </view> </template> <script setup lang="ts"> import { onLoad } from &#39;@dcloudio/uni-app&#39;; import { ref } from &#39;vue&#39;; const currentPageInfo = ref(&#39;&#39;); const webviewPath = ref(&#39;&#39;); onLoad((options: any) => { if (options.url) { webviewPath.value = decodeURIComponent(options.url); } }); const generatePdfFromWebview = async () => { // 获取当前webview对象 // const pages = uni.getCurrentPages(); // if (!pages.length) return; // // 获取当前页面实例(最后一个页面) // const currentPage = pages[pages.length - 1]; // // 获取当前页面的原生Webview对象 // const currentWebview = currentPage.$getAppWebview(); // // 获取Webview子组件(即web-view组件) // const webview = currentWebview.children()[0] // // 捕获网页内容并转换为PDF // webview.capture((captureResult) => { // if (captureResult) { // // 生成PDF文件路径 // const pdfPath = &#39;_doc/&#39; + Date.now() + &#39;.pdf&#39;; // plus.io.resolveLocalFileSystemURL(pdfPath, (entry) => { // entry.createWriter((writer) => { // writer.write(captureResult); // writer.onwriteend = () => { // // 跳转到PDF预览页 // uni.navigateTo({ // url: `pages/home/components/Webpreview?pdfPath=${encodeURIComponent(pdfPath)}` // }); // }; // }); // }); // } // }, { // format: &#39;pdf&#39;, // 指定生成PDF格式 // quality: 100, // 质量设置 // filename: &#39;webview-content&#39; // 文件名 // }); try { uni.showLoading({ title: &#39;生成中...&#39;, mask: true }); const filePath = await captureWebviewPDF(); uni.hideLoading(); uni.navigateTo({ url: `/pages/home/components/Webpreview?pdfPath=${encodeURIComponent(filePath)}` }); } catch (e) { uni.hideLoading(); uni.showToast({ title: `生成失败: ${e}`, icon: &#39;none&#39;, duration: 3000 }); console.error(&#39;PDF生成错误:&#39;, e); } }; const captureWebviewPDF = (): Promise<string> => { return new Promise((resolve, reject) => { // 获取当前页面WebView对象 const pages = getCurrentPages(); if (!pages.length) return reject(&#39;页面栈为空&#39;); const currentPage = pages[pages.length - 1]; // @ts-ignore const currentWebview = currentPage.$getAppWebview?.() || currentPage.$scope?.$getAppWebview?.(); if (!currentWebview) return reject(&#39;无法获取WebView对象&#39;); const webview = currentWebview.children()[0]; const platform = uni.getSystemInfoSync().platform; // if (platform === &#39;android&#39;) { // // Android 解决方案 // plus.android.importClass(&#39;android.graphics.Bitmap&#39;); // plus.android.importClass(&#39;android.graphics.pdf.PdfDocument&#39;); // webview.captureBitmap((bitmap: any) => { // try { // const pdfDoc = new plus.android.newObject(&#39;android.graphics.pdf.PdfDocument&#39;); // const pageInfo = new plus.android.newObject( // &#39;android.graphics.pdf.PdfDocument$PageInfo$Builder&#39;, // bitmap.getWidth(), // bitmap.getHeight(), // 1 // ).create(); // const page = pdfDoc.startPage(pageInfo); // page.getCanvas().drawBitmap(bitmap, 0, 0, null); // pdfDoc.finishPage(page); // const fileName = `capture_${Date.now()}.pdf`; // const filePath = `${plus.io.PUBLIC_DOWNLOADS}/${fileName}`; // const stream = plus.io.createStream(filePath); // pdfDoc.writeTo(stream); // stream.close(); // resolve(filePath); // } catch (e) { // reject(`Android生成失败: ${e}`); // } // }); // } else if (platform === &#39;ios&#39;) { // iOS 解决方案 const fileName = `capture_${Date.now()}.pdf`; const filePath = `${plus.io.PUBLIC_DOCUMENTS}/${fileName}`; webview.contentsToPDF({ filename: filePath }, (res: any) => { resolve(filePath); }, (err: any) => { reject(`iOS生成失败: ${err}`); }); // } else { // reject(&#39;不支持该平台&#39;); // } }); }; </script> <style> .webview-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .webview-wrapper { height: calc(100vh - 120rpx); width: 100%; overflow: hidden; } .bottom-action-area { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background-color: #007aff; padding: 30rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; align-items: center; } .capture-btn { width: 100%; height: 90rpx; background-color: #007aff; border-radius: 45rpx; box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2); display: flex; align-items: center; justify-content: center; } .btn-text { color: #ffffff; font-size: 32rpx; font-weight: 500; } /* PDF预览组件样式 */ .custom-preview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; padding: 0 0 40rpx 0; box-sizing: border-box; } .preview-header { width: 100%; height: 100rpx; background-color: #007aff; color: #ffffff; display: flex; align-items: center; justify-content: center; position: relative; } .title-container { display: flex; align-items: center; justify-content: center; width: 100%; } .preview-title { color: #ffffff; font-size: 34rpx; font-weight: bold; } .close-btn { position: absolute; right: 30rpx; font-size: 40rpx; color: white; } .preview-pdf { width: 100%; height: calc(100% - 100rpx - 120rpx); background-color: white; } .action-buttons { display: flex; width: 100%; justify-content: space-between; padding: 30rpx 5%; margin-top: auto; background-color: #353336; box-sizing: border-box; } .action-btn { flex: 1; height: 90rpx; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; margin: 0 15rpx; color: #ffffff; font-size: 34rpx; font-weight: 500; } .cancel-btn { background-color: #666; } .confirm-btn { background-color: #007aff; } </style>
08-12
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <style> /* styles.css */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f2f2f2; } h1 { margin: 0; } main { max-width: 800px; margin: 20px auto; padding: 20px; background-color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } #box { display: flex; flex-direction: column; align-items: center; } .buttons { margin-bottom: 20px; } button { padding: 10px 20px; margin-right: 10px; background-color: #333; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .background-div { margin-bottom: 20px; } .background-btn { padding: 10px 20px; background-color: #333; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .content { width: 80%; background-color: #f9f9f9; padding: 20px; } h2 { margin-top: 0; } #todo-form { display: flex; justify-content: center; align-items: center; margin-bottom: 10px; gap: 10px; } .input-field { padding: 10px; flex: 1; } .submit-btn { padding: 10px 20px; background-color: #333; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .list { height: 400px; } .item { height: 40px; border-radius: 4px; line-height: 40px; padding: 8px; margin-bottom: 8px; background-color: #eee; } .item:hover { background-color: #ccc; } .hidden { display: none; } #myCanvas { /* display: none; */ } </style> <body> <main> <div class="buttons"> <button class="start-btn" id="start-btn">开始录制</button> <button class="pause-btn">暂停录制</button> <button class="resume-btn">继续录制</button> <button class="stop-btn" id="stop-btn">结束录制</button> </div> <div id="box"> <video width="100%" height="100" src="抖音-记录美好生活.mp4" autoplay controls></video> <section class="content"> <h2>TODO LIST</h2> <div class="background-div"> <button class="background-btn">切换背景颜色</button> </div> <div id="todo-form"> <input type="text" class="input-field" placeholder="输入待办事项" /> <button type="submit" class="submit-btn">提交</button> </div> <div class="list"></div> </section> <canvas id="myCanvas"></canvas> </div> <img src="" alt="" class="hidden" /> </main> <script src="https://cdn.bootcdn.net/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> <script> // 假设我们有一个目标元素 #target 和一个用于绘制的 canvas 元素 #myCanvas const target = document.getElementById(&#39;box&#39;); const canvas = document.getElementById(&#39;myCanvas&#39;); const startBtn = document.getElementById(&#39;start-btn&#39;); const stopBtn = document.getElementById(&#39;stop-btn&#39;); let mediaRecorder; let recordedChunks = []; let animationId; let stream; async function captureCanvas() { try { // 使用html2canvas捕获目标元素 const canvasElement = await html2canvas(target); const ctx = canvas.getContext(&#39;2d&#39;); // 将捕获的内容绘制到canvas上 canvas.width = canvasElement.width; canvas.height = canvasElement.height; ctx.drawImage(canvasElement, 0, 0); } catch (error) { console.error(&#39;捕获失败:&#39;, error); } } // 开始录制 startBtn.addEventListener(&#39;click&#39;, async () => { recordedChunks = []; // 先绘制一次,确保canvas有内容 await captureCanvas(); // 获取canvas的媒体流,设置帧率(例如30fps) stream = canvas.captureStream(30); mediaRecorder = new MediaRecorder(stream, { mimeType: &#39;video/webm;codecs=vp9&#39; }); mediaRecorder.ondataavailable = event => { if (event.data.size > 0) { recordedChunks.push(event.data); } }; mediaRecorder.onstop = () => { // 合并数据并生成视频文件 const blob = new Blob(recordedChunks, { type: &#39;video/webm&#39; }); const url = URL.createObjectURL(blob); const a = document.createElement(&#39;a&#39;); a.href = url; a.download = &#39;recorded.webm&#39;; a.click(); // 释放资源 stream.getTracks().forEach(track => track.stop()); URL.revokeObjectURL(url); }; mediaRecorder.start(); // 开始循环绘制,以保持视频流的持续生成 function updateCanvas() { captureCanvas().then(() => { animationId = requestAnimationFrame(updateCanvas); }); } updateCanvas(); }); // 停止录制 stopBtn.addEventListener(&#39;click&#39;, () => { mediaRecorder.stop(); cancelAnimationFrame(animationId); }); </script> </body> </html> 以上代码在html2canvas转视频是如何收录视频和音频,请给出一个完整的案例
最新发布
08-15
<template> <view class="webview-container"> <cover-view class="webview-wrapper"> <web-view :src="webviewPath" id="targetWebview" ></web-view> </cover-view> <cover-view class="bottom-action-area"> <cover-view class="capture-btn" @click="generatePdfFromWebview"> <cover-view class="btn-text">立即取证</cover-view> </cover-view> </cover-view> </view> </template> <script setup lang="ts"> import { onLoad } from &#39;@dcloudio/uni-app&#39;; import { ref } from &#39;vue&#39;; const currentPageInfo = ref(&#39;&#39;); const webviewPath = ref(&#39;&#39;); onLoad((options: any) => { if (options.url) { webviewPath.value = decodeURIComponent(options.url); } }); const generatePdfFromWebview = async () => { // 获取当前webview对象 // const pages = uni.getCurrentPages(); // if (!pages.length) return; // // 获取当前页面实例(最后一个页面) // const currentPage = pages[pages.length - 1]; // // 获取当前页面的原生Webview对象 // const currentWebview = currentPage.$getAppWebview(); // // 获取Webview子组件(即web-view组件) // const webview = currentWebview.children()[0] // // 捕获网页内容并转换为PDF // webview.capture((captureResult) => { // if (captureResult) { // // 生成PDF文件路径 // const pdfPath = &#39;_doc/&#39; + Date.now() + &#39;.pdf&#39;; // plus.io.resolveLocalFileSystemURL(pdfPath, (entry) => { // entry.createWriter((writer) => { // writer.write(captureResult); // writer.onwriteend = () => { // // 跳转到PDF预览页 // uni.navigateTo({ // url: `pages/home/components/Webpreview?pdfPath=${encodeURIComponent(pdfPath)}` // }); // }; // }); // }); // } // }, { // format: &#39;pdf&#39;, // 指定生成PDF格式 // quality: 100, // 质量设置 // filename: &#39;webview-content&#39; // 文件名 // }); try { // 调用原生捕获 const filePath = await captureWebviewPDF() // 跳转预览页 uni.navigateTo({ // url: `/pages/pdf-preview?filePath=${encodeURIComponent(filePath)}` url: `pages/home/components/Webpreview?pdfPath=${encodeURIComponent(filePath)}` }) } catch (e) { uni.showToast({ title: &#39;生成失败&#39;, icon: &#39;error&#39; }) } }; const captureWebviewPDF = () => { return new Promise((resolve, reject) => { if (uni.getSystemInfoSync().platform === &#39;android&#39;) { // Android 使用原生渲染 plus.android.importClass(&#39;android.graphics.pdf.PdfDocument&#39;) const webview = plus.webview.currentWebview() webview.captureBitmap(bitmap => { const pdfDoc = new PdfDocument() const page = pdfDoc.startPage(bitmap.width, bitmap.height) page.canvas.drawBitmap(bitmap, 0, 0, null) pdfDoc.finishPage(page) const filePath = `${plus.io.PUBLIC_DOWNLOADS}/capture_${Date.now()}.pdf` pdfDoc.writeToStream(plus.io.createStream(filePath)) resolve(filePath) }) } else { // iOS 使用 WKWebView 截图 const webview = plus.webview.currentWebview() webview.contentsToPDF({ success: (filePath) => resolve(filePath), fail: (e) => reject(e) }) } }) } </script> <style> .webview-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .webview-wrapper { height: calc(100vh - 120rpx); width: 100%; overflow: hidden; } .bottom-action-area { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background-color: #007aff; padding: 30rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; align-items: center; } .capture-btn { width: 100%; height: 90rpx; background-color: #007aff; border-radius: 45rpx; box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2); display: flex; align-items: center; justify-content: center; } .btn-text { color: #ffffff; font-size: 32rpx; font-weight: 500; } /* PDF预览组件样式 */ .custom-preview { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; padding: 0 0 40rpx 0; box-sizing: border-box; } .preview-header { width: 100%; height: 100rpx; background-color: #007aff; color: #ffffff; display: flex; align-items: center; justify-content: center; position: relative; } .title-container { display: flex; align-items: center; justify-content: center; width: 100%; } .preview-title { color: #ffffff; font-size: 34rpx; font-weight: bold; } .close-btn { position: absolute; right: 30rpx; font-size: 40rpx; color: white; } .preview-pdf { width: 100%; height: calc(100% - 100rpx - 120rpx); background-color: white; } .action-buttons { display: flex; width: 100%; justify-content: space-between; padding: 30rpx 5%; margin-top: auto; background-color: #353336; box-sizing: border-box; } .action-btn { flex: 1; height: 90rpx; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; margin: 0 15rpx; color: #ffffff; font-size: 34rpx; font-weight: 500; } .cancel-btn { background-color: #666; } .confirm-btn { background-color: #007aff; } </style> 类型“PlusWebviewWebviewObject”上不存在属性“captureBitmap”。 找不到名称“PdfDocument”。你是否指的是“Document”? 类型“PlusIo”上不存在属性“createStream”。 类型“PlusWebviewWebviewObject”上不存在属性“contentsToPDF”。
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值