React-native-web: Sound for react-native-web

Created on 29 Apr 2017  ·  3Comments  ·  Source: necolas/react-native-web

My apologies as this isn't really a bug but an inquiry, and I didn't know where else to post this (I assume SO would downvote this kind of question).

Has anyone gotten sound to work for devices and web with react-native-web? I have gotten sound to work for web with react-sound, but this doesn't work with iOS (e.g. “SoundManager requires a browser with window and document objects.”). I have gotten sound to work in iOS with react-native-sound, but this doesn't work with web (e.g. "Can't resolve 'react-native/Libraries/Image/resolveAssetSource' in '/Users/thayes/workspace/AquaReactNative/node_modules/react-native-sound'").

Is there an npm package out there that will get along with both react-native and web?

Most helpful comment

Hi @tgh, I use react-native-sound on native, and the howler.js library on web.

You should install howler with: npm install howler --save

Then create two files: sound.js and sound.web.js. This is the code I'm using: https://gist.github.com/ndbroadbent/64d71fc1f1f522e059676934b06f1a30

Then to play a sound:

import Sound from './sound'

new Sound(url).play()

All 3 comments

@ndbroadbent said he had a working version of react-native-sound https://github.com/necolas/react-native-web/issues/437#issuecomment-296383126. you might want to discuss with him

Hi @tgh, I use react-native-sound on native, and the howler.js library on web.

You should install howler with: npm install howler --save

Then create two files: sound.js and sound.web.js. This is the code I'm using: https://gist.github.com/ndbroadbent/64d71fc1f1f522e059676934b06f1a30

Then to play a sound:

import Sound from './sound'

new Sound(url).play()

@ndbroadbent I did this and passed the compile errors, however I get runtime errors because of this method:

  window.sound_background.getCurrentTime((seconds: number, isPlaying: boolean) => {
  if (isPlaying) {
     return;
  }

Do you think we can have the getCurrentTime exposed in howler similarly?

Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings