Sound playback driving me crazy...

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Re: Sound playback driving me crazy...

Post by bn » Tue Apr 05, 2011 4:02 pm

Hi Britt,
So then I can't do callbacks? How do I highlight the words of my storybook app as they are read?
well, I for one don't get the callbacks to work in iOS. You could ask support at runrev.com.

If callbacks don't work in iOS you could do the following (hack/workaround alert)

Take your soundfile in Livecode in the player that has the callbacks set. In your callback handler your could collect the milliseconds from start for each consecutive callback. This gives you a list of the callbacks in milliseconds. You could then in iOS start the sound and at the same time use your list of known milliseconds from start to hilite a word. Like in the send in time examples you were doing. Either you do the difference in the list and issue a "send "hiliteWord 3" to field xy" in xxx milliseconds. I did not test this but it probably would work. Not nice but if your project depends on it you might as well try it.

Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Apr 06, 2011 8:55 pm

After days of struggle and suffering, I have realized that the Standalone Applications Settings > Copy Files only works properly if you copy the files individually. If you just copy the folder that contains the files, you're likely to have the same frustration I've been going through.

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

Re: Sound playback driving me crazy...

Post by bn » Wed Apr 06, 2011 9:48 pm

Hi Britt,
After days of struggle and suffering, I have realized that the Standalone Applications Settings > Copy Files only works properly if you copy the files individually. If you just copy the folder that contains the files, you're likely to have the same frustration I've been going through.
That is not my experience. I successfully copied a couple of files in a folder by just indicating the folder in "Copy Files"

Kind regards

Bernd

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Sound playback driving me crazy...

Post by Dixie » Wed Apr 06, 2011 9:58 pm

Hi Britt..

Bernd's suggestion certainly does work... I have had to use something like this in an animated book.

I have a list of callbacks in a field on each page

10,textColour 1
....
2450,textcolour 12
2650,textcolour 13

I point the value of each line of the callback list to a handler textColour.. Since, you caln't use the player callbacks, just send a message in time (in millisecs) to the handler textColour to do your highlighting...

Code: Select all

on textColour theWord
   set the textColor of word theWord of fld "pageText" to 255,255,255
   set the textColor of word 1 to (theWord -1) of fld "pageText" to 0,0,0
end textColour
hope it helps...

Dixie

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

Re: Sound playback driving me crazy...

Post by ctflatt » Thu Apr 07, 2011 1:00 am

Dixie:

Hi!

This sounds like something I've been trying to figure out, as well.

Do you have a sample stack to share?

:Todd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Thu Apr 07, 2011 9:56 pm

Runrev support is saying you can use player objects in iOS:

Dear Britt Griscom,

Thank you for your request. I'm not sure which callbacks you mean, but yes, you
can use a player object in iOS.

Jacqueline

04/05/2011 13:51 - Britt Griscom wrote:

Hi.

How do I get callbacks to work in iOS? I can't use a player object, can I?

Thanks,

Britt Griscom

Email has been scanned for viruses by Altman Technologies' email management
service




Jacqueline Gay
--
RunRev Support Team
LiveCode – Realize fast, compile-free coding
--

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

Re: Sound playback driving me crazy...

Post by bn » Thu Apr 07, 2011 11:19 pm

Hi Britt,

I tried again with all kinds of variations to get a Livecode player object to play a sound file in iOS and send callbacks. Both failed. I still might do something wrong but I doubt it. As you found out the play pathToSoundFile works. But no way to attach callbacks for me.

Maybe you should have been a bit more specific in your mail to support. Jacque's
I'm not sure which callbacks you mean
lets me doubt she fully understood what you are after.

Maybe you write again and explain that you want to mark text triggered by the callbacks of the player. Then Jacque shurely understands. She is extremely experienced in all things Livecode.
The misunderstanding could be related to the fact that the iOS native player also are called players. I even tried to attach callbacks to a native iOS player, I did not succeed.

However I kind of faked the callbacks in a button:

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put "" into field "fErr"
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      iphonePlaySoundOnChannel tWholePath, 1, now
      send "fakeCallback" to me in 1000 milliseconds
   end if
end mouseUp

on fakeCallback
   put the milliseconds into field "fErr"
   iphoneSoundOnChannel(1)
   if the result <> "" then
      send fakeCallback to me in 1000 milliseconds
   end if
