SoundUtils.ts 610 B

123456789101112131415161718192021222324252627
  1. import { Audio } from 'expo-av';
  2. import request from './RequestUtils';
  3. async function play(sound) {
  4. console.log(sound);
  5. const soundObject = new Audio.Sound();
  6. try {
  7. await soundObject.loadAsync({ uri: sound });
  8. await soundObject.playAsync();
  9. await soundObject.unloadAsync();
  10. } catch (error) {
  11. // An error occurred!
  12. }
  13. }
  14. function SoundPlay(info) {
  15. const infos = info.split('_');
  16. console.log(infos);
  17. request.get(`/voice/get/${infos[1]}`).then((res) => {
  18. console.log(res);
  19. if (res.url) {
  20. play(res.url);
  21. }
  22. });
  23. }
  24. export { SoundPlay };