Record a Message!
Getting fit isn’t easy: sometimes it can be hard to motivate yourself to go and exercise. How about letting the user record a message that they can play whenever they need some extra motivation?
-
Go to the Designer view and add two more Buttons to your app. Set their labels to
Play motivational message
andRecord
, or something similar. -
Then, from Media, add a Sound and a SoundRecorder component. Just like the File component, these won’t be visible on the screen.
-
In Blocks, add a
when Button.TouchDown
block and awhen Button.TouchUp
block for theRecord
button. This time, you’re not going to detect the usual click of the button. Instead, you’re going to start recording when the user presses and holds the button, and you’ll stop recording when they stop pressing. -
Add
call SoundRecorder.Start
to theTouchDown
block, andcall SoundRecorder.Stop
to theTouchUp
block, like this:
Now you can record sound, you need to set up the Sound component to play it!
-
Drag out the
when SoundRecorder.AfterSoundRecorded
block. -
In the Sound component, find the
set Sound1.Source to
block and put that inside the block you just took out.
The AfterSoundRecorded
block has a variable called sound
. This is the where you tell the block where for find the sound file you’ve recorded.
- Hover over the
sound
variable and take theget sound
block to attach on as the source for the Sound component:
- Finally, take out a
Button.Click
block for thePlay
button. In it, put acall Sound1.Play
from the Sound component.
- Test out the app and have some fun recording and playing back your own motivational messages!
Challenge: save the sound
- See if you can use a File component to make the app remember the location of the sound file to play.