React Native Expo-av按钮触摸与音效播放延迟问题及优化方案
更新:
我留下这些内容是为了节省他人的研究时间。我使用onPressIn替代onPress来获得更好的效果。事件调用顺序如下:onPressIn --> onPressOut --> onPress
<TouchableWithoutFeedback onPressIn={() => {sound.play()}}> <View><Text></Text></View> </TouchableWithoutFeedback>
使用expo-av开发乐器APP:触摸按钮即时播放音效仍有延迟
如标题所述,我正尝试使用expo-av开发一款乐器APP,要求触摸按钮时能立即播放音效。我已预加载音效,延迟有所缩短但仍存在约50ms的滞后。
App.js
import { playSound } from "PlaySound"; export default function App() { const [sound, setSound] = useState({}); useEffect(() => { const getStateData = async () => { setSound(await playSound(require(`./assets/Sound/ding.mp3`))); }; getStateData(); }, []); return ( <TouchableWithoutFeedback onPress={() => { sound.play(); }} > <View> <Text></Text> </View> </TouchableWithoutFeedback> ); }
PlaySound.js
import { Audio } from "expo-av"; export async function playSound(path) { const audio = await Audio.Sound.createAsync(path); return { async play() { await audio.sound.replayAsync(); }, }; }
希望能得到进一步减少延迟的帮助,目标是实现无延迟的即时音效播放。
内容的提问来源于stack exchange,提问作者Raffy Norair
相关产品推荐
相关产品推荐

