Catch error when play audio

How can i solve this error?

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  Button,
} from 'react-native';
import {Audio} from 'expo-av';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.press = this.press.bind(this);
  }

  press() {
    this.playSound();
  }

  async playSound() {
    const soundObject = new Audio.Sound();
    try {
      await soundObject.loadAsync(require('./assets/Motherboard.mp3'));
      await soundObject.playAsync();
    } catch (error) {
      alert('An error occurred!')
    }
  }

  render() {
    return (
      <TouchableOpacity 
        style={styles.container}
        onPress={this.press}
      >
        <Text>Play</Text>
      </TouchableOpacity>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

This is my snacks

Please elaborate on what error you are getting?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.