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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

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.