You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 17:10:37