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