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.

Is there a way to automate audio file include?

See original GitHub issue

Iā€™ve managed to get audio playing, but Iā€™m striving to make includes to the project automated.

Iā€™ve got this in my package.json to automate font includes from my src/assets/fonts folder

        "rnpm": {
		"assets": [
			"src/assets/fonts"
		]
	}

This puts files into Resources folder. Unfortunately it doesnā€™t seem like Sound can play from there. Could you suggest something (if possible) to have similar flow for src/assets/audio folder. If not, is it possible to include audio file from src folder as opposed to native?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Venryxcommented, Feb 28, 2017

@benvium

At the moment android can only play audio files from the res/raw folder. Iā€™m planning to add android assets support at some time as itā€™d be useful for us, but donā€™t have a timeline on this.

Android asset support can be accomplished by adding this to the start of the RNSoundModule.createMediaPlayer function:

if (fileName.startsWith("assets/")) {
	try {
		MediaPlayer player = new MediaPlayer();
		AssetFileDescriptor assetFileInfo = context.getAssets().openFd(fileName.substring("assets/".length()));
		player.setDataSource(assetFileInfo.getFileDescriptor(), assetFileInfo.getStartOffset(), assetFileInfo.getLength());
		player.prepare();
		return player;
	} catch (IOException e) {
		e.printStackTrace();
	}
}

And then from JavaScript, doing:

var whoosh = new Sound('whoosh.mp3', 'assets', (error)=>{});

Of course, this isnā€™t that much different from using the android/app/src/main/res/raw directory, as mentioned in the Readme. But I like this slightly better, because the assets folder preserves the original filename and folder structure. This is nice for when you want the user to be able to reference the files manually. (as is true in my app)

0reactions
0xAsimetriqcommented, Feb 23, 2017

Does the trick now, looking forward for Android support, I think this is really neat feature šŸ‘

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make a volume automation clip in FL Studio ... - YouTube
How to make a volume automation clip in fl studio 20 for audio and midi, Yes annoyingly due to how FL studio works...
Read more >
What Is Mix Automation? Everything You've Been Too Afraid ...
The most popular use of automation in mixing is to adjust the volume of a track. For example, it allows you to bring...
Read more >
Automation in the Logic Pro Audio Track Editor - Apple Support
Show automation in the Audio Track Editor. In the Logic Pro Audio Track Editor, click the Show/Hide Automation button in the Audio Track...
Read more >
Automate mixes with envelopes in Adobe Audition CC
Envelopes are nondestructive, so they don't change audio files in any way. If you open a file in the Waveform Editor, for example,Ā ......
Read more >
Automation Clips - Playlist - FL Studio
There are several ways to create an Automation Clip: ... VST/AU plugin controls - There are two methods; Prefer 'Last tweaked' unless that...
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