07-13-2012 11:17 AM
hi,
i just try to add sounds in my Game , took example playAudio from Ndk samples.
created two simple methods .code are same as in sample but still getting Error can't Open source.
here is my code
MySoundPlayer.h
/*
* MySoundPLayer.h
*
* Created on: Jul 13, 2012
* Author: vivek
*/
#ifndef MYSOUNDPLAYER_H_
#define MYSOUNDPLAYER_H_
#include <bps/bps.h>
#include <bps/audiomixer.h>
#include <bps/dialog.h>
#include <bps/navigator.h>
#include <mm/renderer.h>
#include <screen/screen.h>
#include <stdio.h>
#include <unistd.h>
#include "types.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#if ! defined(DEFAULT_AUDIO_OUT)
#define DEFAULT_AUDIO_OUT "audio:default"
#endif
#define MSG_SIZE 1024
class MySoundPLayer {
public:
MySoundPLayer();
bool loadSound(const char * Url);
void playsound();
void mmrerror( mmr_context_t *ctxt , char *errorMsg);
float volume;
mmr_connection_t *connection;// = NULL;
mmr_context_t *ctxt;// = NULL;
char msg[MSG_SIZE];
virtual ~MySoundPLayer();
};
#endif /* MYSOUNDPLAYER_H_ */
and CPP
/*
* MySoundPLayer.cpp
*
* Created on: Jul 13, 2012
* Author: vivek
*/
#include "MySoundPLayer.h"
MySoundPLayer::MySoundPLayer() {
// TODO Auto-generated constructor stub
}
MySoundPLayer::~MySoundPLayer() {
// TODO Auto-generated destructor stub
}
bool MySoundPLayer::loadSound(const char * Url) {
const char *ctxt_name = "testplayerr";
const char *audio_out = "audio:default";
const char *input_type = "track";
char cwd[PATH_MAX];
char inputurl[PATH_MAX];
int audio_oid; //outputId
const char *audioout = NULL;
const char *mmrname = NULL;
getcwd(cwd, PATH_MAX);
int rc;
rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, Url);
if (rc > PATH_MAX - 1) {
printf("File name and path too long");
}
mode_t mode = S_IRUSR | S_IXUSR;
strm_dict_t *aoparams = NULL; // output parameters
audioout = DEFAULT_AUDIO_OUT;
const char *inputtype = "track";
if ((connection = mmr_connect(mmrname)) == NULL) {
snprintf(msg, MSG_SIZE, "mmr_connect: %s", strerror(errno));
return false;
} else if ((ctxt = mmr_context_create(connection, ctxt_name, 0, mode))
== NULL) {
snprintf(msg, MSG_SIZE, "%s: %s", ctxt_name, strerror(errno));
return false;
} else if (audioout
&& (audio_oid = mmr_output_attach(ctxt, audioout, "audio")) < 0) {
mmrerror(ctxt, msg);
return false;
} else if (aoparams && mmr_output_parameters(ctxt, audio_oid, aoparams)) {
mmrerror(ctxt, msg);
return false;
} else if (mmr_input_attach(ctxt, inputurl, inputtype) < 0) {
mmrerror(ctxt, msg);
return false;
} else if (mmr_play(ctxt) < 0) {
return false;
mmrerror(ctxt, msg);
}
printf("Success :%s", msg);
return true;
}
void MySoundPLayer::mmrerror(mmr_context_t *ctxt, char *errorMsg) // const char *errmsg )
{
const mmr_error_info_t *err = mmr_error_info(ctxt);
unsigned errcode = err->error_code;
//char errorMsg [1024];
switch (errcode) {
case MMR_ERROR_NONE:
sprintf(errorMsg, "No error", "%s");
break;
case MMR_ERROR_UNKNOWN:
sprintf(errorMsg, "unKnown error", "%s");
break;
case MMR_ERROR_INVALID_PARAMETER:
sprintf(errorMsg, "invalid parameters", "%s");
break;
case MMR_ERROR_INVALID_STATE:
sprintf(errorMsg,
"An attempt to play or seek while there's no input attached or to talk to the context after it's been destroyed",
"%s");
break;
case MMR_ERROR_UNSUPPORTED_VALUE:
sprintf(errorMsg,
"Input or output type not recognized by any plugin Speed out of range",
"%s");
break;
case MMR_ERROR_UNSUPPORTED_MEDIA_TYPE:
sprintf(errorMsg, "No plugin recognized data format", "%s");
break;
case MMR_ERROR_MEDIA_PROTECTED:
sprintf(errorMsg,
" The media format was recognized but file is DRM-protected and either uses an unsupported DRM scheme or the reason for failure is not one of the specific DRM errors listed below",
"%s");
break;
case MMR_ERROR_UNSUPPORTED_OPERATION:
sprintf(errorMsg,
"A seek or set speed call with media that doesn't support it Attach/detach output with a plugin that doesn't support it",
"%s");
break;
case MMR_ERROR_READ:
sprintf(errorMsg, " I/O error at source", "%s");
break;
case MMR_ERROR_WRITE:
sprintf(errorMsg, " I/O error at sink", "%s");
break;
case MMR_ERROR_MEDIA_UNAVAILABLE:
sprintf(errorMsg, "Can't open source", "%s");
break;
case MMR_ERROR_MEDIA_CORRUPTED:
sprintf(errorMsg, "Media currepted", "%s");
break;
case MMR_ERROR_OUTPUT_UNAVAILABLE:
sprintf(errorMsg,
"Can't open sink (possibly because no plugin recognizes it)",
"%s");
break;
case MMR_ERROR_NO_MEMORY:
case MMR_ERROR_RESOURCE_UNAVAILABLE:
sprintf(errorMsg, "No Memory or res unAvaiable", "%s");
break;
case MMR_ERROR_MEDIA_DRM_NO_RIGHTS:
sprintf(errorMsg, "No rights to play the file", "%s");
break;
case MMR_ERROR_MEDIA_DRM_OUTPUT_PROTECTION:
sprintf(errorMsg, " DRM output protection mismatch", "%s");
break;
case MMR_ERROR_DRM_CORRUPTED_DATA_STORE:
sprintf(errorMsg, " DRM data store is corrupted", "%s");
break;
}
}
with this i have Added my wav and Mp3 files in Assets in bar descriptor, check the playsound checkbox
and in Make file added
# Basic libraries required by most native applications LIBS+=bps screen mmrndclient strm
but still getting Error "can't open source. from My error decoding switch case it goes in "
MMR_ERROR_MEDIA_UNAVAILABLE
what step is wrong , or i forget to add something.
can someOne post a wrapper class to play sound on playbook.
or can i use Open AL to play sound. if OpenAl can b used than plz plz post a smple or link for that
source attached also.
Solved! Go to Solution.
07-13-2012 10:08 PM
You probably just don't have the path to your file correct. You only posted part of your code. I don't see where loadSound() is being called from, nor the arguments you are passing to it. Have you tried dumping inputurl to see what path you have assembled?
07-14-2012 07:13 AM
the code which calling LoadSound() is as
mplayer = new MySoundPLayer();
if( mplayer->loadSound("app/native/farewell.mp3"))
printf("Sound Loaded\n");
else
{
printf("Else part\n");
}
also in debugging i got inpuUrl value is ""file:///accounts/1000/appdata/com.game.GemKing.t
07-15-2012 10:54 AM
You are going to kick yourself when you see the solution, change:
rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, Url)to
rc = snprintf(inputurl, PATH_MAX, "file://%s/%s", cwd, Url)or change
if( mplayer->loadSound("app/native/farewell.mp3"))toif( mplayer->loadSound("/app/native/farewell.mp3"))I just had the same problem.