liushengqiang hace 2 años
padre
commit
9fb37dabd3
Se han modificado 1 ficheros con 3 adiciones y 2 borrados
  1. 3 2
      src/view/audio-list/index.tsx

+ 3 - 2
src/view/audio-list/index.tsx

@@ -121,17 +121,18 @@ export default defineComponent({
 			return new Promise((resolve) => {
 				const a = new Audio(src);
 				a.load();
-				a.oncanplay = () => {
-					resolve(a);
+				a.onloadedmetadata = () => {
 					const _promise = a.play();
 					if (_promise !== undefined) {
 						_promise
 							.then((_) => {
 								// 这里就已经开始播放了
 								a.pause();
+								resolve(a);
 								// console.log("🚀 ~ _promise:", _promise);
 							})
 							.catch((error) => {
+								resolve(a);
 								// 无法自动播放
 								// console.log('无法自动播放')
 							});