Пример #1
0
	void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
	{
		if (0 != strcmp(s_currentBackgroundStr.c_str(), pszFilePath))
		{
			stopBackgroundMusic(true);
		}
		else
		{
			if (s_playStatus == PAUSED)
				resumeBackgroundMusic();
			else
				rewindBackgroundMusic();
		}

		if (!s_isBackgroundInitialized)
			preloadBackgroundMusic(pszFilePath);

		if (bLoop)
		{
			// set it up to loop
			strm_dict_t *dictionary = strm_dict_new();
			s_repeatDictionary = strm_dict_set(dictionary, "repeat", "all");

    		if (mmr_input_parameters(s_mmrContext, s_repeatDictionary) != 0)
    		{
    			mmrerror(s_mmrContext, "input parameters (loop)");
    			return;
    		}
		}

		if (s_hasMMRError || !s_mmrContext)
			return;

		if (mmr_play(s_mmrContext) < 0)
		{
			mmrerror(s_mmrContext, "mmr_play");
			s_hasMMRError = true;
		}

		if (!s_hasMMRError)
			s_playStatus = PLAYING;
	}
Пример #2
0
int ZaMp3::playloop(const char * url)
{
	const char *mmrname = NULL;
	const char *ctxtname = "testplayer";
	const char *audioout = NULL;
	const char *inputtype = "autolist";
	//int     final_return_code = EXIT_FAILURE;
	mode_t mode = S_IRUSR | S_IXUSR;
	int audio_oid; // output ID
	strm_dict_t *aoparams = NULL; // output parameters

	mmr_connection_t *connection;
	mmr_context_t *ctxt;

	audioout = DEFAULT_AUDIO_OUT;

	strm_dict_t *aiparams = strm_dict_new();
	aiparams = strm_dict_set(aiparams, "repeat", "all");


	getcwd(cwd, PATH_MAX);
	rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, url);

	if ( ( connection = mmr_connect( mmrname ) ) == NULL ) {
		perror( "mmr_connect" );
	} else if ( ( ctxt = mmr_context_create( connection, ctxtname, 0, mode ) ) == NULL ) {
		perror( ctxtname );
	} 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 ( aiparams && mmr_input_parameters( ctxt, aiparams ) ) {  // NEW
    	mmrerror( ctxt, "input parameters (audio)" );  // NEW
    } else if ( mmr_play( ctxt ) < 0 ) {
		mmrerror( ctxt, "mmr_play" );
	}
	return 0;
}