player looping problem

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

player looping problem

Post by jrioux » Mon Jun 27, 2011 2:36 am

My app fades individual tracks of multi-track Quicktime audio (no video) in and out on cue using a player object and the Enhanced Quicktime external. Works like a dream.

There is a glitch, though, in that the music is supposed to loop cleanly at the end and begin (on the starting note) again. Instead, there is an annoying pause/interval/noise before it starts up again.

I've tried extending the audio segments manually (making multiple sequential copies within each track), but that's just putting off the inevitable--eventually, it gets to the end and there is, once again, the annoying sound before playback begins again.

Is this a Quicktime thing? A Livecode thing?

Howlernator
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Wed Oct 13, 2010 4:44 am

Re: player looping problem

Post by Howlernator » Mon Jun 27, 2011 4:18 am

I'm yet to test it, but apparently the 'seamlessLoop' command in Enhanced QT helps with this.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: player looping problem

Post by jrioux » Mon Jun 27, 2011 8:26 pm

Howlernator wrote:I'm yet to test it, but apparently the 'seamlessLoop' command in Enhanced QT helps with this.
No good. I expect it simply sets playLooping, much as one might do in the IDE.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: player looping problem

Post by jrioux » Mon Jun 27, 2011 8:27 pm

Make that simply "looping" in my last.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: player looping problem

Post by Klaus » Mon Jun 27, 2011 8:55 pm

Please try it, the result might differ from your exspectations! 8)

I don't know the techs behind this, but this is not like the "looping" in LiveCode,
as Trevor, who developed that external, once told me! :D


Best

Klaus

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: player looping problem

Post by admin12 » Mon Jun 27, 2011 10:30 pm

Let us know how things go - this is definitely something I will need to use soon. Seamless looping is a necessity in what I am about to undertake.

Mike

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: player looping problem

Post by jrioux » Tue Jun 28, 2011 9:29 pm

admin12 wrote:Let us know how things go - this is definitely something I will need to use soon. Seamless looping is a necessity in what I am about to undertake.

Mike
@ Klaus, the "no good" was the result of my trying it in the app. What followed was my speculation as to why it didn't work. I'm glad to hear that it differs from setting "looping" in the IDE, but the result, alas, was the same.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: player looping problem

Post by jrioux » Tue Jun 28, 2011 9:51 pm

By the way, I also tried looping the tracks in uncompressed format. Though less pronounced, there's still an audible "glitch" at the loop point (not only that, but the audio file is much larger than before, not surprisingly).

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: player looping problem

Post by admin12 » Wed Jun 29, 2011 1:27 am

I wonder if using (and buying) Franklin audio would solve the looping problem?

Mike

ThatOneGuy
Posts: 77
Joined: Fri Jan 04, 2013 9:57 am

Re: player looping problem

Post by ThatOneGuy » Mon Sep 22, 2014 6:52 am

I apologize for reviving a very old thread, but this problem has yet to be solved.
The player still pauses for a small time before restarting the loop even with uncompressed audio.

I've tried to work around this and have made a command that mimics seamless looping, but it isn't very efficient.
It would be much better if "loop" doesn't pause before restarting. It may just be a problem with QT, however.

Here's my attempt at a solution:

Code: Select all

local allowLooping

command stopLoop playerName
   // Stop looping player
   put false into allowLooping
   
   // Pause associated players
   set the paused of player playerName to true
   if there is a player (playerName && "copy") then set the paused of player (playerName  && "copy") to true
end stopLoop


command seamlessLoop playerName loopCount
   local clonedPlayer, loopPoint
   put true into allowLooping
   
   // Create and hide a duplicate player
   lock screen
   if there is a player (playerName && "copy") then delete player (playerName && "copy")
   clone player playerName
   set the name of it to playerName && "copy"
   put playerName && "copy" into clonedPlayer
   hide player clonedPlayer
   unlock screen
   
   // Remove native looping if applied
   set the looping of player playerName to false
   set the looping of player clonedPlayer to false
   
   // Change from 290 if not perfectly seamless
   put the duration of player playerName - 290 into loopPoint
   
   if loopCount <= 0 then
      repeat while allowLooping
         set the currenttime of player playerName to 0
         set the paused of player playerName to false
         wait while the currentTime of player playerName < loopPoint with messages
         set the currenttime of player clonedPlayer to 0
         set the paused of player clonedPlayer to false
         wait while the currentTime of player clonedPlayer < loopPoint with messages
      end repeat
   else
      repeat loopCount times
         set the currenttime of player playerName to 0
         set the paused of player playerName to false
         wait while the currentTime of player playerName < loopPoint with messages
         set the currenttime of player clonedPlayer to 0
         set the paused of player clonedPlayer to false
         wait while the currentTime of player clonedPlayer < loopPoint with messages
      end repeat
   end if
   
   // Clean up duplicates
   delete player clonedPlayer
