Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
eggshapedfred
Posts: 16
Registered: ‎01-08-2013
My Device: Developer
Accepted Solution

Performance problems with mmr_play() and mmr_stop()

Hello,

 

I am currently working on a game for the BB10 platform and am in the process of implementing the audio. I am using the multimedia renderer to play a background music track in the game, which works fine. My problem comes when trying to switch to a different music track mid-game - this produces a short (but noticeable) stall.

 

A bit more information - my approach is currently single-threaded (I realise that one potential solution is to implement the audio on a separate thread), and when I trigger a new track I am simply calling mmr_input_attach() and then mmr_play(), which are then so expensive that they stall the game.

 

As I say, I know one solution would be to move the audio to another thread, however I was wondering if anyone knew of another solution at all? I've tried playing the tracks from a playlist and using mmr_seek to move between them but I still get the same stall. Unfortunately I haven't been able to find a great deal of information about the internal workings of mmr_play() or mmr_input_attach() or find many forum postings about them so it has been hard to work out what my options might be.

 

Thanks in advance for any help!

Contributor
eggshapedfred
Posts: 16
Registered: ‎01-08-2013
My Device: Developer

Re: Performance problems with mmr_play() and mmr_stop()

For what it's worth I managed to get a threaded solution working quite easily, roughly as follows:

 

void* playMusicOnThread(void* args)
{
	if(mmr_input_attach(musicContext, musicURL(), "autolist")==0)
	{
		// Successful attach, play file
		mmr_play(musicContext());
	}
	else
	{
		// Handle error
	}
	return 0;
}

void MyClass::playMusic(void)
{
    pthread_t pt;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    pthread_create(&pt, &attr, &playMusicOnThread, NULL);
    return;
}

 I'd still be interested if anyone knows of a way to make it work single-threaded, but this solution is enough for my purposes anyway.