Mix_LoadWAV() not working on android

Greetings!

I’m experimenting with developing android apps in SDL 2.0, and everything seems to be fine, except that I can’t make any sound effects, or music.

I tried using Mix_Chunk *chunk and Mix_Music *music as well, using the Mix_LoadWAV() or the Mix_LoadMUS() function, but all it gives back is a NULL pointer, and I can’t figure out why.

I tried putting the wav file into the assets directory, and in the jni/src directory but none of them worked, where do I have to place it?

Here’s my code:

Code:
int main(int argc, char *argv[])
{
int w,h, num=0;
SDL_Event event;
Mix_Chunk *chunkey=NULL;

SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer);
SDL_GetWindowSize(window,&w,&h);
SDL_Init(SDL_INIT_AUDIO);
Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );

chunkey=Mix_LoadWAV("Test.wav"); //it is in the assets directory right now, but didn't work even if it was in the root dir


if (chunkey==NULL)
	exit(0);


while(num<3)
{
	while (SDL_PollEvent(&event))
	{
		if (event.type==SDL_FINGERDOWN)
			{
			Mix_PlayChannel(-1, chunkey, 5); //tried with various arguments
			num++;
			}

	}

}
exit(0);
return 0;

}

Thank you in advance!

Hi,

files you package with your app are not accessible as “ordinary” files from
the app, because the app’s .zip file (just renamed to .apk) is not unpacked
when installed (except for native libraries, but that’s a different story).

You need to use the proper methods for access. In case of “assets”, you can
use “Android_JNI_File*” functions for access.

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: sweetcare <fulop.dani96 at gmail.com>
Komu: sdl at lists.libsdl.org
Datum: 6. 3. 2015 19:21:36
P?edm?t: [SDL] Mix_LoadWAV() not working on android…

"

Greetings!

I’m experimenting with developing android apps in SDL 2.0, and everything
seems to be fine, except that I can’t make any sound effects, or music.

I tried using Mix_Chunk *chunk and Mix_Music *music as well, using the Mix_
LoadWAV() or the Mix_LoadMUS() function, but all it gives back is a NULL
pointer, and I can’t figure out why.

I tried putting the wav file into the assets directory, and in the jni/src
directory but none of them worked, where do I have to place it?

Here’s my code:

                              Code:	 

int main(int argc, char *argv[])
{
? ?int w,h, num=0;
? ?SDL_Event event;
? ?Mix_Chunk *chunkey=NULL;

? ?SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer);
? ?SDL_GetWindowSize(window,&w,&h);
? ?SDL_Init(SDL_INIT_AUDIO);
? ?Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );

? ?chunkey=Mix_LoadWAV(“Test.wav”); //it is in the assets directory right
now, but didn’t work even if it was in the root dir

? ?if (chunkey==NULL)
? ?? ?exit(0);

? ?while(num<3)
? ?{
? ?? ?while (SDL_PollEvent(&event))
? ?? ?{
? ?? ?? ?if (event.type==SDL_FINGERDOWN)
? ?? ?? ?? ?{
? ?? ?? ?? ?Mix_PlayChannel(-1, chunkey, 5); //tried with various arguments
? ?? ?? ?? ?num++;
? ?? ?? ?? ?}

? ?? ?}

? ?}
? ?exit(0);
? ?return 0;
}

Thank you in advance!_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

Thank your for your response. I’ll try to make it work, and will give a feedback:)

hardcoredaniel wrote:> Hi,

files you package with your app are not accessible as “ordinary” files from the app, because the app’s .zip file (just renamed to .apk) is not unpacked when installed (except for native libraries, but that’s a different story).

You need to use the proper methods for access. In case of “assets”, you can use “Android_JNI_File*” functions for access.

Regards,

Daniel


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The SDL satellite libs all use SDL_RWFromFile() for their basic file
loading. SDL 2 on Android makes this look up the file in the assets
directory first. So you should put the files in assets/ and just call
Mix_LoadWAV() normally (do not add “assets/” to any filename strings). If
it’s not working, then something else is up. Are you using a recent
version of SDL_mixer and not an old SDL 1.2 one?

Jonny DOn Saturday, March 7, 2015, sweetcare <fulop.dani96 at gmail.com> wrote:

Thank your for your response. I’ll try to make it work, and will give a
feedback:)

hardcoredaniel wrote:

Hi,

files you package with your app are not accessible as “ordinary” files
from the app, because the app’s .zip file (just renamed to .apk) is not
unpacked when installed (except for native libraries, but that’s a
different story).

You need to use the proper methods for access. In case of “assets”, you
can use “Android_JNI_File*” functions for access.

Regards,

Daniel


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hey. yes, I’m sure that I am using the correct version of the SDL_Mixer. Really, I can’t just figure out why wouldn’t it load the file… Any tips? Or any way I can make it work, maybe without sdl_mixer?

Jonny D wrote:> The SDL satellite libs all use SDL_RWFromFile() for their basic file loading.?? SDL 2 on Android makes this look up the file in the assets directory first.?? So you should put the files in assets/ and just call Mix_LoadWAV() normally (do not add “assets/” to any filename strings).?? If it’s not working, then something else is up.?? Are you using a recent version of SDL_mixer and not an old SDL 1.2 one?

Jonny D

You could try ALmixer. Many (painful) years were spent making ALmixer
work well (as possible) on Android.

Thanks,
EricOn 3/7/15, sweetcare <fulop.dani96 at gmail.com> wrote:

Hey. yes, I’m sure that I am using the correct version of the SDL_Mixer.
Really, I can’t just figure out why wouldn’t it load the file… Any tips?
Or any way I can make it work, maybe without sdl_mixer?


Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

I reinstalled the whole project, and now it’s working. Thank you anyway:)