Timer with sound question

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Timer with sound question

Post by ctflatt » Fri Apr 29, 2011 12:58 pm

I am needing to play a sound file (alarm.mp3) after a specific time has passed. I have looked at other timers/counters in the forum and found this one, which is working for tracking the minutes and seconds. How/where would I implement a play command to play the sound file after X minutes/seconds have passed?

This script produces the sound, but it keeps repeating the first second of the sound file over and over...

I'm sure the problem is in the message order, but I am at a loss... could someone point me in the right direction?

Any input would be appreciated, as always :)

:Todd

Code: Select all

global gWeight
local tMin1, tSec1, tCalories

on mouseUp
   --start with graphic "Stand"
   if the label of me is "Stand" then
      --change graphic to "Sit"
      set the label of me to "Sit"
      set the icon of me to 1060
      put 0 into tMin1
      put 0 into tSec1
      --update calories burned
      send "CaloriesBurned" to me in 60 seconds
      --start timer
      send "Timer1" to me in 1 second
      --sound alarm
      send "soundAlarm" to me in 120 seconds
   else if the label of me is "Sit" then
      --change graphic to "Stand"
      set the label of me to "Stand"
      set the icon of me to 1059
      put 0 into tMin1
      put 0 into tSec1
      put "00" into field "1Sec"
      put "00" into field "1Min"
      put 0 into tCalories 
   end if
   
end mouseUp

on Timer1
      add 1 to tSec1
      if tSec1 < 60 then
            if tSec1 <= 9 then
                  put "0" & tSec1 into field "1Sec"
            else
                  put tSec1 into field "1Sec"
            end if
      else
            if tSec1 = 60 then
                  put "00" into field "1Sec"
            end if
            put 0 into tSec1
            add 1 to tMin1
            if tMin1 <= 9 then
                  put "0" & tMin1 into field "1Min"
            else
                  put tMin1 into field "1Min"
            end if
      end if
      if the label of me <> "Stand" then
            send "Timer1" to me in 1 second
            send "CaloriesBurned" to me in 60 seconds
      end if
end Timer1

on CaloriesBurned
   put the round of (gWeight * tMin1 * .009) into tCalories
   put tCalories into field tCaloriesBurned 
end CaloriesBurned

on soundAlarm
   set the blendLevel of img "alarm_icon_retina.png" to 0
   play specialFolderPath(engine) & "/assets/alarm.mp3"
end soundAlarm
Last edited by ctflatt on Fri Apr 29, 2011 3:06 pm, edited 1 time in total.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Timer with sound question

Post by ctflatt » Fri Apr 29, 2011 1:05 pm

Ok, now I'm totally baffled... The script is now working fine, however, I have encountered a new issue...

Once the soundAlarm is issued, there is a delay in the update of the timer... is this a place for "without waiting"?

If so, on what?

Thanks, and sorry for the false, um... alarm...

:Todd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Timer with sound question

Post by bn » Fri Apr 29, 2011 2:57 pm

Hi Todd,

why don't you just say:

Code: Select all

on mouseUp -- or whatever
   send "soundAlarm" to me in 3 seconds -- change this
end mouseUp

on soundAlarm
   if the environment is mobile then
         set the blendLevel of img "alarm_icon_retina.png" to 0
         play specialFolderPath(engine) & "/assets/alarm.mp3"
   else
      beep
   end if
end soundAlarm
if you want a one-off sound alarm?

Kind regards

Bernd

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Timer with sound question

Post by ctflatt » Fri Apr 29, 2011 3:03 pm

Bernd:

Thanks for the reply...

I have to show minutes and seconds elapsed, and provide a toggle button to stop/start as well.

I have this all scripted, but there is a delay in the "count" as the sound starts. This is what I'm trying to fix now.

:Todd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Timer with sound question

Post by bn » Fri Apr 29, 2011 3:14 pm

Hi Todd,

It would help if you would explain a bit more what you want to do in a question. I had the impression the code you posted was the code you grabbed somewhere and you try to adapt it to your situation.

Is this your actual code and does it reflect what you want to do?

Kind regards

Bernd

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: Timer with sound question

Post by ctflatt » Fri Apr 29, 2011 3:28 pm

Bernd:

Sending a file to you of the app.

If you have time...

:Todd

ps... I am feeling more sophisticated in my abilities these days... still no pro, but trying...

Post Reply