zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 748 forks source link

TypeError: onError is not a function. (In 'onError(error, props)', 'onError' is #778

Open septe01 opened 2 years ago

septe01 commented 2 years ago

:beetle: hello I implement this package for 2 devices android and ios, in Android no issue but when testing on Ios I have got an issue TypeError: onError is not a function. (In 'onError(error, props)', 'onError'

:beetle: after I observed the error message, I browsed to the package dir of the sound.js file and I found onError && onError(error, props); then I commented this error disappeared.

:beetle: myScript

import React, {useEffect} from 'react';
import {Text, View} from 'react-native';

import Sound from 'react-native-sound';

import dingSucces from './../assets/ringtone/game_success2.wav';
import dingFail from './../assets/ringtone/game_failed.mp3';
import dingGameOver from './../assets/ringtone/game_over.mp3';

Sound.setCategory('Playback');

const createSound = typeSound => {
  return new Sound(typeSound, Sound.MAIN_BUNDLE, error => {
    if (error) {
      console.log('------failed to load the sound', error);
      return;
    }
    // if loaded successfully
    console.log(
      '+++++duration in seconds: ' +
        typeSound.getDuration() +
        'number of channels: ' +
        typeSound.getNumberOfChannels(),
    );
  });
};

var ding = createSound(dingSucces);
var dingFailled = createSound(dingFail);
var dingGameOv = createSound(dingGameOver);

export default function SoundEffect() {
  const playPauseSucces = () => {
    ding.play(success => {
      if (success) {
        console.log('successfully finished playing');
      } else {
        console.log('playback failed due to audio decoding errors');
      }
    });
  };
  const playPauseFailled = () => {
    dingFailled.play(success => {
      if (success) {
        console.log('successfully finished playing');
      } else {
        console.log('playback failed due to audio decoding errors');
      }
    });
  };
  const playPauseGameOver = () => {
    dingGameOv.play(success => {
      if (success) {
        console.log('successfully finished playing');
      } else {
        console.log('playback failed due to audio decoding errors');
      }
    });
  };

  return [playPauseSucces, playPauseFailled, playPauseGameOver];
}

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

sperezm97 commented 2 years ago

@septe01 Did you find any workaround for this ?

ViktorsLV commented 6 months ago

Having the same issue, is there any solution to this?