static void stopBackground(bool bReleaseData)
    {
    	s_playStatus = STOPPED;

		if (s_mmrContext)
			mmr_stop(s_mmrContext);

		if (bReleaseData)
		{
			if (s_mmrContext)
			{
				mmr_input_detach(s_mmrContext);
				mmr_context_destroy(s_mmrContext);
			}

			if (s_mmrConnection)
				mmr_disconnect(s_mmrConnection);

			if (s_repeatDictionary)
				strm_dict_destroy(s_repeatDictionary);

			if (s_volumeDictionary)
				strm_dict_destroy(s_volumeDictionary);

			s_mmrContext = 0;
			s_mmrConnection = 0;
			s_repeatDictionary = 0;
			s_volumeDictionary = 0;
			s_hasMMRError = false;
			s_currentBackgroundStr = "";
			s_isBackgroundInitialized = false;
		}
    }
void MmRendererMediaPlayerControl::detach()
{
    if (m_context) {
        if (m_inputAttached) {
            mmr_input_detach(m_context);
            m_inputAttached = false;
        }
        if (m_videoRendererControl)
            m_videoRendererControl->detachDisplay();
        if (m_videoWindowControl)
            m_videoWindowControl->detachDisplay();
        if (m_audioId != -1 && m_context) {
            mmr_output_detach(m_context, m_audioId);
            m_audioId = -1;
        }
    }

    m_loadingTimer.stop();
}
Example #3
0
void BbMediaPlayerControl::detach()
{
    if (m_context) {
        if (m_inputAttached) {
            mmr_input_detach(m_context);
            m_inputAttached = false;
        }
        if (m_videoControl)
            m_videoControl->detachDisplay();
        if (m_audioId != -1 && m_context) {
            mmr_output_detach(m_context, m_audioId);
            m_audioId = -1;
        }
    }

    if (!m_tempMediaFileName.isEmpty()) {
        QFile::remove(m_tempMediaFileName);
        m_tempMediaFileName.clear();
    }
    m_loadingTimer.stop();
}
Example #4
0
int main( int argc, char **argv ) {
    const char *mmrname = NULL;
    const char *ctxtname = "testplayer";
    const char *audioout = NULL;
    const char *inputtype = "track";
    char cwd[PATH_MAX];
    char inputurl[PATH_MAX];
    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) 10 OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    if (setup_screen() != EXIT_SUCCESS) {
        printf("Unable to set up the screen. Exiting.");
        return 0;
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry(R) 10 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 (NAVIGATOR_EXIT event). 
     * This allows us to clean up application resources.
     */
    navigator_request_events(0);
    dialog_request_events(0);

    /*
     * Create and display the dialog.
     */
    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");
          goto fail;
    }

    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 parameters (audio)" );
    } else if ( mmr_input_attach( ctxt, inputurl, inputtype ) < 0 ) {
        mmrerror( ctxt, inputurl );
    } else if ( mmr_play( ctxt ) < 0 ) {
        mmrerror( ctxt, "mmr_play" );
    } else if (BPS_SUCCESS != bps_add_sigevent_handler( &mmr_sigevent, mmr_sigevent_handler, ctxt ) ) { 
        snprintf( msg, MSG_SIZE, "bps_add_sigevent_handler() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else if ( drain_and_arm_mmr_events ( ctxt ) ) {
        snprintf( msg, MSG_SIZE, "drain_and_arm_mmr_events() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else {
        show_dialog_message( "Playing Audio\n" );
        final_return_code = EXIT_SUCCESS;
    }

fail:
    /*
     * 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
             * flag so the application will stop processing events, clean up
             * and exit
             */
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                if (NAVIGATOR_EXIT == bps_event_get_code(event)) {
                    if (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;
                }
            } else if (bps_event_get_domain(event) == dialog_get_domain()) {
                if (DIALOG_RESPONSE == bps_event_get_code(event)) {
                    handle_dialog_response_events(event);
                }
            }
        }
    }

    /*
     * Destroy the dialog, if it exists and cleanup screen resources.
     */
    destroy_dialog();
    cleanup_screen();
    /*
     * Clean up the BPS infrastructure and exit
     */
    bps_shutdown();

    return final_return_code;

}