Player repeat loop

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
oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

Player repeat loop

Post by oldummy » Thu Jan 25, 2024 11:34 am

I have a list field with music files in it.
I have a button with the following script that I want to start the player at line 1 and play everything in the field one at a time for it's complete duration.
Whenever I click the button, only the last line in the list plays. What am I neglecting this time?


on mouseup
repeat for each line theline in fld "playlist"
set the filename of player "myplayer" to theline
start player "myplayer"
wait until the sound is done -- seems like this would be correct
end repeat
end mouseup

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

Re: Player repeat loop

Post by Klaus » Thu Jan 25, 2024 11:43 am

Hi oldummy,

this line

Code: Select all

wait until the sound is done
will only work with sounds started with the "play audioclip xyz" command, but NOT with player objects!
You could add a "on playstopped" handler to your card with the player and set the filename to the next
line in your field.

Know what I mean?

Best

Klaus

P.S.
Please use the CODE tags after pasting your script here!

Code: Select all

on mouseup
  repeat for each line theline in fld "playlist"
    set the filename of player "myplayer" to theline
    start player "myplayer"
    wait until the sound is done -- seems like this would be correct
  end repeat
end mouseup
8)

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Player repeat loop

Post by jmk_phd » Thu Jan 25, 2024 4:06 pm

Hi oldummy --

Last spring I built a LiveCode stack that creates a playlist from my archive of .mp3 music files stored on disk. Although perhaps a bit more elaborate than what you need -- in my case, the stumbling block was employing callbacks with a player object to advance a progress bar, which the incredible folks here on the forums helped me to solve -- I believe that it accomplishes you are trying to do.

At the time I uploaded a working version of that stack to the forum. You can still find it there:

https://forums.livecode.com/viewtopic.p ... 75#p222307

I've since removed from my server the set of short .mp3 files mentioned in that post, but I'm sure you have your own that you can use to test this out. The scripts include detailed comments, so hopefully you can locate in the code the routines that are most relevant to what you are trying to achieve.

Best wishes,

jeff k

oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

Re: Player repeat loop

Post by oldummy » Sat Jan 27, 2024 10:37 am

I thank you both for the your help with this. And I really appreciate your album stack jmk. I'm afraid it was a little too far over my head at this time, but I intend to use it to learn about callbacks, as I know nothing about them yet.
I did use KI did use klaus's suggestion and went with the playstopped method. It works until I find a way to break it.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”