asaca
This commit is contained in:
@@ -101,22 +101,47 @@ const Index = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// // speak("欢迎使用"); // 语音播报
|
||||
|
||||
// const innerAudioContext = Taro.createInnerAudioContext();
|
||||
// innerAudioContext.src = baby;
|
||||
// innerAudioContext.autoplay = true;
|
||||
|
||||
// // 可选设置
|
||||
// innerAudioContext.onPlay(() => {
|
||||
// console.log("开始播放");
|
||||
// });
|
||||
// innerAudioContext.onError((res) => {
|
||||
// console.log(res.errMsg);
|
||||
// console.log(res.errCode);
|
||||
// });
|
||||
// }, []);
|
||||
|
||||
useEffect(() => {
|
||||
// speak("欢迎使用"); // 语音播报
|
||||
// const env = Taro.getEnv()
|
||||
// if (env !== Taro.ENV_TYPE.WEB) return
|
||||
|
||||
const innerAudioContext = Taro.createInnerAudioContext();
|
||||
innerAudioContext.src = baby;
|
||||
innerAudioContext.autoplay = true;
|
||||
const innerAudioContext = Taro.createInnerAudioContext()
|
||||
innerAudioContext.src = baby
|
||||
innerAudioContext.loop = true
|
||||
|
||||
// 可选设置
|
||||
innerAudioContext.onPlay(() => {
|
||||
console.log("开始播放");
|
||||
});
|
||||
innerAudioContext.onError((res) => {
|
||||
console.log(res.errMsg);
|
||||
console.log(res.errCode);
|
||||
});
|
||||
}, []);
|
||||
const handlePlay = () => {
|
||||
innerAudioContext.play()
|
||||
console.log('尝试播放音频')
|
||||
document.removeEventListener('touchstart', handlePlay)
|
||||
document.removeEventListener('click', handlePlay)
|
||||
}
|
||||
|
||||
document.addEventListener('touchstart', handlePlay, { once: true })
|
||||
document.addEventListener('click', handlePlay, { once: true })
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('touchstart', handlePlay)
|
||||
document.removeEventListener('click', handlePlay)
|
||||
innerAudioContext.destroy()
|
||||
}
|
||||
}, [])
|
||||
|
||||
// 在线测试地址
|
||||
// http://wstool.jackxiang.com/
|
||||
@@ -168,6 +193,8 @@ const Index = () => {
|
||||
<source src={testmpkv} type="video/mp4"></source>
|
||||
</video>
|
||||
</View> */}
|
||||
|
||||
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user