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.

Playing sound on device

See original GitHub issue

I can get my sounds and the demo app sounds to work on the ios simulator but when I build to my phone on both apps I get no sound. No errors, the app recognizes the mp3 file because I get the length of the mp3 just fine with getDuration(), here is some of the code, what am I missing?

class MusicPlayer extends Component {
  constructor() {
    super();
    this.playSong = this.playSong.bind(this);
    this.pauseSong = this.pauseSong.bind(this);
    this.changeVolume = this.changeVolume.bind(this);
    this.backPress = this.backPress.bind(this);
    this.tick = this.tick.bind(this);
    this.state = {
      volume: .5,
      isPlaying: false,
      songLength: 0,
      currentTime: 0,
      interval: null,
      error: null
    }
  }

  componentWillMount() {
    var song = new Sound('collide.mp3', Sound.MAIN_BUNDLE, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        this.setState({
          error:error.message
        })
      } else { // loaded successfully
        console.log('duration in seconds: ' + song.getDuration() +
            'number of channels: ' + song.getNumberOfChannels());
        this.setState({
          volume: .5,
          song: song,
          isPlaying: false,
          songLength: song.getDuration(),
          currentTime: 0,
          interval: null,
          error: null
        })
      }
    });
  }

  playSong() {
    this.state.song.play();
    this.setState({
      isPlaying: true,
      interval: setInterval(this.tick, 1000)
    })
  }

  pauseSong() {
    this.state.song.pause();
    this.setState({
      isPlaying: false,
      interval: clearInterval(this.state.interval)
    })
  }

  tick() {
    this.state.song.getCurrentTime((seconds) => {
      this.setState({
        currentTime: seconds
      })
    })
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Frosty92commented, May 25, 2016

@boblad, take solace in knowing that you aren’t the only one feeling stupid. Thanks for your prompt reply, it fixed my issue!

2reactions
bobladcommented, May 25, 2016

@Frosty92 I felt really stupid when I figured out my issue, Even if your sound is all up on Ios but your sound switch on the side or your phone is off it wont play. I think there is a method in the docs that overrides this though.

On Wed, May 25, 2016 at 3:16 PM, Hamza Hassan notifications@github.com wrote:

I am having the same problem, any updates @boblad https://github.com/boblad ?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/zmxv/react-native-sound/issues/38#issuecomment-221710051

Read more comments on GitHub >

github_iconTop Results From Across the Web

Play a sound on a device with Find Devices on iCloud.com
Play a sound on your iPhone, iPad, iPod touch, Mac, or Apple Watch ... In Find Devices on iCloud.com, click All Devices, then...
Read more >
How To Play Sounds on 2 Devices in Windows - Alphr
1. Make sure that your external devices are connected to your computer. 2. Open “Settings,” then click on “System.” 3. Click on the...
Read more >
Play Android Audio on Google Nest or Home devices
Play popular music, playlists, podcasts, and more from your Android device to Google Nest or Home speakers or displays. This is also known...
Read more >
Fix sound or audio problems in Windows - Microsoft Support
Select Hardware and Sound from the Control Panel, and then select Sound. On the Playback tab, select and hold (or right-click) Default Device,...
Read more >
Play a sound - iCloud Help
In the device's Info window, click Play Sound. Play Sound button in the device's Info window. If the device is online, the sound...
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