您的位置:首页 > 新闻 > 会展 > 室内装饰设计风格_品牌建设理论有哪些_北京百度推广投诉电话_百度指数怎么提升

室内装饰设计风格_品牌建设理论有哪些_北京百度推广投诉电话_百度指数怎么提升

2025/2/25 4:45:44 来源:https://blog.csdn.net/weixin_45264424/article/details/145449137  浏览:    关键词:室内装饰设计风格_品牌建设理论有哪些_北京百度推广投诉电话_百度指数怎么提升
室内装饰设计风格_品牌建设理论有哪些_北京百度推广投诉电话_百度指数怎么提升

方法一:通过显示“需要播放音频”弹窗,进行交互之后播放。

 <audio ref="audioRef"><source src="./mp3/tishi.mp3" /></audio><script setup>import { ref } from 'vue'let audioRef = ref(null)onMounted(() => {if (window.performance.navigation.type === 1) {//重新加载audioClick()} else {handelShow()}})const audioClick = () => {let startPlayPromise = audioRef.value.play()if (startPlayPromise !== undefined) {startPlayPromise.catch(error => {if (error.name === 'NotAllowedError') {// 弹窗引导用户与页面做交互,只需要一个简单的按钮即可// 记得在按钮上绑定一个带有play()方法的回调函数,以element-plus的组件为例ElMessageBox.alert('当前正在自动播放音频', '提示', {confirmButtonText: '确认',callback: () => {audioRef.value.play()},})}})}}const handelShow = () => {audioRef.value.play()}
</script>

方法二:通过监听页面点击事件,页面有交互之后播放。

 data() {return {initIntervalPlay:null,firstPlayVid: true,}},mounted() {const audio =document.getElementById("videoSound");let startPlayPromise = audio.play();if (startPlayPromise !== undefined) {//判断 首次进入用户没交互时,无法播放问题startPlayPromise.catch((error) => {document.removeEventListener('click', this.playHandle)document.addEventListener('click', this.playHandle)}).then(() => {this.intervalPlay()});}
}playHandle() {if (this.firstPlayVid) {document.getElementById("videoSound").play()this.intervalPlay()this.firstPlayVid = false}},//循环播报提示音intervalPlay(){if (this.initIntervalPlay) {window.clearInterval(this.initIntervalPlay)}this.initIntervalPlay = setInterval(() => {document.getElementById("videoSound").play()}, 5000)}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com