Mark Gibbons
Posts: 0
Joined: Thu Jan 23, 2014 12:02 pm

How do I add audio to a button?

Hi there; I'm unfamiliar with any code or HTML5 but trying to learn, and as of writing this I'm only 3 hours into it so I sincerely apologise for being out of touch or asking a stupid question.

I simply want to create an app, that's just the home screen with a button, when you push the button it plays a sound effect. (I have a 0.3MB, 2 second .mp3 file that I want to use for it.) And that's basically my app.

I cannot figure out how to add an .mp3 to a button, or even the music tab that is offered.

Any help, in simpleton speak for now would be greatly appreciated. (Along with any advice for a complete beginner). Also as some feedback to any staff: It was amazingly simple to upload and add the image from my computer, if uploading small sound files to segments was similar, that would really speed things up.

Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I add audio to a button?

Hi Mark,

You can specify a link to an mp3 file in properties panel:
http://docs.appery.io/documentation/u...

You can also set its URL dynamically: preAppery("mobileaudio").attr("src", "http://example.com/1.mp3");/pre
Where mobileaudio is a name of Audio component and http://example.com/1.mp3 is a link to mp3 file.

Rom
Posts: 0
Joined: Wed Jun 18, 2014 3:26 pm

How do I add audio to a button?

Thanks Katya,

I had a similar question and your answer did help me to some extent.
Could you please also brief how can I access a stored variable and play using a URL stored in variable?

I'm using the below code:

var url = localStorage.getItem("songDirectLink");
alert(url);
Appery("audioPlayer").attr("src", "url");
Appery("audioPlayer").trigger("play");

The alert, which I just created to test the variable and it's value gives right URL that I want player to play. However, player doesn't load the remote file, but if I manually insert URL instead of var "url", player works fine.

Please help!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I add audio to a button?

Hi Rom,

You pass a string "url" rather than a variable to Audio component, so replace:preAppery("audioPlayer").attr("src", "url");/preWith:preAppery("audioPlayer").attr("src", url);/pre

Return to “Issues”