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.

How to play sound from network?

See original GitHub issue

Hi everyone, I would like to know how to play a sound from a given url

I’m trying to run the following method which runs a local file and it also doesn’t work

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

function onPlaySound() {
  console.log('Sound started playing!');
  whoosh.play((success) => {
    if (success) {
      console.log('successfully finished playing');
    } else {
      console.log('playback failed due to audio decoding errors');
    }
  });
}

Would be grateful if someone could provide me with an example of how to run an mp3 from a url

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
trepiditycommented, Aug 4, 2017

Try this, inside your component

  _loadAudio = () => {
    const sound = new Sound(
      'https://s3.amazonaws.com/hanselminutes/hanselminutes_0001.mp3',
      undefined,
      (error) => {
        if (error) {
          console.log(error);
        } else {
          console.log('Playing sound');
          sound.play(() => {
            sound.release();
          });
        }
      }
    );
  };

  _componentDidMount = () => {
    this._loadAudio();
  };
4reactions
daramasalacommented, Jul 6, 2017

You must wait until the sound is loaded. The best way I found was to start playing in the oncomplete handler:

    const sound = new Sound('https://s3.amazonaws.com/hanselminutes/hanselminutes_0001.mp3',
      undefined,
      error => {
        if (error) {
          console.log(error)
        } else {
          console.log("Playing sound");
          sound.play(() => {
            // Release when it's done so we're not using up resources
            sound.release();
          });
        }
      });
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to play music through the Network speaker with a ... - Sony
Right-click the mouse and select Play To. Select the Network speaker. Using a computer with the Windows® XP OS or the Windows Vista®...
Read more >
Stream audio via LAN (Local Area Network) - VLC Only
Stream audio/mic from PC to PC via LAN (Local Area Network ) - VLC Only In In this video, I'll show how to...
Read more >
How to play music through the Network speaker with a ...
Using the computer, click Start. · Select All Programs. · Select Windows Media Player. · Select Library. · Select Media Sharing. · Select...
Read more >
Stream Windows audio over the network
Go into Control Panel > Sound > Recording > Right click in the devices list > Show disabled devices > Right click on...
Read more >
Listening to music on a PC via network connection (Windows ...
Connect the speaker and PC to your network. · Tap the NETWORK button. · Right-click on the Start screen of the PC. ·...
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