Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play sound from JS bundle (main.jsbundle) #14

Open
gnestor opened this issue Jan 22, 2016 · 10 comments
Open

Play sound from JS bundle (main.jsbundle) #14

gnestor opened this issue Jan 22, 2016 · 10 comments

Comments

@gnestor
Copy link

gnestor commented Jan 22, 2016

As of react-native 0.14 (https://facebook.github.io/react-native/docs/images.html#static-image-resources), images and other assets can be bundled in the JS bundle and used by simply requiring them (e.g. <Image source={require('./my-icon.png')} />). Is it possible to play sounds that are in the JS bundle using react-native-sound?

Example:

let sound = new Sound('filename', Sound.JS_BUNDLE, (error, props) => {
    sound.play()
})
// or
let sound = new Sound(require('./filename'), (error, props) => {
    sound.play()
})
@zmxv
Copy link
Owner

zmxv commented Jan 22, 2016

This sounds like a good idea. It will save us the trouble of manually adding sound assets to XCode.
I'm not sure if the require syntax works for non-images, though. Can you confirm?

@gnestor
Copy link
Author

gnestor commented Jan 22, 2016

@amasad says it does: facebook/react-native#1043 (comment)

@danleveille
Copy link

@zmxv @gnestor So should this be working? Using require('./sound.mp3') gives me the following error:

Unable to resolve module ./sound.mp3 from [project]/index.ios.js: Invalid directory [project]/sound.mp3

@zmxv
Copy link
Owner

zmxv commented Feb 10, 2016

@danleveille Where is sound.mp3 located in your project?

@danleveille
Copy link

@zmxv For now I have it in the base project folder (same folder as index.ios.js, etc.). The path the error outputs is correct, which is strange because the file is definitely there.

@danleveille
Copy link

Just doing some more debugging:

When I do this:
var sound = require('./sound.mp3');

I get the error:

Unable to resolve module ./sound.mp3 from [project]/index.ios.js: Invalid directory [project]/sound.mp3

However, using an image seems to work fine:

var image = require('./image.png');

It seems like mp3 files aren't being included. Even if I put the MP3 file in node-modules/react-native-sound/

Any clue on how to make sure the mp3 file is included?

@zmxv
Copy link
Owner

zmxv commented Feb 18, 2016

@danleveille Is the mp3 file listed in the "Copy Bundle Resources" section under "Build Phases"?

@danleveille
Copy link

@zmxv No. Maybe I misinterpreted this Github issue. I thought @gnestor was suggesting that using require() would automatically include the MP3 file on both iOS and Android without having to manually add the sound files to to Xcode (and an Android directory).

@lopezjurip
Copy link

What's the current state of this issue?

@zmxv
Copy link
Owner

zmxv commented Apr 19, 2016

@mrpatiwi This is not a high priority feature on my to-do list.

ohtangza pushed a commit to ohtangza/react-native-sound that referenced this issue Aug 8, 2017
…sory

Support playing through connected audio accessory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants