Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

New Contributor
Posts: 4
Registered: ‎10-19-2011
My Device: 9380
My Carrier: T-Mobile

How to download sound file and play from local storage?

[ Edited ]

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();

    QString fileExt = url.path().split('.').last();
    fileName = QString("%1/app/native/sample%2.%3")

    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);


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.

Posts: 138
Registered: ‎05-11-2012
My Device: Developer
My Carrier: Developer

Re: How to download sound file and play from local storage?

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.



BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: How to download sound file and play from local storage?

    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.