Results 1 to 6 of 6

Thread: MP3 file from Resources :-/

  1. #1
    Join Date
    Nov 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question MP3 file from Resources :-/

    Hi!

    How can I use a mp3 file from Resources ? I have tried the following code but without any success. I would appreciate if someone could shed some light on how to play audio files from the resource qrc file. Thanks !

    Qt Code:
    1. QString location = ":/kalimba.mp3";
    2.  
    3. m_mediaObject = new Phonon::MediaObject(this);
    4.  
    5. // Setup player
    6. m_videoWidget = new Phonon::VideoWidget(this);
    7. Phonon::createPath(m_mediaObject, m_videoWidget);
    8. setCentralWidget(m_videoWidget);
    9.  
    10. //m_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
    11. m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    12. m_audioOutput->setVolume(100.0);
    13. Phonon::createPath(m_mediaObject, m_audioOutput);
    14.  
    15. QObject::connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State)));
    16. //m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(location.toUtf8())));
    17. m_mediaObject->setCurrentSource(Phonon::MediaSource(location.toUtf8()));
    18.  
    19. m_mediaObject->play();
    20.  
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    The qrc file:

    Qt Code:
    1. <RCC>
    2. <qresource prefix="/">
    3. <file>kalimba.mp3</file>
    4. </qresource>
    5. </RCC>
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MP3 file from Resources :-/

    have you checked if the code works if you specify a mp3 file from your disk (for debugging purpose)?

  3. #3
    Join Date
    Nov 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: MP3 file from Resources :-/

    Yes the code works fine with a local mp3 file.

    Qt Code:
    1. QString location = "/Users/pat/Documents/QT_projects/PhononMp3-build-desktop/kalimba.mp3";
    To copy to clipboard, switch view to plain text mode 

    Is the resources qrc file the only way to get a media file embedded with the executable file ?

  4. #4
    Join Date
    Nov 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: MP3 file from Resources :-/

    Did anyone encountered the same problem ? I am testing on the mac platform...
    MediaSource recognizes only absolut paths ? isn't it possible to have only :

    Qt Code:
    1. QString location = "kalimba.mp3"
    To copy to clipboard, switch view to plain text mode 

    The mp3 file is inside the build desktop directory

    Thanks


    Added after 55 minutes:


    This works works if I include the mp3 file into the phonon.app/Contents/MacOS directory:

    Qt Code:
    1. Phonon::MediaObject *music = createPlayer(Phonon::MusicCategory,
    2. Phonon::MediaSource("kalimba.mp3"));
    3. music->play();
    To copy to clipboard, switch view to plain text mode 

    My problem with an audio file within the qrc file is still not resolved. Any help would be appreciated
    Last edited by qtpat; 26th November 2010 at 16:02.

  5. #5
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: MP3 file from Resources :-/

    Quote Originally Posted by qtpat View Post
    My problem with an audio file within the qrc file is still not resolved. Any help would be appreciated
    And it still causes trouble ...
    got it to work on Windows with qrc, but only in Qt Creator -_-
    on Mac only local files, no qrc (app ran outside of qt creator, also with QMediaPlayer)

  6. #6
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MP3 file from Resources :-/

    Hi,

    I have the same problem, have you found any solution ?

    thank you

Similar Threads

  1. Is it possible to add QT resources to a DLL?
    By cboles in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2017, 01:12
  2. Replies: 8
    Last Post: 5th November 2012, 09:43
  3. Qt Resources
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2008, 17:30
  4. getting absolute file path of Qt resources
    By dvmorris in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2007, 03:56
  5. QMessageBox Icon Issue and How to add a dir to Qt Resources File
    By vishal.chauhan in forum Qt Programming
    Replies: 19
    Last Post: 25th March 2007, 01:13

Tags for this Thread

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.