×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    26

    Question Play an audio file from Resources :-/

    Hello!

    How can I use an audio 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 !


    Code:
    Phonon::MediaObject *music = createPlayer(Phonon::MusicCategory, Phonon::MediaSource(":/music.wav"));
    music->play();
    Code:
    <RCC>
        <qresource prefix="/">
            <file>music.wav</file>
        </qresource>
    </RCC>
    PS: The code works fine with a local audio file but not via the .qrc file

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Play an audio file from Resources :-/

    If I recall correctly its not possible to play audio file from the resource file.
    I believe if you extract the audio file from the resource to the dir of your choice, you can then access it and play as desired.
    Cheers,
    Jon

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    26

    Re: Play an audio file from Resources :-/

    Thanks Jon. Yes I have given up for now the idea to play audio files from resource files

    Regards,

    Pat

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Play an audio file from Resources :-/

    Not much point in putting an audio file in resources, unless you have lots of small ones. Better to just use DEPLOYMENT to install the file on the device. Remember, anything in resources takes up more RAM and makes app loading slower.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Play an audio file from Resources :-/

    Quote Originally Posted by danhicksbyron View Post
    Remember, anything in resources takes up more RAM and makes app loading slower.
    Oh, this is good to know!
    So if I have say 500 images in a resource file, the quickest way to access them for iteration would be via the resource directly?
    I have an app that iterates through a list of images with speed controls to iterate through the given list(10 to 15 images at a time). I was worried that I may need to extract the list of images from the resource to a location before iterating for speed, perhaps that will not be an issue?
    Excuse my ignorance, I am a Qt,c++ rookie.
    Sorry for the hijack!
    Cheers,
    Jon

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Play an audio file from Resources :-/

    Resource files are good for small files that are frequently referenced. A small file (small images, style sheets, etc) takes up a minimum of something like 2K in the file system, and takes a non-trivial amount of time to open. Placing it in a resource file means it only takes up the storage for its actual size, and it can be opened quickly.

    The downside is that it's compiled into the application and so takes up RAM for as long as the app is loaded and running.

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: Play an audio file from Resources :-/

    Thanks for the info!
    I should be all set then as my images are only around 3~6k each.
    It seems to run quick enough in the emu and over the RDA but unfortunately I don't have an actual device to give it a true test....
    In any event, I just released it so this handy info you passed on makes me happy!
    Cheers,
    Jon

  8. #8
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    Re: Play an audio file from Resources :-/

    Quote Originally Posted by Jon Heron View Post
    If I recall correctly its not possible to play audio file from the resource file.
    I believe if you extract the audio file from the resource to the dir of your choice, you can then access it and play as desired.
    Cheers,
    Jon
    +1. On most platforms, neither Phonon nor QSound do resources.

    Workaround code:
    Code:
    	QFile file2(QDir::tempPath() + "/lrgboom.wav");
    	if (file2.open(QIODevice::ReadWrite))
    	{
    		QFile workFile(":/sfx/rsc/music/lrgboom.wav");
    		if(workFile.open(QIODevice::ReadOnly))
    		{
    			file2.write(workFile.readAll());
    			workFile.close();
    		}
    		file2.close();
    	}
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

Similar Threads

  1. Play wav file in resources with QMediaPlayerControl
    By daudrain in forum [Archived] Qt Mobility Project
    Replies: 1
    Last Post: 2010-08-18, 14:55
  2. how 2 play audio file
    By manmay.gupta in forum Symbian
    Replies: 4
    Last Post: 2009-05-26, 07:58
  3. play audio file
    By nitroxxx123 in forum Symbian
    Replies: 1
    Last Post: 2009-04-12, 07:52
  4. Replies: 2
    Last Post: 2008-02-20, 08:42
  5. How can I play the segment of an audio file, e.g. wav. file in my N73?
    By ipxx in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2007-07-30, 05:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×