Phonon::MediaSource, cannot use resource as media source

693 views Asked by At

with QT 4.6, I am trying to access a wav file in my QResource file to use as the media source of a media player and it does not work:

Phonon::MediaObject *music;  
music=Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource(:/FPS_sounds/arming.wav));  
music->play();

If I put the direct path it works. I have been successful at using resources in other parts of my program so there does not seem to be a problem there and the Qt doc says I can use QResource for this type of operation. Is this a bug or am I missing something?

1

There are 1 answers

0
reflog On BEST ANSWER

This one gave me a good scratch as well. But lo and behold, it can be implemented easily using a temporary file:

  {
        QTemporaryFile f;
        f.open(); 
        QResource res(":/badger");
        f.write((char*)res.data(),res.size());
        f.flush();
        f.setAutoRemove(true);
        f.close();
        QString fn = f.fileName();
        QSound::play(fn);
    }