React-native-sound: When I play 13 different sound files the 14 will not play

Created on 29 Nov 2017  路  15Comments  路  Source: zmxv/react-native-sound

I have around 20 files of sound to play in my application but when I play 13 different audio files the next one will always get false on the play() method. I`ve tried every combination of release() and stop() possible. Even the reset doesn't 'recover' the audio player. This issue is happening on Android and using RN 0.42.3

Most helpful comment

I had similar problem. I solve it, when I create global variable with sound and call release before create new sound.

// @flow
import RNFS from 'react-native-fs'
import Sound from 'react-native-sound'
import { AlertError } from './elements/Alert'
import { strings } from '../app/i18n'

let sound = null

const playWord = (wordId: string) => {
  const pathToDir = RNFS.DocumentDirectoryPath + '/lingain-audio'
  const pathToFile = pathToDir + '/' + wordId + '.mp3'

  RNFS.exists(pathToFile).then(isExist => {
    if (isExist) {
      Sound.setCategory('Playback')

      if (sound !== null) sound.release()

      sound = new Sound(pathToFile, '', error => {
        if (!error) {
          sound.play(success => {
            if (!success) {
              // reset the player to its uninitialized state (android only)
              // this is the only option to recover after an error occured and use the player again
              sound.reset()
            }
          })
        }
      })

      sound.release()
    }
  })
}

export default playWord

All 15 comments

I faced same issue, do you get the solution on it?

I went native for Android. Did you get this error on iOS too ? I hope this lib will work fine with the iOS.

Yes its worked for iOS.

Nice. I haven`t implemented the iOS version of my project yet but for the android scenario I'd suggest you to go native for now. There is something wrong with the reset or release function that it is not working correctly relative to the Android system.

I'm trying to fix it now. Every time assigning the current playing sound to the state. If new sound playing, i'm releasing and stopping the current playing sound now it seems OK. I played over 30 sounds fastly and doesn't faced the problem

Did you play over 10 different audio files ? My issue is when I play over 10 audio files.

Yes over 20 different files tried over 30-40 times

Ok. That is good. I really tried every combination of stop and release possible for my code and the error persisted. I dunno maybe when I have more time in my project I will try this lib with android again.
I'm glad that is working with the iOS though.

Isn't this because your RAM is full? 13 audio files can fill your RAM memory? is it possible to play 13 audio files at a time?

I ain't know that every time the played audio files placed on ram automatically. We had to use release() function the remove it from RAM though

Maybe trying to load 13 audio files to RAM at a time caused this problem.. because this is not a usual task which smartphones do.

Can you play 13 different audio files at a time using this plugin? never tried it...

As I mentioned on the main thread I did try every combination of stop e release possible. I wasn`t trying to play 13 sounds concurrently.

I had similar problem. I solve it, when I create global variable with sound and call release before create new sound.

// @flow
import RNFS from 'react-native-fs'
import Sound from 'react-native-sound'
import { AlertError } from './elements/Alert'
import { strings } from '../app/i18n'

let sound = null

const playWord = (wordId: string) => {
  const pathToDir = RNFS.DocumentDirectoryPath + '/lingain-audio'
  const pathToFile = pathToDir + '/' + wordId + '.mp3'

  RNFS.exists(pathToFile).then(isExist => {
    if (isExist) {
      Sound.setCategory('Playback')

      if (sound !== null) sound.release()

      sound = new Sound(pathToFile, '', error => {
        if (!error) {
          sound.play(success => {
            if (!success) {
              // reset the player to its uninitialized state (android only)
              // this is the only option to recover after an error occured and use the player again
              sound.reset()
            }
          })
        }
      })

      sound.release()
    }
  })
}

export default playWord

I ran into this same thing. It would play some number of sound files out of an array of files, but would eventually lock up and not play anymore. As @oxilor pointed out above, by calling release() it seems to remove this issue. I call it in the success callback of play() so it's removed immediately after it plays then moves onto the next track.

Guys when you use release() it solves the problem. Thank you again.

Was this page helpful?
0 / 5 - 0 ratings