end seamlessLoop
I made one function that can be passed as a message with the name of the player to loop and the number of times to loop it. Anything zero or less loops forever.
The other function is passed the same name and stops the infinite loop and pauses the looping sound.

If anyone has a better solution (not including externals) I'd be happy to hear of it.

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

Re: player looping problem

Post by jacque » Mon Sep 22, 2014 9:58 pm

I think some of the problem is that you're running it all from a single handler which involves lots of waiting, and also tried to calculate the time interval to wait (which can only be approximate, given how computers work.) You might get better results if you rely on native engine messages rather than trying to implement your own event loop.

I would create two players and leave them on the card permanently, there's no reason to create and delete them. Hide them both if you want. Then the basic idea is to preload them both with the same file and start the first one playing. Create a playStopped handler which will trigger when the active player finishes. When you get a playStopped message, immediately start the second player. When that one finishes, start up the first one again, and so forth. You can tell which player stopped by checking the target.

Code: Select all

on playStopped
 if there is no player "firstPlayer" then exit playStopped -- user changed cards
 if the short name of the target contains "firstPlayer" then
  start player "secondPlayer"
 else
  start player "firstPlayer"
 end if
end playStopped
You'll want to add your toggle flag too, so that you can exit if the looping is turned off. I'm not sure this will give you perfectly seamless playback but if your sound loops have no silence at the end then it should be pretty close.

I see that your handler doesn't always want to play through to the end (it subtracts 290 from the duration.) For those situations you can set a callback on the player that calls "playStopped" at that point in the playback. See the callbacks property in the dictionary. I've used those and they work well. You'll need to adjust the playStopped handler to stop the current player before or just after the second one starts to play back.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: player looping problem

Post by okk » Wed May 20, 2020 1:21 pm

Hi,
and 6 years later the original issue remains. I can't get seamless looping working out of the box on LC 9.5 on MacOSX 10.12.6 I noticed that even Quicktime player doesn't create a seamless loop, so I guess the problem is passed from AV foundation to livecode. But this is just guessing. I attach a stack that uses the two player method and callbacks to create a seamless loop, compared to the out of box looping. On my system I can hear a clear difference betwen the two methods. The question remains though will this be seamless on different systems and devices?

Does anyone has experience with looping of audio tracks on mobile devices, can they handle seamless looping out of the box?

Thanks!
Oliver
Attachments
seamless_loop.zip
(109.81 KiB) Downloaded 163 times

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

Re: player looping problem

Post by jacque » Wed May 20, 2020 4:13 pm

An audio guy told me once that mp3 files are impossible to loop, there is always a break at the end. I don't know what file format you use, or which one would work, but if you're using mp3 the problem is innate to the file format.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: player looping problem

Post by capellan » Wed May 20, 2020 11:54 pm


okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: player looping problem

Post by okk » Thu May 21, 2020 12:09 am

Hi Jacque, thanks for responding to this super old thread. It just became an important topic to me, since I develop an app with gps triggered audio loops. In order for it to work properly a seamlees looping is essential.

In response to your post I would say: do not trust "an audio guy". I tried it with wav, aiff, and any format the player can play. There is no difference in the behaviour. But he behaviour happens already in Quicktime Player, so we can't blame Livecode - at least this time ;). I use the same files in Ableton Live or Maschine 2 - of course they are dedicated audio programs - but there is no issue with looping, also with mp3 format. The looping is precise to the millisecond. So it is defintely possible. And as my stack demonstrated it, there is a way to "fake" seamless looping. Why the player could not do this out of the box?

Best
Oliver

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”