Callbacks for android/ios audio [RE-OPEN]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Voyd
Posts: 13
Joined: Thu Mar 10, 2016 8:11 pm

Callbacks for android/ios audio [RE-OPEN]

Post by Voyd » Thu Mar 10, 2016 9:37 pm

Hi all,
Quite new and I've searched but unable to come up with a solution.
I understand that callbacks work on livecode with qt player but the qt player is not on android.
I'm able to get audio working on a android tablet with a simple "play audioclip "wavFile"" but don't know if there is a way to add callbacks to mobilePlaySoundOnChannel.
If there is a way to do that could someone point me in the right direction or:
I was thinking to get the duration of the sound file and do a countdown or countup. I've already got my callbacks with timing in ticks (i think) from the qt player in livecode.
If that is possible how do I achieve this?

The audio is packed with the app and accessed with specialFolderPath("engine").

Thank you


Sheldon
Last edited by Voyd on Wed Apr 06, 2016 9:24 pm, edited 2 times in total.

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

Re: Callbacks for android/ios audio

Post by Klaus » Thu Mar 10, 2016 10:10 pm

Hi Sheldon,

1. welcome to the forum! :D

2. Yes, callbacks are not supproted except with QT on desktop machines, but you can use "send xx in yyy"
Do something like this:
...
mobilePlaySoundOnChannel your_soundfile, your_channel, whatever_type
send "yourCallbackMessage1" to me*** in xxx ticks
# *** or "...to this cd # or stack", or wherever you put your callback handlers
send "yourCallbackMessage2" to me*** in yyy ticks
# etc.
...
You get the picture! :D

Check "send" in the dictionary to see how you can cancel the message later, if neccessary.


Best

Klaus

Voyd
Posts: 13
Joined: Thu Mar 10, 2016 8:11 pm

Re: Callbacks for android/ios audio

Post by Voyd » Thu Mar 10, 2016 10:38 pm

Hi Klaus,
Thank you for the welcome, glad to be a part of it :D

Yeah I'm starting to get the picture.

so all that will be inside the mouseUp for example is:

on moustUp
mobilePlaySoundOnChannel wavFile, storyChan, now
send "showText 11" to me in 400 ticks
send "showText 12" to me in 400 ticks
end mouseUp

and if I'm understanding correctly me* can be replaced by card or stack that holds the handler?

Thank you


Sheldon

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

Re: Callbacks for android/ios audio

Post by Klaus » Thu Mar 10, 2016 10:52 pm

Hi Sheldon,
Voyd wrote:

Code: Select all

on moustUp
  mobilePlaySoundOnChannel wavFile, storyChan, now
  send "showText 11" to me in 400 ticks
  send "showText 12" to me in 400 ticks
end mouseUp
since we are sending the NAME of a handler, this must be ONE word like
...
send "showtext11" to xxx
...
Voyd wrote:...and if I'm understanding correctly me* can be replaced by card or stack that holds the handler?
Exactly!


Best

Klaus

Voyd
Posts: 13
Joined: Thu Mar 10, 2016 8:11 pm

Re: Callbacks for android/ios audio

Post by Voyd » Thu Mar 10, 2016 11:18 pm

Hi Klaus,

The numbers are parameters for the line number that i want the text to read from.
All works fine, with one problem, the timing is off, i thought it was ticks that i noted from QT but that's too slow then tried to do milliseconds that's too fast.
Do you have any idea what timing or conversion I should use?
or do I need to manually and painfully write the times again :( :( ?

Also is it necessary to import file and copy file or can i just copy file?

Edit: Found solution for the time. Found out that the numbers in QT callbacks are frames and its 600 frame so i did frameNumber/600 seconds, so now my callbacks are in sync.

Also importing the audio as Control is not needed when you copy files in and use in specialFolderPath("engine").


Thank you


Sheldon

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

Re: Callbacks for android/ios audio [SOLVED]

Post by Klaus » Sat Mar 12, 2016 2:59 pm

Hi Sheldon,

Yes, sorry, sure the numbers are parameters to your handlers!

And yes, QT uses its own timescale, check "the timescale" of a player = QT units per second.
"Most" of the time this is 600 but can differ from movie to movie!

And for crossplatform reasons get used to use -> specialfolderpath("resources")!
That is where files end after using "Copy files" in the standalone builder settings.
On mobile it is the same as -> specialfolderpath("engine"), nevertheless :D

Imported audio and video don't even work on the mobile platform, so using external
files is the way to go!


Best

Klaus

Voyd
Posts: 13
Joined: Thu Mar 10, 2016 8:11 pm

Re: Callbacks for android/ios audio [SOLVED]

Post by Voyd » Sat Mar 12, 2016 4:52 pm

Thank you Klaus, just need help with my other question. If you could can you help with that as well please.
http://forums.livecode.com/viewtopic.php?f=7&t=26784


Thanks you


Sheldon

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Callbacks for android/ios audio [SOLVED]

Post by jacque » Sat Mar 12, 2016 5:49 pm

Klaus wrote:And for crossplatform reasons get used to use -> specialfolderpath("resources")!
That is where files end after using "Copy files" in the standalone builder settings.
On mobile it is the same as -> specialfolderpath("engine"), nevertheless :D
Actually, iOS changed the rules recently and no resource files are allowed in the engine folder any more. That's why LC added the special resources folder to the language. The LC engine will try to translate engine folder references to the new one, but you're right we should just use the new resources folder to start with.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Voyd
Posts: 13
Joined: Thu Mar 10, 2016 8:11 pm

Re: Callbacks for android/ios audio [RE-OPEN]

Post by Voyd » Wed Apr 06, 2016 9:30 pm

Hi Klaus,

Sorry to reopen back this problem, but testing it after I moved on I realize when I pause the mobile audio those messages are still being sent. so when i pres play again the new message queue and the old one is running. is there a way for when I stop and pause the audio to pause and stop the messages being sent. I dont know if you can pause or stop a handler. I tried exit handler but that came up with an error. I assume you can only exit the handler your in.

thank you


Sheldon

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

Re: Callbacks for android/ios audio [RE-OPEN]

Post by Klaus » Thu Apr 07, 2016 9:48 am

Hi Sheldon,

yes, playing audio and sending a message are two different actions and
we only created a "virtual" context between them here!

I am afraid in that case you need to:
1. Cancel the message IDs. Check the dictionary for more info about "send" and the message ids it will return in "the result".
2. Subtract the time the sound had been playing so far from the virtual "callback" times and then
3. when re-starting the audio, "send" the messages in hte new computed time again.
You get the picture.


Best

Klaus

Post Reply