==============================================================
The following are used in CASCADES/QT projects.
==============================================================
cascadesi/q Project, library mmrndclient and STRM cannot be added to the properties of project.
Cause: In the Cascades GUI application, use QT and make to compile the
Workaround:
Modify the QT project file (such as the Xxx.pro file) under the root directory
CONFIG + = qt warn_on debug_and_release cascades
Add later
LIBS + =-LMMRNDCLIENT-LSTRM
Reference: Linking an Object Library to an application
Other:
In the CASCADES/QT project, import the Playaudio example program that comes with the BB10 IDE.
The Mmr_error_none in the header file in the example program cannot find the relevant definition at compile time, or it is a syntax error.
Personal apprentice not fine, had to temporarily have to head file inside the Err are temporarily commented out.
static const char *errlist[] = {
ERR (Mmr_error_none),
...
==============================================================
Here is the code, according to the BB10 IDE in the self-contained Playaudio example C program modified to C + + QT program.
#ifndef _soundmanager_h #define _soundmanager_h #include <errno.h> #include <stdio.h> #include <stdlib.h > #include <string.h> #include <unistd.h> #include <sys/stat.h> #include <bps/bps.h> # Include <bps/audiomixer.h> #include <bps/dialog.h> #include <bps/navigator.h> #include <mm/ renderer.h> #include <QtCore/qstring.h> #include <qhash.h>/* buffer to store messages that we'll di
Splay in the dialog */#define msg_size, static char msg[msg_size]; #if! Defined (default_audio_out) #define Default_audio_out "Audio:default" #endif #define Color_purple 0xffff00ff #define W
Av_relative_path "/app/native/assets/farewell.mp3" #define ERR (code) [Code] = #code static const char *errlist[] = {
}; /* Jiang TODO ERR (mm_error_code. Mmr_error_none), err (Mmr_error_unknown), err (Mmr_error_invalid_parameter), err (mmr_error_invalid_state), Err (MM R_error_unsupported_value), ERR (mmr_error_Unsupported_media_type), err (mmr_error_media_protected), err (mmr_error_unsupported_operation), Err (MMR_ERROR_READ ), err (Mmr_error_write), err (mmr_error_media_unavailable), err (mmr_error_media_corrupted), Err (MMR_ERROR_OUTPU t_unavailable), err (mmr_error_no_memory), err (mmr_error_resource_unavailable), */#undef ERR #define NERRS (size
Of (Errlist)/sizeof (ERRLIST[0)) class Soundmanager:public Qobject {q_object public:soundmanager ();
~soundmanager ();
Public slots:void Playmp3 ();
};
#endif//_soundmanager_h
#include "soundmanager.h" void Show_dialog_message (char* msg) {} static void Mmrerror (mmr_context_t *ctxt, const char
*ERRMSG) {Const mmr_error_info_t *err = Mmr_error_info (ctxt);
unsigned errcode = err->error_code;
const char *name; if (errcode >= Nerrs | |
(name = errlist[Errcode]) = = NULL) {name = "Bad error code";
} snprintf (msg, msg_size, "%s:error%d (%s) \ n", ErrMsg, Errcode, name);
Show_dialog_message (msg);
} void Soundmanager::p Laymp3 () {const char *mmrname = NULL;
const char *ctxtname = "Testplayer";
const char *audioout = NULL;
const char *inputtype = "track";
Char Cwd[path_max];
Char Inputurl[path_max];
float volume;
int RC;
int final_return_code = exit_failure;
int exit_application = 0;
mmr_connection_t *connection = NULL;
mmr_context_t *ctxt = NULL; /* * Before we can listen for events from the BlackBerry (R) OS platform * Services, we need to InitiaLize the BPS Infrastructure */bps_initialize (); /* * Once the BPS infrastructure have been initialized we can register for * events from the various BlackBerry (R ) OS platform Services.
The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so we can track when * The system is terminating the application (NAVI Gator_exit event).
This allows * us to clean up application resources.
*/navigator_request_events (0);
Dialog_request_events (0);
/* * Create and display the dialog.
*///jiang//create_dialog ();
GETCWD (CWD, Path_max);
rc = snprintf (Inputurl, Path_max, "file://%s%s", CWD, Wav_relative_path);
if (rc > Path_max-1) {show_dialog_message ("File name and PATH too long"); Jiang//return 1;
Fail return; } mode_t mode = S_IRUSR |
S_IXUSR; int audio_oid; Output ID strm_dict_t *aoparams = NULL;
Output parameters audioout = default_audio_out; if ((connection = Mmr_connect (mmrname)) = = NULL) {snprintf (msg, Msg_size, "Mmr_connect:%s", Strerror (errno
));
Show_dialog_message (msg); } else if ((Ctxt = Mmr_context_create (connection, ctxtname, 0, mode)) = = = NULL) {snprintf (msg, msg_size, '%s ')
:%s ", Ctxtname, Strerror (errno));
Show_dialog_message (msg); } else if (audioout && (audio_oid = Mmr_output_attach (Ctxt, Audioout, "audio")) < 0) {Mmrerror (
Ctxt, audioout); } else if (Aoparams && mmr_output_parameters (Ctxt, Audio_oid, Aoparams)) {Mmrerror (ctxt, "output par
Ameters (audio) ");
} else if (Mmr_input_attach (Ctxt, Inputurl, InputType) < 0) {Mmrerror (ctxt, Inputurl);
} else if (Mmr_play (Ctxt) < 0) {Mmrerror (Ctxt, "Mmr_play"); } else {//3 minutes and 5 seconds is the Total length of the sample song.
rc = Audiomixer_get_output_level (Audiomixer_output_speaker, &volume); if (rc = = bps_success) {snprintf (msg, msg_size, successfully queried the output level.\ncurrent volume is%f
\ n ", volume);
Show_dialog_message (msg);
} else {show_dialog_message ("Failed to query the output level.\n");
}//play for the seconds at normal volume sleep (30); Decrease the volume and play for seconds Audiomixer_set_output_level (Audiomixer_output_speaker, volume/2.0)
;
if (rc = = bps_success) {show_dialog_message ("successfully decreased the volume by half.\n");
} else {show_dialog_message ("Failed to decrease the volume.\n");
} sleep (30); Set the volume to original level and play for seconds Audiomixer_set_output_level (Audiomixer_output_speaker,
volume);
if (rc = = bps_success) { Show_dialog_message ("Successfully set the volume back to original level.\n");
} else {show_dialog_message ("Failed to set the volume.\n");
} sleep (30);
Mute for 5 Seconds Audiomixer_set_output_mute (Audiomixer_output_speaker, true);
if (rc = = bps_success) {show_dialog_message ("successfully muted.\n");
} else {show_dialog_message ("Failed to mute.\n");
} sleep (5);
Toggle the mute setting and play until the end Audiomixer_toggle_output_mute (Audiomixer_output_speaker);
if (rc = = bps_success) {show_dialog_message ("successfully toggled the mute setting.\n");
} else {show_dialog_message ("Failed to toggle the mute setting.\n");
} Final_return_code = exit_success;
}/* * Process Navigator events until we receive a Navigator_exit event. */while (!exit_application) {/* * Using a negative timeout ( -1) in the "Call" to Bps_get_event (...)
* Ensures that we don ' t busy wait by blocking until an event is * available.
*/bps_event_t *event = NULL;
Bps_get_event (&event,-1); if (event) {/* * * If it is a Navigator_exit event then set the Exit_application * FL AG so the application would stop processing events, clean up * and exit */if (Bps_ev Ent_get_domain (Event) = = Navigator_get_domain ()) {if (Navigator_exit = = Bps_event_get_code (event) &&A mp (Final_return_code = = exit_success)) {mmr_stop (ctxt); Not really necessary – mmr_input_detach () would take care of this mmr_input_detach (Ctxt); Not really necessary – Mmr_context_destroy () would take care of this mmr_context_destroy (Ctxt); Not really necessary--MMR_disconnect () would take care of this mmr_disconnect (connection);
Not really necessary – exiting would take care of this exit_application = 1;
}}}}/* * Clean up the BPS infrastructure and exit */Bps_shutdown ();
Jiang//return Final_return_code;
Return
} Soundmanager::soundmanager () {} soundmanager::~soundmanager () {}