Hi Chris
I am learning the APP inventor because I am going to start giving classes in high school and I was asked to give this subject.
I am taking a course in Coursera, but I do not understand everything they are teaching.
I had followed their instructions to make an app to set up an Alarm and the code does not work.
I do not know what to do in order to see what was wrong with the blocks, is there any way to see what the problem was?
Right, first thing to note is that this tutorial is not a good example of what App Inventor can be used for. The reason is, An alarm that spans hours requires the App to stay on for that length of time, which can be done but it will drain the battery. Making a custom alarm requires access to Android Background Services but App Inventor does not support this. Another issue is that the Clock Timer lacks accuracy - it is suitable for many purposes but for accurate timing my colleague Anke has created an extension.
However, we can test over a few minutes without concern for the battery
⌠the .mp3 might be too big for the Sound Component so I substituted the Player Component just in case.
Basically, the code works like this:
Get the Alarm time set by the User
Get the Time Now
Convert both times to milliseconds (the unit used by the Clock Timer)
Subtract Time Now from Alarm Time to get the Duration of Time until the Alarm should trigger - set that value as the Clock Timer Interval and Enable the Clock timer.
So, I can see nothing wrong with the code logic, but I can confirm it doesnât work with the Companion. I simplified the code and still no joy
Doesnât work as an APK either. Must be something obvious Iâm missing. I have tested my own simplified code. âDoItâ correctly shows the ClockTimer should tigger in 120000 milliseconds (2 minutes). The Clock is triggered at the correct time - we know that because the Label text is changed from the Alarm time to the âAlarm not Setâ message. Yet the .mp3 is not played (I have verified it is OK) and even vibrate fails to happen.
Well, I have tried taking the sound functions out of the Timer block and put them into a procedure but still no sound/vibration is played when the Timer is triggered.
Itâs getting late (Iâm in the UK), so I will assign this puzzle to a colleague.
We want you to learn to code with App Inventor Ilya. This note does not provide advice about your Project specifically but might provide a different way to look at and learn to code with Blocks.
Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventorâs Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ⌠the links are at the bottom of the Web page. The book âteachesâ users how to program with AI2 blocks.
If your course explanations are too difficult and you cannot get help from that course, the above resources and FREE course mentioned may help you develop the skills necessary to teach the computer course.
Little test, no alarms, no clocks. Tested Sound and Player components. The .mp3s are still not played! The App Inventor IDE does play them, and they are within the Android spec.
Mono/Stereo 8-320Kbps constant (CBR) or variable bit-rate (VBR)
Alarm-ringtone.mp3 and Twin-bell-alarm-clock-sound.mp3 are both 192kbps 44100Hz
My Test, with a couple of extra files: PlaySound.aia (1.7 MB)
Evan - am I getting something very basic wrong? Is it the path to the files that is a problem?
Yes, everything works fine. I have tried almost all audio formats and sample rates in the past few years. No problems, so it wonât be because of that. Which device and which Android version is it (tested with Companion or APK)?
Does Hello Purr work for you, if using both Sound and Player? I wasnât able to get this to work in an Android 9 emulator, but it was also the case that Hello Purr didnât work in spite of it being dead simple. Everything worked on my Google Pixel running Android 10.
Can you play the MP3 files through your phoneâs default music app?