Results 1 to 6 of 6

Thread: MP3 file from Resources :-/

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 ?

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, 00:12
  2. Replies: 8
    Last Post: 5th November 2012, 08:43
  3. Qt Resources
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2008, 16:30
  4. getting absolute file path of Qt resources
    By dvmorris in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2007, 02: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, 00: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.