react-native-sound icon indicating copy to clipboard operation
react-native-sound copied to clipboard

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

Open septe01 opened this issue 3 years ago • 2 comments

: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...

  • [^] iOS
  • [ ] Android
  • [ ] Windows

Are you using...

  • [^] React Native CLI (e.g. react-native run-android)
  • [ ] Expo
  • [ ] Other: (please specify)

Which versions are you using?

  • React Native Sound: "^0.11.2"
  • React Native: "0.66.4"

Does the problem occur on...

  • [^] Simulator
  • [^] Device

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

  • Device:

septe01 avatar Jan 15 '22 02:01 septe01

@septe01 Did you find any workaround for this ?

sperezm97 avatar Feb 06 '22 19:02 sperezm97

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

ViktorsLV avatar Dec 13 '23 21:12 ViktorsLV