INQ241B
Mobile Apps

Activity 0

Extend the Play Sound App

  1. Modify the Play Sound app you created to also play a sound when you shake the phone. To do this, first add an AccelerometerSensor component, found under the Sensors section of the component designer. Then in the blocks editor, add a Shaking event handler, found in the AccelerometerSensor drawer. Finally, add a Play function call, found in the Sound drawer, to the event handler. Test your changes by shaking the phone.

  2. As you shake the phone, the sound will sound strange, as if it is echoing. That is because the accelerometer sensor is triggering the shaking event many times a second, so the sounds are overlapping. If you look at the Sound component in the Designer, you will see a property called Minimum interval. That determines how close together successive sounds can start. It is currently set at a half-second (500 milliseconds), which is probably less than the duration of a single sound. By playing with the minimum interval, you can change how much the sounds overlap. Set the minimum interval so that the sound do not overlap at all.