question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sound found but play() doesn't fire

See original GitHub issue

Hi there, Just trying to implement a basic example with your component. Everything seems to be fine until I call play() and then nothing happens. I’ve tried delaying the call with setTimeout() but no luck.

Here’s my code:

componentDidMount: function() {
    var snd_testShort = new Sound('mymp3.mp3', Sound.MAIN_BUNDLE, (error) => {
      if (error) {
        console.log('snd_testShort - failed to load the sound', error); 
      } else { 
        //all the file details come back and are logged...
        console.log('snd_testShort - duration in seconds: ' + snd_testShort._duration +
            ' number of channels: ' + snd_testShort._numberOfChannels);

        //the below line fires
        console.log("snd_testShort - play attempt");

       //I get nothing back from the `play()` call - I can breakpoint in XCode and the play method there fires without issue
        snd_testShort.play((test) => {
          console.log("snd_testShort - TEST");
          if (test) {
            console.log('snd_testShort - successfully finished playing');
          } else {
            console.log('snd_testShort - playback failed due to audio decoding errors');
          }
        });
      }
    });

As stated, in XCode I can step through the following in RNSound (seemingly) without issue:

RCT_EXPORT_METHOD(play:(nonnull NSNumber*)key withCallback:(RCTResponseSenderBlock)callback) {
  AVAudioPlayer* player = [self playerForKey:key];
  if (player) {
    [[self callbackPool] setObject:[callback copy] forKey:key];
    [player play];
  }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

103reactions
dmwallacecommented, Apr 5, 2016

I found the same thing after a recent upgrade to the module. It appears you have to call .play() now inside the callback function passed to the Sound constructor. e.g.

old code (no longer works… if you console.log(sound) you will see that sound._loaded == false)

let sound = new Sound('path/to/file.wav', Sound.MAIN_BUNDLE, (error) => {
            if (error) {
                console.log('failed to load the sound', error);
            }
        });
        sound.play(); // no longer works... sound is not loaded yet

New code (works):

let sound = new Sound('path/to/file.wav', Sound.MAIN_BUNDLE, (error) => {
            if (error) {
                console.log('failed to load the sound', error);
            } else {
                sound.play(); // have to put the call to play() in the onload callback
            }
        });
3reactions
rgomezpcommented, Feb 10, 2019

This should be made more clear in documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

simple sounds will not play | Apple Developer Forums
I'm trying to play some simple interface sound effects, and the method I found online does not work. I don't get any errors...
Read more >
Try These Fixes When Your Sound is Not Working in Chrome
1. Launch Chrome. 2. Click on the three dots (or three horizontal lines) in the upper right-hand corner of the browser. 3. Go...
Read more >
PlaySound() mmslib does not play existing sound
This following code perfectly works: PlaySound(L"C:\\Windows\\Media\\Cityscape\\Windows Balloon.wav", 0, SND_FILENAME );.
Read more >
Chrome Sound Not Working: 8 Fixes - groovyPost
If audio stops while using Chrome, you can take different troubleshooting steps. Here are eight fixes for Chrome sound not working.
Read more >
Audio Not playing in Unity at all. [SOLVED] - Unity Forum
Hi tmanallen, does preview playback of sounds work in the editor? ... I have to try that, but it doesn't play in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found