关于 Vue 微信客户端 不能播放音乐(报错和不能播放的问题)
前言
用vue 做音乐播放的时候,在本地可以打开播放,但在微信里面不能播放音乐
所以这样解决
// 音乐播放
audioPlay(){
let _this = this;
var audio = _this.music;
if(_this.bgmUrl){
audio.src = _this.bgmUrl;
//audio.play();
_this.esPlayMusic();
_this.timeupdate();
wx.ready(()=>{
})
typeof WeixinJSBridge !== 'undefined' && WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
//audio.play();
_this.esPlayMusic();
_this.timeupdate();
});
}
},
timeupdate() {
let _this = this;
var audio = _this.music;
audio.addEventListener("timeupdate", function() {
var duration = this.duration;
var currentTime = this.currentTime;
var percentage = (currentTime / duration) * 100;
if (percentage == 100) {
_this.audioPlay();
typeof WeixinJSBridge !== 'undefined' && WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
_this.audioPlay();
});
}
})
},
主要是这段代码
typeof WeixinJSBridge !== 'undefined' && WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
//audio.play();
_this.esPlayMusic();
_this.timeupdate();
});
后来又因为 点击过快 出现报错了
The play() request was interrupted by a call to pause()
因为上一个用户的播报还没结束,这一个播报就要覆盖上来了,所以需要异步处理下
上代码了
// 异步加载音乐播放
esPlayMusic(){
let _this = this;
//let audio = document.getElementById("audioPlay");
var audio = _this.music;
//audio.play();
var playPromise = audio.play();
if (playPromise) {
playPromise.then(() => {
// 音频加载成功
// 音频的播放需要耗时
setTimeout(() => {
// 后续操作
//console.log("done");
}, audio.duration * 1000); // audio.duration 为音频的时长单位为秒 }).catch((e) => {
//console.log("Operation is too fast, audio play fails");
});
}
},
这样就解决了
关于 Vue 微信客户端 不能播放音乐(报错和不能播放的问题)的更多相关文章
- 新版uni-app 在微信小工具调试遇到报错解决方案
问题描述:我在运行到微信小程序是运行报错打不开微信小程序报错如下图 结局方案:将微信小程序安全设置开启如下图
- vue 使用webpack打包后路径报错以及 alias 的使用
一.vue 使用webpack打包后路径报错(两步解决) 1. config文件夹 ==> index.js ==> 把assetsPublicPath的 '/ '改为 './' 2. b ...
- Vue学习笔记-vue-element-admin 按装报错再按装
一 使用环境 开发系统: windows 后端IDE: PyCharm 前端IDE: VSCode 数据库: msyql,navicat 编程语言: python3.7 (Windows x86- ...
- vue 音乐播放器报错
使用Vue报错[Vue warn]: Error in nextTick: "TypeError: fn.bind is not a function"页面进不去. 检查:看看da ...
- 谷歌浏览器不能播放audio 报错Uncaught (in promise) DOMException
在2018年4月份发布的Chrome 66正式关掉了声音自动播放,也就是说<audio autopaly></audio> <video autoplay>< ...
- Vue入门之旅:一报错 Unknown ... make sure to provide the "name" option及error compiling template
报错一: Unknown custom element: <custom-select> - did you register the component correctly? For r ...
- vue安装遇到的5个报错小结
前言 这篇博文不会教你怎么安装vue,但会告知安装过程中可能遇到的5个问题 2017年我写过一篇安装vue的博客,详情:https://www.cnblogs.com/tu-0718/p/752109 ...
- Nuxt.js vue init nuxt-community/koa-template 初始化项目报错
报错提示: Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functi ...
- Vue 项目中的ESlint语法报错问题
在项目中的""和;经常会报错,真的很纠结,今天看到一个解决方法,可以不用卸载删除 在项目根目录中,新建一个.prettierrc文件,来移除分号,和替换为单引号. { " ...
随机推荐
- 461. 汉明距离(Hamming Distance)leetcode
首先附上题目链接: https://leetcode-cn.com/problems/hamming-distance/ 一:题目 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. ...
- Linux常用目录名称
目录 用途 / 虚拟目录的根文件,通常不会在这里存储文件 /bin 二进制目录,存放许多用户的GNU工具 /boot 启动目录,存放启动文件 /dev 设备目录,Linux在这里创建设备节点 /etc ...
- finereport 填报 单元格 JS 触发 提交SQL 事件
var location = this.options.location; var cr = FR.cellStr2ColumnRow(location); var col = cr.col; var ...
- 【转帖】GBase 数据库
产品介绍 分析型数据管理系统 GBase 8a GBase 8a能够实现大数据的全数据(结构化数据.半结构化数据和非结构化数据)存储管理和高效分析,为行业大数据应用提供完整的数据库解决方案.GBase ...
- 如何决定使用 HashMap 还是 TreeMap? (转)
问:如何决定使用 HashMap 还是 TreeMap? 介绍 TreeMap<K,V>的Key值是要求实现java.lang.Comparable,所以迭代的时候TreeMap默认是按照 ...
- Codeforces 1220E. Tourism
传送门 这是一道英语题,首先要读懂题目: $\text{Alex believes that his trip will be interesting only if he will not use ...
- 关于redis的几件小事(七)redis缓存雪崩与穿透
1.缓存雪崩 (1)什么是缓存雪崩 缓存雪崩指的是在同一时刻,缓存大量失效,导致大量的请求直接到了数据库,数据库压力剧增,引起系统崩溃.可能出现的情况有: ①大量的key设置了相同的过期时间,导致在缓 ...
- springboot配置文件之yml的语法学习
springboot配置文件(.yml/.yaml.properties) YAML(YAML Ain't Markup Language) YAML A Markup Language:是一个标记语 ...
- python之time
1. 获取当前时间戳 # -*- coding: UTF- -*- import time print(time.time()) # 输出:1540693297.94459 2. 将时间戳格式化为本地 ...
- 浏览器进程线程时间循环、与vue netTick的实现原理
浏览器事件循环(结合vue nextTick)https://juejin.im/post/5cb736c5f265da039955d4e8#comment messageChanel的讲解https ...