From 1f2268afb00e73458d2089edd76ac52300eee12e Mon Sep 17 00:00:00 2001 From: Jin Yufeng <1750665@tongji.edu.cn> Date: Tue, 25 Jan 2022 23:20:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pauseMedia=20=E7=9A=84=20a?= =?UTF-8?q?pi=EF=BC=8C=E5=8F=AF=E7=94=A8=E4=BA=8E=E6=9A=82=E5=81=9C?= =?UTF-8?q?=E5=AA=92=E4=BD=93=E6=92=AD=E6=94=BE=20#317?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/miniprogram/index.js | 9 +++++++++ src/uni-app/components/mp-html/mp-html.vue | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/miniprogram/index.js b/src/miniprogram/index.js index 085266a2..a09df2d6 100644 --- a/src/miniprogram/index.js +++ b/src/miniprogram/index.js @@ -282,6 +282,15 @@ Component({ }) }, + /** + * @description 暂停播放媒体 + */ + pauseMedia () { + for (let i = (this._videos || []).length; i--;) { + this._videos[i].pause() + } + }, + /** * @description 设置富文本内容 * @param {string} content 要渲染的 html 字符串 diff --git a/src/uni-app/components/mp-html/mp-html.vue b/src/uni-app/components/mp-html/mp-html.vue index 2190312c..72939a74 100644 --- a/src/uni-app/components/mp-html/mp-html.vue +++ b/src/uni-app/components/mp-html/mp-html.vue @@ -260,6 +260,24 @@ export default { }) }, + /** + * @description 暂停播放媒体 + */ + pauseMedia () { + for (let i = (this._videos || []).length; i--;) { + this._videos[i].pause() + } + // #ifdef APP-PLUS + const command = 'for(var e=document.getElementsByTagName("video"),i=e.length;i--;)e[i].pause()' + // #ifndef APP-PLUS-NVUE + this.$mp.page.$getAppWebview().evalJS(command) + // #endif + // #ifdef APP-PLUS-NVUE + this.$refs.web.evalJs(command) + // #endif + // #endif + }, + /** * @description 设置内容 * @param {String} content html 内容