Audio QML element in Android - no sound...

1,110 views
Skip to first unread message

Lutor Zoltán

unread,
Sep 24, 2013, 5:46:30 PM9/24/13
to andro...@googlegroups.com
Hi,

I've tried to use Audio QML element in Qt 5.1.1 for Android and no sound...
App worked fine in Win7 desktop...

I've found something related to 'playing from asset' but I have no clue
what it means and how I should use it...

http://stackoverflow.com/questions/8440600/qml-soundeffect-not-working-audio-does
https://groups.google.com/forum/#!msg/android-qt/7XF0pt9nBig/Z9rG9vrXKzIJ

Thanks,

Zoltan

***********************************


import QtQuick 2.0
import QtMultimedia 5.0

Item
{
property alias timer : soundPlaybackGapTimer
property alias audio : playAudioId
property alias source : playAudioId.source

function on()
{
off()
playAudioId.play()
}

function off()
{
playAudioId.stop() // call before stopping the timer.
// see playAudioId.onStopped
soundPlaybackGapTimer.stop()
}

Timer
{
id : soundPlaybackGapTimer
interval : 1000
running : false
repeat : false

onTriggered :
{
playAudioId.play();
}

}

Audio
{
id : playAudioId
source : "../sound/Untitled.mp3"

onStopped:
{
soundPlaybackGapTimer.start();
}

onErrorChanged:
{
console.debug("Error: ", error)
console.debug(errorString)

switch ( error )
{
case Audio.NoError:
console.debug("there is no current error.")
break
case Audio.ResourceError:
console.debug("the audio cannot be played due to a problem
allocating resources.")
break
case Audio.FormatError:
console.debug("the audio format is not supported.")
break
case Audio.NetworkError:
console.debug("the audio cannot be played due to network
issues.")
break
case Audio.AccessDenied:
console.debug("the audio cannot be played due to
insufficient permissions.")
break
case Audio.ServiceMissing:
console.debug("the audio cannot be played because the media
service could not be instantiated.")
break

default:
console.debug("GEBASZ!!!")
}
}
}
}

Mériadeg Perrinel

unread,
Sep 25, 2013, 3:38:02 AM9/25/13
to andro...@googlegroups.com
Hi zlutot,

I had the same problem.
Read this post:
https://groups.google.com/forum/#!topic/android-qt/7XF0pt9nBig

You have to embed your audio source in the assets repository or your app.
not sound repo.
Do like I did in the post and that will work for android and Qt5.1.1

Mériadeg Perrinel

unread,
Sep 25, 2013, 3:42:03 AM9/25/13
to andro...@googlegroups.com
Sorry I'll be more explicit:

replace
source   : "../sound/Untitled.mp3"

by

"assets://audio/Untitled.mp3"

And put your Untitled.mp3 under the assets repositiory like :

MyLocalMachine/MyAppRepos/assets/Untitled.mp3

And don't worry if you think it's strange that I say you to put here when you write assets://audio/...

That will work for Android but of course not for desktop !

Zoltán Lutor

unread,
Sep 25, 2013, 4:29:56 AM9/25/13
to andro...@googlegroups.com
Thanks!

"
And put your Untitled.mp3 under the assets repositiory like :
MyLocalMachine/MyAppRepos/assets/Untitled.mp3
And don't worry if you think it's strange that I say you to put here when you write assets://audio/...
"
What is 'assets repositiory'? Where to put what? I work on Windows7...
What to put into the project file (if any), where to put audio files (relative to project file/qml folder)?

Working small example would be the best...

I'm sorry for lame questions but I'm totally newbie with this assets stuff, so, what should I do? ;-)
I use Qt on desktop, Symbian and Meego but started playing with it for Android recently.
More detailed the instruction is it is better... 



2013/9/25 Mériadeg Perrinel <meri...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "android-qt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-qt+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mériadeg Perrinel

unread,
Sep 25, 2013, 8:30:48 AM9/25/13
to andro...@googlegroups.com

Hi Zlutor,

If you don't have the assets repository, that probably mean your project hasn't be created with a QtCreator wizard for QtQuick app (compatible android)
So depending of your app, I suggest you make a try with a new simple app created by this way.
Then you will have a assets repo created by the wizard.
Assuming your app is calle myPlayer
Then you will have myPlayer\android\assets

In addition, I use all of this under windows 7 too, but of course is cross plateform.

Zoltán Lutor

unread,
Sep 25, 2013, 11:10:51 AM9/25/13
to andro...@googlegroups.com
I've created it with QtCreator (for Android). I just do not know what 'assets repo' means... :-)

"myPlayer\android\assets" - should I just copy all sound files there and refer to them as "assets//audio/xxx.mp3' and I'm done? Will it be part of the apk package automatically?




2013/9/25 Mériadeg Perrinel <meri...@gmail.com>

Mériadeg Perrinel

unread,
Sep 25, 2013, 11:35:56 AM9/25/13
to andro...@googlegroups.com
It has to be done.
That cannot work if not.
But If you don't have myPlayer\android\assets repository (directory ?) I really don't now how to help you.
All my new app created with QtCreator wizard have this repository created.
And yes, packaging will make the necessaries to put them in the audio repository of your apk package.
You cannot invent it, but that works :)

zoltan...@gmail.com

unread,
Sep 25, 2013, 12:33:43 PM9/25/13
to andro...@googlegroups.com

It can be there - I just has no access to the source code atm...


So, I have to create audio folder in assets folder, copy there sound files and done?


Mériadeg Perrinel írta ekkor: 2013.09.25. 17:35

Mériadeg Perrinel

unread,
Sep 26, 2013, 3:15:32 AM9/26/13
to andro...@googlegroups.com
Zlutor,

I'm sorry but I cannot understand how you can compile your program without the source code ?
So I see two options for you.
Try to create mainly the assets repository and put your sounds there. Then in the code, tell its in assets/radio repository.
You don't have to create the radio repository. The apk will take care of that.

But, I really think you have to create a testPlayer app with only the Audio element mecanism.
Create this player using QtCreator and the good wizard, then you will have the assets repository.
Test it, after probably that will help you to integrate your sound in your first app.

Zoltán Lutor

unread,
Sep 26, 2013, 3:36:53 AM9/26/13
to andro...@googlegroups.com
Of course, I have the source code but it is on my desktop computer at home and I wrote the mail from my phone from the city... ;-)

Anyway, thanks for your help, I will try to make it work.



2013/9/26 Mériadeg Perrinel <meri...@gmail.com>

Mériadeg Perrinel

unread,
Sep 26, 2013, 3:50:06 AM9/26/13
to andro...@googlegroups.com
Lol I understand !
Sorry for that, I'm French... my English is still approximative.
Ok tell me if you success or have any other questions.

Lutor Zoltán

unread,
Sep 28, 2013, 1:45:52 PM9/28/13
to andro...@googlegroups.com, Mériadeg Perrinel
Hi,

Something is still not OK...

I've put Untitled.mp3 RatShield/android/assets but I still get the
following error on my tablet:

D/MediaPlayer( 8593): Couldn't open file on client side, trying server side
D/Qt ( 8593):
assets:/qml/RatShield/shieldappfamily/ShieldFamilyMember.qml:135
(setAudioSource): playAudioId.source: assets:/audio/Untitled.mp3
E/MediaPlayer( 8593): error (1, -2147483648)
E/MediaPlayer( 8593): Error (1,-2147483648)

Here it is the part where I try to hide platform dependency:

//-----------------------------------------
var ANDROID_SPECIFIC_PREFIX = "assets://audio/"
var OTHER_SPECIFIC_PREFIX = "../audio/"
function audioPathPrefix(audioFileName) {
var path;
switch ( getPlatform() )
{
case PLATFORM_ANDROID:
path = ANDROID_SPECIFIC_PREFIX+audioFileName
break;

default:
path = OTHER_SPECIFIC_PREFIX+audioFileName
}

console.debug("path: ", path)
return path
}

It does not work with
var ANDROID_SPECIFIC_PREFIX = "assets:/audio/"
either... :-(

What do I wrong?

Thanks,

ZOltan

On Wed, 25 Sep 2013 09:42:03 +0200, Mï¿œriadeg Perrinel
<meri...@gmail.com> wrote:

> Sorry I'll be more explicit:
>
> replace
> source : "../sound/Untitled.mp3"
>
> by
>
> "assets://audio/Untitled.mp3"
>
> And put your Untitled.mp3 under the assets repositiory like :
>
> MyLocalMachine/MyAppRepos/assets/Untitled.mp3
>
> And don't worry if you think it's strange that I say you to put here when
> you write assets://audio/...
>
> That will work for Android but of course not for desktop !
>
>
> On Wednesday, September 25, 2013 9:38:02 AM UTC+2, Mï¿œriadeg Perrinel
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Lutor Zoltán

unread,
Sep 28, 2013, 3:40:57 PM9/28/13
to andro...@googlegroups.com, Mériadeg Perrinel
Hi,

I've updated to Qt 5.1.1 and
source : "../sound/Untitled.mp3"
works for all platforms...

Br,

Zoltan

On Wed, 25 Sep 2013 09:42:03 +0200, Mï¿œriadeg Perrinel
<meri...@gmail.com> wrote:

> Sorry I'll be more explicit:
>
> replace
> source : "../sound/Untitled.mp3"
>
> by
>
> "assets://audio/Untitled.mp3"
>
> And put your Untitled.mp3 under the assets repositiory like :
>
> MyLocalMachine/MyAppRepos/assets/Untitled.mp3
>
> And don't worry if you think it's strange that I say you to put here when
> you write assets://audio/...
>
> That will work for Android but of course not for desktop !
>
>
> On Wednesday, September 25, 2013 9:38:02 AM UTC+2, Mï¿œriadeg Perrinel

Mériadeg Perrinel

unread,
Sep 30, 2013, 4:12:21 AM9/30/13
to andro...@googlegroups.com, Mériadeg Perrinel
Hi, lol I was looking was that wasn't works.
And telling me : "That may works, what is the problem..."
After 10 minutes : "Have to ask if its Qt is really in Qt5.1.1"

Then read your last post, and see that you finally did it !
lol

Ok nice, enjoy !

Mériadeg Perrinel

unread,
Apr 15, 2014, 3:24:28 PM4/15/14
to andro...@googlegroups.com, Mériadeg Perrinel
Hi, I come back on this post today because the Audio source property doesn't seems to works in 5.2.1 like it was in 5.1.1
In 5.2.1, it's possible to use QRC to store the mp3 like jpg or whatever you want.
With my SIII, I have make it works. But I have found a problem  with the generated .pkg:
If you want to install this one in another Android device, the sound isn't load.
So that works with the Android device used in the complete tool-chain (directly installed from QtCreator), but its seems to be impossible to use the generated .pkg on another device.

Do someone see the same behaviour and / or have any idea of how to fix it ?

Thanks for the help.

Mériadeg Perrinel

unread,
Apr 16, 2014, 2:07:18 PM4/16/14
to andro...@googlegroups.com, Mériadeg Perrinel
Ok, the problem is solved, but let's explain it from the beginning:

I'm on Windows 8 64 and use Qt5.2.1

That is the code of the main.qml file that works on desktop version:

...


    Audio {
        id: playMusic
        source: "qrc:/mymusic.mp3"
    }
...

This is a part of my app repository

myApp/
myApp/myApp.pro
myApp/mymusic.mp3
myApp/ressource.qrc
myApp/qml/myApp/main.qml


Of course mymusic.mp3 is on my ressource.qrc

With the desktop version, my sound is loaded and can be played.
With the android version, I have two behaviour:
1) The first one is that for the Android device that is connected to my computer and recognized by QtCreator, so the one use for the android compilation and deployment toolchain,
that works too.
2) The myApp.apk generated should be normally the same as the one installed by the toolchain on my Android device, but it seems to be wrong.
So If I completely removed the installed version of my device and installed again by myself the myApp.apk the mp3 isn't loaded (the graphics part of the app works).

This behaviour can be reproduced on Samsung SIII, Samsung SII, LG F6, bluestack

To bypass the problem with Android, I have to do two thing:

1) Change my app repository to:
myApp/
myApp/myApp.pro
myApp/ressource.qrc
myApp/qml/myApp/main.qml
myApp/qml/myApp/mymusic.mp3

2) Then change my code to:
...
Audio {
        id: playMusic
        source: "mymusic.mp3"
    }
...

Of course in this case, mymusic.mp3 don't needs to be in the qrc
So that works for Android because in the myApp.apk, the mp3 is copied next to the main.qml
It's not cross platform...

If you have more info about all of this feel free to answer here

Meriadeg
Reply all
Reply to author
Forward
0 new messages