"Mix_LoadMUS" for Android

As discussed previously (http://forums.libsdl.org/viewtopic.php?t=7692), IMG_Load can access files in /assets/ via RWops. I also hacked together a system for loading XML files and passing them to TinyXML. Now I’m working on music, but Mix_LoadMUS doesn’t seem to work the way IMG_Load does. I think I’ll need to load the files manually using RWops, as with XML - trouble is music is not like text: I’m not sure quite how to handle it. Any advice?

Thanks,

William

Not sure what you mean, here is the example from the SDL_mixer docs:

// load the MP3 file “music.mp3” to play as music
Mix_Music *music;
music=Mix_LoadMUS(“music.mp3”);
if(!music) {
printf(“Mix_LoadMUS(“music.mp3”): %s\n”, Mix_GetError());
// this might be a critical error…
}

If you’re having trouble loading a file, perhaps the coded is not built
into SDL_Mixer? I just had to jump through hoops to get OGG support under
Mingw (couldn’t get SMPEG to compile), so you might want to take a look at
the build logs to see exactly what support is in your version of SDL_mixer.

Cheers.On Tue, Nov 22, 2011 at 11:06 PM, wilbefast wrote:

**
As discussed previously http://forums.libsdl.org/viewtopic.php?t=7692,
IMG_Load can access files in **/assets/ via RWops. I also hacked together
a system for loading XML files and passing them to TinyXML. Now I’m working
on music, but Mix_LoadMUS doesn’t seem to work the way IMG_Load does. I
think I’ll need to load the files manually using RWops, as with XML -
trouble is music is not like text: I’m not sure quite how to handle it. Any
advice?

Thanks,

William


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

There is Mix_LoadMUS_RW(). I haven’t ever used it, so I’m not sure if it
automatically supports the variety of formats that Mix_LoadMUS() does.

Here’s an old GPwiki article for WAV using Mix_LoadWav_RW():
http://content.gpwiki.org/index.php/SDL_mixer:Tutorials:Playing_a_WAV_Sound_from_a_Custom_Resource_File_using_SDL_RWops

Jonny DOn Wed, Nov 23, 2011 at 7:16 PM, Jeremy Jurksztowicz <jurksztowicz at gmail.com wrote:

Not sure what you mean, here is the example from the SDL_mixer docs:

// load the MP3 file “music.mp3” to play as music
Mix_Music *music;
music=Mix_LoadMUS(“music.mp3”);
if(!music) {
printf(“Mix_LoadMUS(“music.mp3”): %s\n”, Mix_GetError());
// this might be a critical error…
}

If you’re having trouble loading a file, perhaps the coded is not built
into SDL_Mixer? I just had to jump through hoops to get OGG support under
Mingw (couldn’t get SMPEG to compile), so you might want to take a look at
the build logs to see exactly what support is in your version of SDL_mixer.

Cheers.

On Tue, Nov 22, 2011 at 11:06 PM, wilbefast wrote:

**
As discussed previously http://forums.libsdl.org/viewtopic.php?t=7692,
IMG_Load can access files in **/assets/ via RWops. I also hacked
together a system for loading XML files and passing them to TinyXML. Now
I’m working on music, but Mix_LoadMUS doesn’t seem to work the way IMG_Load
does. I think I’ll need to load the files manually using RWops, as with XML

  • trouble is music is not like text: I’m not sure quite how to handle it.
    Any advice?

Thanks,

William


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


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

Thanks for the ressource, I’ll have a look. FI, the code I’m running is:

Code:
ASSERT_MIX(Mix_OpenAudio(SOUND_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
MIX_DEFAULT_CHANNELS, SOUND_UNNAMED_PAR) != -1,
“Starting SDL Mixer”);

// Load and play music on loop (-1)
music = Mix_LoadMUS(ASSET("music.ogg"));
//ASSERT_MIX(music, "Loading music file");
Mix_PlayMusic(music, -1);

ASSERT_MIX logs Mix_GetError() (depending on platform this can end up being just a printf) and returns EXIT_FAILURE if there’s a problem. On Linux there’s no trouble, but Android doesn’t find the .ogg, so I’m guessing it’s not using RWops by default for Android

Just wanted to share that SDL_mixer works on Android. Actually initially i struggled for playing music on android phones.

Example Code:-

SoundManager::SoundManager()
{
if (Mix_Init(MIX_INIT_OGG) < 0)
{
#ifdef DEBUG
Logger::Instance()->Log(MODNAME, func,“Mix_Init(MIX_INIT_OGG) (%s)”, Mix_GetError());
#endif

}
else
{
    
	if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) < 0)
	{
            #ifdef DEBUG
	Logger::Instance()->Log(MODNAME, __func__,"Mix_OpenAudio (%s)", Mix_GetError());
	#endif	
	exit(2);
	}
	else
	{
	#ifdef DEBUG
	Logger::Instance()->Log(MODNAME, __func__,"Calling Mix_OpenAudio (22050, AUDIO_S16, 2, 4096)");
	#endif

	}

}

}

Mix_Music* pMusic = Mix_LoadMUS(fileName.c_str());

void SoundManager::playMusic(std::string id, int loop)
{
Mix_VolumeMusic(MIX_MAX_VOLUME/6);
Mix_PlayMusic(mMusic_[id], loop);
}

It’s pretty simple, the main catch is Mix_Init(MIX_INIT_OGG) for ogg file. For Wav you don’t require it.
Thanks to Gabriele for the right pointer.

Raghuvendra Kumar------------------------
Raghuvendra Kumar