浏览代码

feat: 部分ios的safari浏览器不支持volume音量调节

TIANYONG 1 年之前
父节点
当前提交
38c48c301f
共有 3 个文件被更改,包括 19 次插入3 次删除
  1. 12 1
      src/helpers/metronome.ts
  2. 5 0
      src/view/tick/index.tsx
  3. 2 2
      vite.config.ts

+ 12 - 1
src/helpers/metronome.ts

@@ -132,7 +132,8 @@ class Metronome {
 	}
 	createAudio = (src: string): Promise<HTMLAudioElement | null> => {
 		return new Promise((resolve) => {
-			const a = new Audio(src + '?v=' + Date.now());
+			// const a = new Audio(src + '?v=' + Date.now());
+			const a = new Audio(src);
 			a.load();
 			a.onloadedmetadata = () => {
 				resolve(a);
@@ -197,6 +198,16 @@ class Metronome {
 		this.source = metronomeData.followAudioIndex === 1 ? audioData.tick : audioData.tock;
 		// this.source.volume(metronomeData.disable ? 0 : beatVolume);
 		this.source.volume = metronomeData.disable ? 0 : beatVolume
+		/**
+		 * https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLMediaElement/volume
+		 * volume属性在部分ios手机的Safari浏览器不被支持
+		 */
+		if (this.source.volume <= 0) {
+			this.source.muted = true
+		} else {
+			this.source.muted = false
+		}
+		console.log('音量',this.source,this.source.volume)
 		this.source.play();
 		metronomeData.followAudioIndex += 1;
 		metronomeData.followAudioIndex = metronomeData.followAudioIndex > metronomeData.totalNumerator ? 1 : metronomeData.followAudioIndex;

+ 5 - 0
src/view/tick/index.tsx

@@ -33,6 +33,11 @@ const handlePlay = (i: number, source: any | null) => {
 			if (source) {
 				const beatVolume = state.setting.beatVolume / 100
 				source.volume = beatVolume;
+				if (source.volume <= 0) {
+					source.muted = true
+				} else {
+					source.muted = false
+				}
 				source.play();
 			}
 			resolve(i);

+ 2 - 2
vite.config.ts

@@ -68,8 +68,8 @@ export default defineConfig({
 				// target: "https://test.lexiaoya.cn",
 				// target: "https://dev.kt.colexiu.com",
 				// target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
-				target: "https://test.resource.colexiu.com",
-				// target: "https://test.kt.colexiu.com",
+				// target: "https://test.resource.colexiu.com",
+				target: "https://test.kt.colexiu.com",
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/instrument/, ""),
 			},