How to access Android apk resources from AIR native extension?

305 views Asked by At

My native extension can't access resources that are inside apk.

Lets say, I wanna play a sound natively "my_sound.wav":

MediaPlayer mediaPlayer = MediaPlayer.create(freContext.getActivity(), freContext.getResourceId("raw.my_sound"));
mediaPlayer.start();

I create native extension (.ane file) like this:

adt -package -target ane playSound.ane extension.xml -swc playSoundAPI.swc -platform Android-ARM -C Android-ARM .

...with a sound file being inside the folder Android-ARM/res/raw/my_sound.wav so it is packed into the .ane file.

And later it is packed into the Android application (.apk file).

When I run this aapt command:

aapt list -v myApp.apk

.. I can see my sound file among the other resources, so I know it's inside:

6342  Deflate    5414  15%    263300  06-11-15 19:21  b998fae3 res/raw/my_sound.wav

Also if I open myApp.apk with a file archiver, I can see the res/raw/my_sound.wav inside.

Problem is, when I run the app on my phone, it produces an error:

android.content.res.Resources$NotFoundException: File res/raw/my_sound.wav from drawable resource ID #0x7f040005

What am I doing wrong?

UPDATE:

It looks like the problem occurs only with a sound files. For example, I can read a text from res/raw/some.txt and display this text on the screen. I tried same thing with a .wav file and I managed to access it and print out it's contents as a text (lots of gibberish) using InputStream and ByteArrayOutputStream. So, the sound file IS THERE but why can't i play it? Still gives me Resources$NotFoundException. But it's there for sure. I tried it with mp3, wav and different wav sampling rates, no change. I also have tried to play it as a native android application and it works perfectly, but when I try to do the same in android native extension, it is not working ...

0

There are 0 answers