Results 1 to 2 of 2

Thread: QMediaplayer Sound file problem

  1. #1
    Join Date
    Nov 2014
    Posts
    12
    Thanks
    4

    Default QMediaplayer Sound file problem

    Hello,

    I have a problem with QMediaPlayer play sound in a different PC than in the developed one.
    The release program works just fine in the PC that I have developed (I've copied all *.dll,...), but trying to use the same program in a different PC there is no sound.
    I have my sounds in my Resources and their are together with the images that I use, so it isn't path fail.

    I create in the header (*.h) file my QMediaPlayer variable:
    Qt Code:
    1. QMediaPlayer * ErrorSound;
    To copy to clipboard, switch view to plain text mode 

    At cpp, in the constructer, I load the sounds:
    Qt Code:
    1. ErrorSound = new QMediaPlayer();
    2. ErrorSound->setMedia(QUrl("qrc:/Error.wav"));
    To copy to clipboard, switch view to plain text mode 

    Further in the correct place I call it to play:
    Qt Code:
    1. ErrorSound->play();
    To copy to clipboard, switch view to plain text mode 

    I've checked the Data.qrc (my resource file) and all files are there:
    <RCC>
    <qresource prefix="/">
    .......other files
    <file>Error.wav</file>
    </qresource>
    </RCC>

    All image files and sound files are in same place, same folder, as the *.exe file.

    If anyone got this problem and know how to fix it i would thank you for helping me out.

  2. #2
    Join Date
    Sep 2013
    Posts
    11
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: QMediaplayer Sound file problem

    In the header define the following

    Qt Code:
    1. private:
    2. QPointer <QMediaPlayer> mp3backgroundplayer;
    3.  
    4.  
    5. signals:
    6.  
    7. void playmp3background();
    8. void stopmp3background();
    To copy to clipboard, switch view to plain text mode 


    in the code use this to load it from the resource file

    Qt Code:
    1. QPointer <QMediaPlayer> mp3backgroundplayer = new QMediaPlayer (this);
    2. // ...
    3. mp3backgroundplayer->setMedia(QUrl("qrc:/spacegame/images/gamemedia/spacegamebackground.mp3"));
    4. mp3backgroundplayer->setVolume(30);
    5. mp3backgroundplayer->l
    6.  
    7. mp3backgroundplayer->play();
    8. connect(this,SIGNAL(playmp3background()),mp3backgroundplayer.data(),SLOT(play()));
    9. connect(this, SIGNAL(stopmp3background()), mp3backgroundplayer.data(), SLOT(stop()));
    To copy to clipboard, switch view to plain text mode 


    to stop use this

    Qt Code:
    1. this.emit(stopmp3background());
    To copy to clipboard, switch view to plain text mode 


    good luck

Similar Threads

  1. QMediaPlayer record radio stream to file?
    By gadlol in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2013, 17:33
  2. QMediaPlayer repeat sound
    By alenn.masic in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2013, 15:46
  3. QMediaPlayer: MP4 file with AAC audio format
    By ollerei in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2013, 03:51
  4. Replies: 1
    Last Post: 26th November 2012, 20:09
  5. Sound not playing when using executable file
    By Zotop in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2010, 00:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.