1. GSM-S's Avatar
    I have tried googling it, and searching for the cowbell sample app. However, I could not find it. I tried to use the QT media player, but I get an error.
    Code:
    player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("asset:///music/coolsong.mp3"));
    player->play();
    How do I play a simple sound from C++ on BB10?

    ~.Posted using CB10 on my Z10 running 10.3.1.~
    Last edited by GSM-S; 04-27-15 at 03:17 AM.
    04-27-15 02:31 AM
  2. baarn's Avatar
    04-27-15 05:19 AM
  3. GSM-S's Avatar
    Thanks for the links. Unfortunately, I have encountered a syntax error, and I have no idea where it is and how to fix it.
    Code:
    #include <QObject>
    #include <bb/multimedia/MediaPlayer>
    #include <bb/multimedia/SystemSound>
    
    class Sound : public QObject {
    public:
        bb::multimedia::MediaPlayer mp(this); // Error appears here
        mp.setSourceUrl(QUrl("asset:///media.mp3")); // Error appears here
    
        void onPlay() {
            mp.play(); // automatically prepares
        }
    
        void onStop() {
            mp.stop();
        }
    };
    04-27-15 05:32 PM
  4. RodgerLeblanc's Avatar
    Thanks for the links. Unfortunately, I have encountered a syntax error, and I have no idea where it is and how to fix it.
    Code:
    #include <QObject>
    #include <bb/multimedia/MediaPlayer>
    #include <bb/multimedia/SystemSound>
    
    class Sound : public QObject {
    public:
        bb::multimedia::MediaPlayer mp(this); // Error appears here
        mp.setSourceUrl(QUrl("asset:///media.mp3")); // Error appears here
    
        void onPlay() {
            mp.play(); // automatically prepares
        }
    
        void onStop() {
            mp.stop();
        }
    };
    You can't use "asset://" in C++, you'll have to build the path yourself like this :
    QDir::homePath() + "app/native/assets/media.mp3"

    Posted via CB10
    04-27-15 05:54 PM
  5. baarn's Avatar
    You need to create a constructor for your Sound class, initialise mp in the initialisation list, and setSourceUrl in the body.

    Really I would advise you to first get some of the demo apps to compile and run in your development environment and then modify one of them to do what you want.
    04-27-15 06:50 PM

Similar Threads

  1. Replies: 14
    Last Post: 05-01-15, 03:40 PM
  2. How to track login attempts..???
    By Neo Anderson4 in forum BlackBerry Passport
    Replies: 5
    Last Post: 04-29-15, 05:20 PM
  3. BB10 Web Browser: Word Wrap & Settings
    By bbinoz in forum BlackBerry 10 OS
    Replies: 2
    Last Post: 04-27-15, 02:42 PM
  4. How can i subscribe to CB news and receive them in my inbox/gmail?
    By eeeeeeehsan in forum General BlackBerry Discussion
    Replies: 1
    Last Post: 04-27-15, 01:49 AM
  5. Is there any way to assign a tone to a group of contacts?
    By Batibreaker in forum Ask a Question
    Replies: 1
    Last Post: 04-26-15, 11:37 PM
LINK TO POST COPIED TO CLIPBOARD