06-19-2012 06:03 AM - edited 06-19-2012 06:04 AM
Hi, I'm trying to download an audio file and play it using the mmr on BB10.
When I call "mmr_attach_input" the file isn't readable, but I don't know what's wrong.
Here is the downloader code (running in a cascades app, connected to a QNetworkReply):
QByteArray bytes = reply->readAll();
reply->deleteLater();
QString fileExt = url.path().split('.').last();
fileName = QString("%1/app/native/sample%2.%3")
.arg(QDir::currentPath())
.arg(counter++)
.arg(fileExt);
FILE *sampleFile = fopen(fileName.toStdString().c_str(), "wb+");
if (sampleFile) {
int nBytes = fwrite(bytes.data(), bytes.size(), 1, sampleFile);
qDebug() << "written " << nBytes << " to file";
fchmod(fileno(sampleFile), 0755);
fclose(sampleFile);
}
And the "player":
mmr_context_t *context = mmr_context_create(mmr, generateContextName().c_str(), 0, S_IRUSR | S_IXUSR);
if (context) {
const char *fileName = getLocalFileName();
int result = mmr_output_attach(context, "audio:default", "audio");
if (result >= 0) { result = mmr_input_attach(context, fileName, "track"); }
if (result >= 0) { result = mmr_play(context); }
Tested also:
FILE *test = fopen(fileName, "rb");
And I couldn't open the file. The filename is right, and the file is actually saved (I can open it as a "file://" url in the web browser).
The error I get after mmr_input_attach is MMR_ERROR_MEDIA_UNAVAILABLE.
Additional information: if I call mmr_input_attach before mmr_output_attach, I get an MMR_ERROR_UNSUPPORTED_MEDIA_TYPE, but I suppose it's an expected behaviour.
06-19-2012 03:02 PM
Not sure if it is directly relevant because you are using a different player but have you checked out the cowbell sample app which makes use of sound files?
Certainly it sets up the path files and maybe a useful pattern to follow.
Graham
06-19-2012 07:56 PM
fileName = QString("%1/app/native/sample%2.%3")
Is this where you're trying to save the file? The app/ directory is a symlink into the read-only installation directory for your app. You can't write files there on the target.
Try saving to data/ instead, or tmp/, or get yourself access_shared permission and write files to shared/music.
Cheers,
Sean