July 17, 2011

jkosonen jkosonen
Lab Rat
66 posts

Audio element not working? How to play from resource?

 

I’m having problems using audio element from qml file located in resource file.

If my qml file is not in resource, the sound plays just fine. But instantly after I put the qml file to the resource, I can’t hear the audio element anymore. What should I do? I have tried putting the sound file to resource and to use it from file path…

13 replies

July 18, 2011

Chuck Gao Chuck Gao
Lab Rat
342 posts

What’s the error? Can not find files?

 Signature 

Chuck

July 18, 2011

jkosonen jkosonen
Lab Rat
66 posts
Chuck Gao wrote:
What’s the error? Can not find files?

It’s mute. If I use soundeffect it works, but then I can’t change the volume.

July 19, 2011

Chuck Gao Chuck Gao
Lab Rat
342 posts

I think it’s a problem with path, there is no error(Output to the console) about this ?

 Signature 

Chuck

July 19, 2011

jkosonen jkosonen
Lab Rat
66 posts
Chuck Gao wrote:
I think it’s a problem with path, there is no error(Output to the console) about this ?

There’s no error with path, since if I change it to SoundEffect it works..

July 27, 2011

AlterX AlterX
Ant Farmer
123 posts

I’ve a similar problem…
On Symbian^3 and Harmattan if i embed the qml in the resource, sounds (using SoundEffect) don’t hear!
If i load qml as a local file, sounds work, but no images are loaded from the resource!!!

September 8, 2011

pscanlan pscanlan
Lab Rat
4 posts

I have the same problem and it is not related to the path! It crashed the app.

February 18, 2012

nokiadev nokiadev
Lab Rat
7 posts

Did anyone find a solution yet as I too have the same issue :(

February 21, 2012

nokiadev nokiadev
Lab Rat
7 posts

I have solved this issue by using “file” protocol in audio source

  1. Audio {
  2.    id: playSound
  3.    source: "file:///opt/YourProject/sounds/game.mp3"
  4. }

February 22, 2012

kibsoft kibsoft
Lab Rat
37 posts

I knew about file:///, but is there possibility to play sound from resource file?

February 24, 2012

nokiadev nokiadev
Lab Rat
7 posts

Yes I have played sound from resource file but with some limitations e.g.

  • sound file size: 70kb approx.
  • Bit Rate: 8 bit
  • .wav files only
  • and the most worst thing is that It plays once.

March 25, 2012

owenzhao owenzhao
Lab Rat
60 posts

You can leave you sound file outside of resource file, then use

  1. viewer.rootContext()->setContextProperty("installPath", "file:///" + QCoreApplication::applicationDirPath() + "/");

in your main.cpp, make sure this line is before you setsource(“main.qml”)
In you qml code, just use
  1.         Audio {
  2.                  id: playMusicAudio
  3.                  volume: 1.0
  4.                  source: installPath + "sound/youmusic.mp3"
  5.         }

You need to have this in you app.pro file

  1. # Add more folders to ship with the application, here
  2. folder_01.source = qml/yourappname/sound
  3. DEPLOYMENTFOLDERS = folder_01

March 5, 2013

matti- matti-
Ant Farmer
107 posts

Perhaps it would be sensible to write a C++ wrapper that would read the mp3 audio file from the resource and feed it to QSound somehow? Is this even an issue anymore? Just stumbled upon this thing today when learning QML – noticed that my Audio {} would not play an .mp3 from within a resource and I’d prefer not to ship separate audio files.

I’d bet there already exists a robust solution, will keep googling.

edit: Guess I’ll try writing a C++ component that wraps the Phonon player. Somehow strange that images work fine from within qrc but not media..?

 Signature 

Author of MMark13

March 6, 2013

matti- matti-
Ant Farmer
107 posts

Doesnt seem to be happening with QMediaPlayer API either.. keep getting QMediaPlayer::FormatError , “Failed to load media” for the qrc sources.

Probably could write the resource file into /tmp file and play from there but that would be quite silly. Guess I’ll ship the audio files with the app as separate files. :)

 Signature 

Author of MMark13

 
  ‹‹ [solved] Window stays blank after deploying application to another Windows-PC      Deactivate checked Checkbox if a certain condition is met? ››

You must log in to post a reply. Not a member yet? Register here!