shish 11 месяцев назад
Родитель
Сommit
c77cc9028e
2 измененных файлов с 62 добавлено и 42 удалено
  1. 31 21
      ghsApp/src/utils/util.js
  2. 31 21
      hdApp/src/utils/util.js

+ 31 - 21
ghsApp/src/utils/util.js

@@ -324,31 +324,41 @@ export async function callUp(mobile){
 
 //没有库存时的语音播放 shish
 export const noStockRemind = () =>{
-	if(uni.getSystemInfoSync().platform != 'windows'){
-		const innerAudioContext = uni.createInnerAudioContext()
-		innerAudioContext.autoplay = true
-		innerAudioContext.src = "/static/noStock.mp3"
-		innerAudioContext.volume = 1
-		innerAudioContext.onPlay()
-		innerAudioContext.onError()
-		innerAudioContext.onPause(function() {
-			innerAudioContext.destroy()
-		})
-	}
+	try{
+		if(uni.getSystemInfoSync().platform != 'windows'){
+			const innerAudioContext = uni.createInnerAudioContext()
+			innerAudioContext.autoplay = true
+			innerAudioContext.src = "/static/noStock.mp3"
+			innerAudioContext.volume = 1
+			innerAudioContext.onPlay()
+			innerAudioContext.onError()
+			innerAudioContext.onPause(function() {
+				innerAudioContext.destroy()
+			})
+		}
+	} catch (e) {
+      // 开发环境兼容处理
+      console.warn('开发环境音频播放异常(可忽略):', e);
+    }
 }
 
 //点击声效 shish
 export const hitRemind = () =>{
-	if(uni.getSystemInfoSync().platform != 'windows'){
-		const innerAudioContext = uni.createInnerAudioContext()
-		innerAudioContext.autoplay = true
-		innerAudioContext.src = '/static/hit.mp3'
-		innerAudioContext.onPlay()
-		innerAudioContext.onError()
-		innerAudioContext.onPause(function() {
-			innerAudioContext.destroy()
-		})
-	}
+	try{
+		if(uni.getSystemInfoSync().platform != 'windows'){
+			const innerAudioContext = uni.createInnerAudioContext()
+			innerAudioContext.autoplay = true
+			innerAudioContext.src = '/static/hit.mp3'
+			innerAudioContext.onPlay()
+			innerAudioContext.onError()
+			innerAudioContext.onPause(function() {
+				innerAudioContext.destroy()
+			})
+		}
+	} catch (e) {
+      // 开发环境兼容处理
+      console.warn('开发环境音频播放异常(可忽略):', e);
+    }
 }
 
 //去重 姜枫 2021.05.05

+ 31 - 21
hdApp/src/utils/util.js

@@ -303,16 +303,21 @@ export const unique = (arr) => {
 
 //点击声效 shish
 export const hitRemind = () =>{
-	if(uni.getSystemInfoSync().platform != 'windows'){
-		const innerAudioContext = uni.createInnerAudioContext()
-		innerAudioContext.autoplay = true
-		innerAudioContext.src = '/static/hit.mp3'
-		innerAudioContext.onPlay()
-		innerAudioContext.onError()
-		innerAudioContext.onPause(function() {
-			innerAudioContext.destroy()
-		})
-	}
+	try {
+		if(uni.getSystemInfoSync().platform != 'windows'){
+			const innerAudioContext = uni.createInnerAudioContext()
+			innerAudioContext.autoplay = true
+			innerAudioContext.src = '/static/hit.mp3'
+			innerAudioContext.onPlay()
+			innerAudioContext.onError()
+			innerAudioContext.onPause(function() {
+				innerAudioContext.destroy()
+			})
+		}
+	} catch (e) {
+      // 开发环境兼容处理
+      console.warn('开发环境音频播放异常(可忽略):', e);
+    }
 }
 
 
@@ -413,17 +418,22 @@ export const isScanEnv = () =>{
 
 //没有库存时的语音播放 shish
 export const noStockRemind = () =>{
-	if(uni.getSystemInfoSync().platform != 'windows'){
-		const innerAudioContext = uni.createInnerAudioContext()
-		innerAudioContext.autoplay = true
-		innerAudioContext.src = "/static/noStock.mp3"
-		innerAudioContext.volume = 1
-		innerAudioContext.onPlay()
-		innerAudioContext.onError()
-		innerAudioContext.onPause(function() {
-			innerAudioContext.destroy()
-		})
-	}
+	try{
+		if(uni.getSystemInfoSync().platform != 'windows'){
+			const innerAudioContext = uni.createInnerAudioContext()
+			innerAudioContext.autoplay = true
+			innerAudioContext.src = "/static/noStock.mp3"
+			innerAudioContext.volume = 1
+			innerAudioContext.onPlay()
+			innerAudioContext.onError()
+			innerAudioContext.onPause(function() {
+				innerAudioContext.destroy()
+			})
+		}
+	} catch (e) {
+      // 开发环境兼容处理
+      console.warn('开发环境音频播放异常(可忽略):', e);
+    }
 }
 
 export async function callUp(mobile){