iOS audio help

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

iOS audio help

Post by MxDx » Mon Apr 17, 2023 3:11 am

I am using on currentTimeChanged theInterval to sync graphic objects in my app with the playback location of an audio file.
The player object is used for audio playback on Mac OS.
I need to implement this same functionality for the iOS platform.

I'm looking at mergAVPlayerCreate & mergAVPlayerCreatePeriodicTimeObserver to handle this.
#1 Is this the best way to implement it?
I'm still new to LC - the docs on these functions leaves me scratching my head.
#2 Are there any example files I might find somewhere. ( I've yet to find anything)

This is what I have so far - but it doesn't work. ( the path checks out)

Code: Select all

-- Path to the audio file
   put specialFolderPath("engine") & "/Audio Files/myMP3File" into tFilePath   -- myMP3File is a placeholder.
   
   --   -- Create a new AVPlayer object
   put mergAVPlayerCreate("avPlayer", ) into tPlayerID
   
   -- Set the file path for the player
   set the fileName of player tPlayerID to tFilePath
   
   --   -- Start playing the audio file
   play player tPlayerID[/indent]
Thanks in advance

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sat Apr 29, 2023 12:09 am

Wow 300 views and not one tip.
I guess mergAV isn't used much in LC.

Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

Re: iOS audio help

Post by Emily-Elizabeth » Sat Apr 29, 2023 2:06 am

MxDx wrote:
Mon Apr 17, 2023 3:11 am

Code: Select all

   put mergAVPlayerCreate("avPlayer", ) into tPlayerID
What is "avPlayer" ?

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sat Apr 29, 2023 2:41 am

Emily-Elizabeth wrote:
Sat Apr 29, 2023 2:06 am
MxDx wrote:
Mon Apr 17, 2023 3:11 am

Code: Select all

   put mergAVPlayerCreate("avPlayer", ) into tPlayerID
What is "avPlayer" ?
Good question.
The LC documentation advertises the first argument to be - a pointer to an asset in memory?
I really don't understand asset in memory.

So I thought mergAVPlayerCreate("avPlayer", ) would create a player named avPlayer.
But now that I look at it, that doesn't make sense.
Maybe the asset is an audio file in my projects assets folder?
then I would suspect I don't need
-- Set the file path for the player
set the fileName of player tPlayerID to tFilePath
Well I have something to test.
Thanks for your response.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: iOS audio help

Post by jacque » Sat Apr 29, 2023 5:50 pm

Why not use a standard player control? It works on all platforms.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sat Apr 29, 2023 9:49 pm

According to the LC docs
OS - mac, windows, linux
Platforms - desktop, server

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sat Apr 29, 2023 9:52 pm

jacque wrote:
Sat Apr 29, 2023 5:50 pm
Why not use a standard player control? It works on all platforms.
The Player object function > currentTimeChanged doesn't work on iOS.
On the desktop I use this function to sync a graphic on the screen with the audio track.
So on mobile I would have to keep checking the audio track position with a loop or something which is my last resort.
mergAV has a mergAVPlayerCreatePeriodicTimeObserver fuction that would handle this.
I'm banging away on this with the help of GPT-4 ..ha ha

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: iOS audio help

Post by jacque » Sat Apr 29, 2023 10:52 pm

The player control does work on all platforms, but you're right that currentTimeChanged is only listed for desktop and server. You wouldn't have to loop though, LC sends a message every time the frame changes so all you'd need to do is write a handler to catch that message. If the current time is a key point that you've designated, then your handler can take action.

It's moot though if you're building for iOS. One other thing: I used callbacks in a project, which is similar to currentTimeChanged, to key audio to successive field text updates. It worked well on my machine and my client's, but when the app was used on slower or older machines it failed miserably. We didn't realize it for some time, but once we tested it, the delay was bad enough that we removed the feature entirely.

I agree that the mergAV documentation is pretty obscure. I don't quite understand it either.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sat Apr 29, 2023 11:24 pm

jacque wrote:
Sat Apr 29, 2023 10:52 pm
LC sends a message every time the frame changes
How do I grab that message?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: iOS audio help

Post by jacque » Sun Apr 30, 2023 6:48 am

MxDx wrote:
Sat Apr 29, 2023 11:24 pm
jacque wrote:
Sat Apr 29, 2023 10:52 pm
LC sends a message every time the frame changes
How do I grab that message?
It's in the dictionary:

Code: Select all

on currentTimeChanged theInterval -- display the time in a field
  put theInterval into field "Time Code"
end currentTimeChanged
The contents of the handler would be whatever you want to do about the player's current time (the interval.) I think you'll get this message many times per second, so you'd want to designate certain intervals where the handler would act.

But if you are building for iOS then a player control won't work. But the "mobileControlCreate" command does work to create players on mobile. That's a bit more scripting though, since you have to create, manage, and delete the player instance in script. See the "mobileControlCreate" command in the dictionary. You can also use mobileControlGet to get the currentTime of the mobile player, but in this case you're right that you'd need to loop every second or two to see where the player is at. There's no automatic messaging that I know of, like there is for the desktop control.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MxDx
Posts: 9
Joined: Mon Apr 17, 2023 2:49 am

Re: iOS audio help

Post by MxDx » Sun Apr 30, 2023 2:51 pm

jacque wrote:
Sun Apr 30, 2023 6:48 am
MxDx wrote:
Sat Apr 29, 2023 11:24 pm
jacque wrote:
Sat Apr 29, 2023 10:52 pm
LC sends a message every time the frame changes
How do I grab that message?
It's in the dictionary:

Code: Select all

on currentTimeChanged theInterval -- display the time in a field
  put theInterval into field "Time Code"
end currentTimeChanged
I guess I wasn't clear enough in my first post that I have already implemented the Mac OS version of my app using currentTimeChanged.
But thanks for your reply.

I ended up going a different route then using the mergAV functions. Not as slick as I would like but it works.

Post Reply

Return to “iOS Deployment”