end fakeCallback
put this into the stack I posted before. Make shure there is a field "fErr" on the card and that the sound is included inside the folder as in the script. Or adapt the script for the path.
This shows how to fake a callback by putting the milliseconds into field "fErr" while the sound is playing. Look in the iOS Release Notes for more on the syntax of iphoneSoundOnChannel.

I just whipped this up, it is not "production quality"... But it works.

Kind regards

Bernd

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Sound playback driving me crazy...

Post by Jellicle » Fri Apr 08, 2011 7:10 am

Slightly off topic, but I'm finding that a downloaded mp3 played using the play command stops when the user presses the iPhone sleep button (the one on the top of the device). It restartes when the phone is woken up again, using the same button. Very annoying.
14" MacBook Pro
Former LiveCode developer.
Now recovering.

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

Re: Sound playback driving me crazy...

Post by bn » Fri Apr 08, 2011 9:17 am

Hi Jellicle,
It restartes when the phone is woken up again, using the same button. Very annoying.
That is the way the iPhone works. You put the app to sleep and then you wake it up. The same thing happens withh all apps, they are there when you wake up the the iPhone.
I don't know whether the app gets a suspendStack/resumeStack message when the iPhone is put to sleep, it is worth a try to look whether it does. If so you could stop the sound.

Kind regards

Bernd

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Sound playback driving me crazy...

Post by Jellicle » Fri Apr 08, 2011 9:54 am

Every other app I've tried continues playing when that button is used to turn off the display. Every audio streaming app, every sound app...all of them.

Edit: so to be clear, I want the sound to continue when the user turns off the screen.
Last edited by Jellicle on Sat Apr 09, 2011 1:39 am, edited 1 time in total.
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Fri Apr 08, 2011 1:05 pm

Bernd,

How would you adapt your script for multiple callbacks, each of which took a different amount of time?

Britt

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Sound playback driving me crazy...

Post by Klaus » Sat Apr 09, 2011 12:20 pm

Hi Britt,

just "stack" the "fake callback" "send" messages :D
Create separate handlers for every single "callback" handler*** (Or use the same handler with different parameters) and do this:
*** like here in my example fakecallback1, fakecallback2 etc...

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put "" into field "fErr"
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      iphonePlaySoundOnChannel tWholePath, 1, now
      send "fakeCallback1" to me in 1000 milliseconds
      send "fakeCallback2" to me in 2000 milliseconds
      send "fakeCallback3" to me in 3000 milliseconds
      send "fakeCallback4" to me in 4000 milliseconds
      ## etc, just as you need...
   end if
end mouseUp
Know what I mean?
We need to fire the "callback" messages manually, that's all!


Best

Klaus

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Sun Apr 10, 2011 8:48 am

So the line

Code: Select all

      send "fakeCallback4" to me in 4000 milliseconds
Sends "fakeCallback4" 4000 milliseconds from the beginning of this handler, not 4000 milliseconds from when this line is read?

If so, then I can have my "callbacks" timed from the beginning of my audio file. If not, then I need to find the time difference between each one.

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Sound playback driving me crazy...

Post by Klaus » Sun Apr 10, 2011 11:47 am

Britt,

the "timing" starts in the NAMELY MILLISECOND when the sound is started:
...

## Sound starts here:
iphonePlaySoundOnChannel tWholePath, 1, now

## Now we "send" these messages, so they will get executed in the future "... in X millisecs"
## Of course you will need to supply your own times!
send "fakeCallback1" to me in 1000 milliseconds
send "fakeCallback2" to me in 2000 milliseconds
send "fakeCallback3" to me in 3000 milliseconds
send "fakeCallback4" to me in 4000 milliseconds
...

Remember that "the callbacks" in the desktop version of LiveCode are a list of
handler names and a time (in the movie) when they should get executed.

We are simply mimicking this behaviour manually, know what I mean?


Best

Klaus

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

Re: Sound playback driving me crazy...

Post by bn » Mon Apr 11, 2011 11:52 am

@ Jellicle,

Hi, today I tested the iphonePlaySoundOnChannel syntax on my iPhone. It does what you expect: if you put the app to sleep with the sleep button and the sound is playing and then start the iPhone again the sound plays on.
It just does not work for the simple play command.

something like this:

Code: Select all

if the environment is "mobile" then
      put "" into field "fErr"
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      iphonePlaySoundOnChannel tWholePath, 1, now
end if
Kind regards

Bernd

Post Reply