Proper way to use assetBundlePatterns

#1

What would be the proper way to bundle fonts, images and sounds?
I’m developing an app for Android.

I have this in app.json

"assetBundlePatterns": [
  "assets/img/*.png",
  "assets/snd/*.mp3",
  "assets/fonts/*.ttf"
]

I know I need to use Font.loadAsync for fonts. Do I need to use Asset.loadAsync for sounds or do I just request them as usual require for the bundle versions to work? And do I need to bundle all the splash and icon images or does Expo bundle them by default?

Currently when I launch the app I see that sounds are not bundled as I get error messages first couple of times trying to play them. And the same thing is happening if the app was in the background for a long period of time. When I launch it from the multitask screen it doesn’t have cached versions of sounds and won’t load them again.

0 Likes

#2

I think some of these questions are answered in our guide for asset bundling. You should be able to load sounds fine using require if it works for you online. We bundle splash screens and icons by default, you don’t need to do anything special there.

Do you have a reproduction of the sound caching issue you’re having? It would be really useful if you could post a small example to snack and/or github to help us find the root cause of that issue.

0 Likes

#3

Thanks @dikaiosune for a quick reply.

The guide shows just the very basics. It doesn’t have any use cases, it just shows the syntax of the assetBundlePatterns param, and it’s not 100% clear what files can be bundled and how to use them in the app. Whether to prefetch them with Asset.loadAsync or just request as an external resource via require.

I’ll have some tests today having sounds bundled and requiring them in the app and will get back with an update.

0 Likes

#4

@dikaiosune

Did some testing. Tried to request sounds with require and by using first Asset.loadAsync and then Asset.fromModule. In both cases the behaviour is unpredictable. This time it loads and plays sounds, next time sounds are not loaded or undefined. And it doesn’t matter whether I am connected to the internet or not. Tried different paths, relative with ./ in the beginning and with the package name.

Here’s the snack: https://snack.expo.io/@rckt/sound-test

Oh, and forgot to mention. In emulator it fails to load sounds most of the time.

0 Likes

#5

Had some more tests. When the device is offline, sounds can’t be loaded, so I guess for some reason the app is not getting them from the bundled package, but I can see them in the apk.

0 Likes

#6

So, any advice on how to solve this?
Again. The issue is that sounds are bundled and the apk contains them. But for some reason the app tries to download them from the cdn.

0 Likes

#7

I added Sentry and in the error details noticed this: "bundledAssets":[].
Is it normal that for the standalone apk build?

Running in the emulator I have this in the manifest
"assetBundlePatterns": ["assets/snd/*.mp3", "assets/fonts/*.ttf"]

0 Likes

closed #8

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

0 Likes