The On Show event is triggered whenever the page opens. The background music will still be playing when the user leaves Page1, so this action should pause the music when the user arrives at the Video page.
3 ) C op y t h e A udio.Toggl e P l ay ac t ion t o t h e p a g e ' s On C lo s e eve n t .
We want to add another Audio.TogglePlay action to the On Close event for this page, to toggle the background music back on when the user jumps back to the main page. It needs to be just like the action you added to the On Show event, because we want the two actions to balance each other out-one to turn the audio off, and one to turn it back on again.
You could click on the On Close tab and then add another action the same way you did in step 2. But since we want this action to have the same parameters as the first one, you might as well save yourself a bit of time and just copy the text from one tab to the other.
To do so, just select the whole line of text and press Ctrl+C to copy it into the clipboard. Then, click on the On Close tab, and press Ctrl+V to paste the text onto it.
Note that this won't affect the action that you added to the On Show tab at all-the actions you add to one tab stay the same when you switch to another one. You're just making a change to both events at the same time.
Once you've configured the action for the On Close event, click OK to close the script editor and confirm your changes.
In the properties pane, both events should now show "1 Line" next to them.
4 ) P rev i e w t h e p r oj ec t , a nd c li ck on t h e " V id e o P re s e n t a t ion " bu tt on t o ju m p t o t h e V id e o p a g e .
Now the background music stops when you arrive at the Video page, and the video's audio plays all by itself.
This is because the Audio.TogglePlay action is pausing the background channel on the page's On Show event.
5 ) C li ck on t h e Back bu tt on t o re t u r n t o t h e ma in p a g e .
When you click on the Back button, the background music starts playing again, right where it left off. This time it's the Audio.TogglePlay action on the page's On Close event that is toggling the background audio channel back on.
6 ) E x i t t h e p rev i e w.
That's it for this preview, so click on the Exit button (or press Alt+F4) to exit the application and return to the AutoPlay design environment.
Loading and Playing an Audio File
Now that you know how to pause the background music, let's tackle playing an audio file in response to an event. For example, you might want to start playing an audio file when the user clicks on a button, or when the user jumps to a specific page.
For this exercise, we'll play a different audio file while the user is on the About Ted page.
1 ) S wi t c h t o t h e A bou t T e d p a g e . D oubl e - c li ck on t h e p a g e s u r f ace , a nd c li ck on t h e S cr ip t t a b. I n t h e s cr ip t e di t o r , c li ck on t h e On
S how t a b, a nd a dd a n A udio. P a u s e ac t ion t o p a u s e t h e b ack g r ound
a udio c h a nn e l.
Before we start playing a different song, we need to pause the background music. Although we could use an Audio.TogglePlay action to do it, like we did on the Video page, let's use an Audio.Pause action this time.
To add the action, just click on the Add Action button, select the Audio.Pause action from the list, and click Next to get to the action's parameters. Set the Channel parameter to CHANNEL_BACKGROUND, and click Finish.
That will pause the background music. Now we need an action to play a different audio file.
2 ) C li ck t h e A dd Ac t ion bu tt on t o a dd a s ec ond ac t ion t o t h e On S how t a b. Wh e n t h e Ne w Ac t ion wi z ar d a pp ear s , c hoo s e t h e " A udio "
ca t e go ry . S e l ec t t h e A udio. P l ay ac t ion f r o m t h e li s t , a nd c li ck Nex t .
If you were looking through the list of audio actions, and you wanted to play an audio file, you might head straight for Audio.Play. But when you clicked Next to customize the action, you wouldn't see any way to specify an audio file. All you would find is a single parameter letting you select the audio channel that you want to play.
This is because the Audio.Play action is used to start playing a file that has already been loaded into an audio channel.
In fact, the Audio.Play action assumes that you've already loaded an audio file into a channel using an Audio.Load action.
Luckily, the Audio.Load action gives you a way to do both at the same time.
3 ) C li ck Back t o go b ack t o t h e f i r s t p a g e o f t h e Ne w Ac t ion wi z ar d. S e l ec t t h e A udio.Lo a d ac t ion in s t ea d, a nd c li ck Nex t . L eave t h e
C h a nn e l p arame t er s e t t o CHANN E L _NARRA T I O N , a nd s e t t h e P l ayA u t o ma t i c a nd Loop p arame t er s bo t h t o t r u e .
The Audio.Load action certainly has more parameters to play with.
We want the audio file to play in a different channel than the background music, so leave the Channel set to CHANNEL_NARRATION. The name implies that this channel is for "spoken" audio, but that's only one use for it. You're free to use the channel for other forms of audio, which is exactly what we're going to do.
Note: We don't want to use the background audio channel for this, because it's already occupied by a song from the Background Music tab...and we only want to replace that music "locally" on the About Ted page-not everywhere. Since we're only after a temporary change, we need to leave the background audio channel alone.