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
Posts: 28
Registered: ‎11-21-2012
My Device: Playbook
My Carrier: Telcel

Sound at start... after that no sound

Hello,

 

I am using this function to play a sound each time the user touch a button , when the aplication starts the function is called once and I can hear the sound effect. After that I can not hear the correct sound but a short noise.

 

If the function is not called at the start, I can hear the sound only the first time the button is touched, after that, nothing but the noise.

 

I am new to programing and I can not find a solution to this.

 

Please help!!!

 

void soundClick (int soundNum) {
	if (musicON) {
		bps_initialize();
		const char *ctxtname = "someSound";
		const char *audioout = NULL;
		const char *inputtype = "track";
		char cwd[PATH_MAX];
		char inputurl[PATH_MAX];
		char audioFile[PATH_MAX];
		float volume;
		int rc, au;
		mmr_connection_t *connection = NULL;
		mmr_context_t *ctxt = NULL;

		switch (soundNum){
			case 1:
				sprintf(audioFile,"/app/native/audio1.mp3");
			break;
			case 2:
				sprintf(audioFile,"/app/native/audio2.mp3");
			break;
			case 3:
				sprintf(audioFile,"/app/native/audio3.mp3");
			break;
			case 4:
				sprintf(audioFile,"/app/native/audio4.mp3");
			break;
			case 5:
				sprintf(audioFile,"/app/native/audio5.mp3");
			break;
			case 6:
				sprintf(audioFile,"/app/native/audio6.mp3");
			break;
			case 7:
				sprintf(audioFile,"/app/native/audio7.mp3");
			break;
		}

		getcwd(cwd, PATH_MAX);
		rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, audioFile);
		mode_t mode = S_IRUSR | S_IXUSR;
		int audio_oid; // output ID
		strm_dict_t *aoparams = NULL; // output parameters
		volume =  100.0;
		audioout = "audio:default";

		if ( ( connection = mmr_connect( NULL ) ) == NULL ) {

		} else if ( ( ctxt = mmr_context_create( connection, ctxtname, 0, mode ) ) == NULL ) {

		} else if ( audioout && ( audio_oid = mmr_output_attach( ctxt, audioout, "audio" ) ) < 0 ) {

		} else if ( aoparams && mmr_output_parameters( ctxt, audio_oid, aoparams ) ) {

		} else if ( mmr_input_attach( ctxt, inputurl, inputtype ) < 0 ) {

		} else if ( mmr_play( ctxt ) < 0 ) {

		}

		rc = audiomixer_get_output_level(AUDIOMIXER_OUTPUT_SPEAKER, &volume);

		mmr_disconnect(connection);
	}
}

 

Contributor
Posts: 15
Registered: ‎03-03-2012
My Device: Playbook
My Carrier: Fido

Re: Sound at start... after that no sound

I find the playing of sounds very confusing too. Would love to see a simple routine; the SDK example is incredibly long.

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Sound at start... after that no sound

What is this

		if ( ( connection = mmr_connect( NULL ) ) == NULL ) {

		} else if ( ( ctxt = mmr_context_create( connection, ctxtname, 0, mode ) ) == NULL ) {

		} else if ( audioout && ( audio_oid = mmr_output_attach( ctxt, audioout, "audio" ) ) < 0 ) {

		} else if ( aoparams && mmr_output_parameters( ctxt, audio_oid, aoparams ) ) {

		} else if ( mmr_input_attach( ctxt, inputurl, inputtype ) < 0 ) {

		} else if ( mmr_play( ctxt ) < 0 ) {

		}

 

supposed to mean? what is the logic here?

Contributor
Posts: 28
Registered: ‎11-21-2012
My Device: Playbook
My Carrier: Telcel

Re: Sound at start... after that no sound

Well.... to manage errors... not finished yet... but that is not the problem.

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Sound at start... after that no sound

Good to know that you are aware where the problem *is* ;-)

To me the first obvious strange thing is you are calling mmr_context_create() with every function call but never call mmr_context_destroy()..

Contributor
Posts: 28
Registered: ‎11-21-2012
My Device: Playbook
My Carrier: Telcel

Re: Sound at start... after that no sound

Yes...

 

Added:

 

mmr_context_destroy(ctxt);
mmr_disconnect(connection);

 No luck...

 

Can hear it the first time only.

 

Very frustating.

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: Sound at start... after that no sound

[ Edited ]

any reason you're reinitializing bps on every call?

also, if you're planning on talking to mmrenderer for a long period of time, why not leave the connection up?

Contributor
Posts: 28
Registered: ‎11-21-2012
My Device: Playbook
My Carrier: Telcel

Re: Sound at start... after that no sound

Do you mean open the connection at start (inside main) and just call the function to assign the sound file?
Contributor
Posts: 28
Registered: ‎11-21-2012
My Device: Playbook
My Carrier: Telcel

Re: Sound at start... after that no sound

Do you mean open the connection at start (inside main) and just call the function to assign the sound file?