July 17, 2011

jkosonen jkosonen
Ant Farmer
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…

11 replies

July 18, 2011

Chuck Gao Chuck Gao
Robot Herder
337 posts

What’s the error? Can not find files?

 Signature 

Chuck

July 18, 2011

jkosonen jkosonen
Ant Farmer
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
Robot Herder
337 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
Ant Farmer
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
Hobby Entomologist
60 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
34 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
Ant Farmer
53 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

 
  ‹‹ [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!