AppFurnace2
How do I play, pause, or stop an audio when a button is pressed?
1. Adding the audio files
Open up the Files tool, by clicking the Files tab at the top of the screen
Press the Upload button, and select the audio file you want to play from your computer.
2. Adding a button to press
Open up the Layout tool
Drag a button from the Widgets panel to the canvas.
Click the button.
In the property box on the right-hand side of the screen, select the Code tab (with the 010101 icon).
3. Playing an audio
Ensure you’ve uploaded an audio file and made the button (see above).
Type ‘playMyAudio’ into the text box marked tapped function. This tells the system the name of the function (we’ll come to that) that will be used when the button is tapped.
Open up the Code tool by clicking the Code tab at the top of the screen.
Copy-and-paste the following code into the main window, put it underneath anything that’s already there.
function playMyAudio() {
var a = new af.Audio(“myaudio.mp3”);
a.play();
}
You will need to substitute the name of your mp3 file for the one shown above ( myaudio.mp3 ).
Pausing an Audio
Ensure you’ve uploaded an audio file and made the button (see above).
Put pauseMyAudio into the tapped function box (see above)
Add the following function to the Code tab (replacing the mp3 with your file name).
Note that pausing a audio that’s not playing will have no effect. If the audio is currently paused, then playing it (see function above) will make it continue from where it left off.
function pauseMyAudio() {
var a = new af.Audio(“myaudio.mp3”);
a.pause();
}
Stopping an Audio
Ensure you’ve uploaded an audio file and made the button (see above).
Put stopMyAudio into the tapped function box (see above).
Add the following function to the Code tab (replacing the mp3 with your file name).
If you play an audio that’s been stopped, it’ll start from the beginning.
function stopMyAudio() {
var a = new af.Audio(“myaudio.mp3”);
a.stop();
}
———————————————-
How do I open a web page when a button is pressed?
You can make your app open the device’s web browser and navigate to a URL of your choosing. For example, you might want to open your company’s homepage, or show a wikipedia page with more information about a subject.
Here’s how to do it:
- Open up the Layout tool
- Drag a button from the Widgets panel to the canvas
- Click the button
- In the property box on the right-hand side of the screen, select the Code tab (with the 010101 icon).
- Type ‘openUrl’ into the text box marked tapped function. This tells the system the name of the function (we’ll come to that) that will be used when the button is tapped.
- Open up the Code tool by clicking the Code tab at the top of the screen.
- Copy-and-paste the following code into the main window, put it underneath anything that’s already there.
function openUrl() {
af.openLinkInWebBrowser(“http://www.appfurnace.com”);
}
- You can substitute your own URL for the one shown above. Just be sure to include the http:// part.
Note that for technical reasons when you use the Preview tool, the webpage will not be displayed directly, just a link. On the real Android and iPhone devices the webpage will be immediately loaded.