No audio playback when utilizing Expo AV for iOS in a React Native challenge


I’ve been making an attempt for a pair days simply to have the ability to get a sound to play on my iOS simulator (at present utilizing XCode’s Simulator app). All I am searching for is to have the ability to press the “Pressable” part, and set off audio playback. I’ve run npx expo replace to make sure that all of my packages are updated. I’ve additionally ensured that the trail to my audio file is right.

That is the code I’ve at present:

import { View, Textual content, Pressable } from 'react-native'
import React, { useEffect, useRef, useState } from 'react'

import { Audio } from 'expo-av';


export default operate TrackBody({trackIndex, contents, isPlaying, updateTrackContents}) {

    const soundRef = useRef(null);

    useEffect(() => {
        
        const loadSounds = async () => {
            attempt {
                const sound = new Audio.Sound();
                await sound.loadAsync(require("../belongings/audio/samples/audio.mp3"));
                console.log('Sound Loaded Efficiently');
                console.log(sound);
                soundRef.present = sound;
                console.log("Playback status1:", await soundRef.present.getStatusAsync());
            } catch (error) {
                console.log("Error loading sound:", error);
            }
            
        };
        loadSounds();

        return () => {
            console.log('Sound Unloading')
            soundRef.present && soundRef.present.unloadAsync();
            console.log(soundRef.present)
        };
    }, []);

    const testSound = async () => {

        attempt {
            if (soundRef.present) {
                const standing = await soundRef.present.getStatusAsync();
                await soundRef.present.playAsync();
                console.log('here3')
            } else {
                console.log("Sound reference is null: ", soundRef)
            }
        } catch (error) {
            console.log(error)
        }
    }

  return (
    <View>
        <Pressable type={{backgroundColor: 'purple', peak: 40, width: 40}} onPress={async () => await testSound()}></Pressable>
    </View>
  )
}

Am I making some form of obvious mistake? Irrespective of what number of movies I observe, or what number of occasions I replicate the code from the docs exactly, I’m unable to get audio to play utilizing this package deal.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles