Player won't stop playing file, with 'wait' seconds
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Player won't stop playing file, with 'wait' seconds
I'm creating an LC program which allows me to listen to a sequence of songs or podcasts in a folder, and when I hear an audio file playing that I wish to save as a favorite, I can click a button to have it moved into a separate folder of favorites. I usually know within the first 20 seconds of play whether I want to save it as a favorite.
The user can select the number of seconds to play before moving on to the next audio file. Occasionally, I want to skip the current song playing prior to chosen the chosen length of play and immediately begin playing the next song.
The problem I'm having with my LC scripts is that I cannot get it to skip to the next tune without playing the full chosen length. My 'stop' or 'skip' button is disabled by the player object unless I use the statement "wait gPlaySeconds seconds with messages". Although the "wait" statement does enable a button with stop or pause scripts, the audio file continues playing to the end of the chosen 'wait' length, such as 20 seconds, before going on to the next audio file.
Play button script, excerpt—
start player "tPlayer"
wait gPlaySeconds seconds with messages
Skip/Stop button script—
stop player "tPlayer"
exit to top
The user can select the number of seconds to play before moving on to the next audio file. Occasionally, I want to skip the current song playing prior to chosen the chosen length of play and immediately begin playing the next song.
The problem I'm having with my LC scripts is that I cannot get it to skip to the next tune without playing the full chosen length. My 'stop' or 'skip' button is disabled by the player object unless I use the statement "wait gPlaySeconds seconds with messages". Although the "wait" statement does enable a button with stop or pause scripts, the audio file continues playing to the end of the chosen 'wait' length, such as 20 seconds, before going on to the next audio file.
Play button script, excerpt—
start player "tPlayer"
wait gPlaySeconds seconds with messages
Skip/Stop button script—
stop player "tPlayer"
exit to top
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Player won't stop playing file, with 'wait' seconds
Try
Code: Select all
without waiting
Re: Player won't stop playing file, with 'wait' seconds
Thanks, but "without waiting" only works with the move and send to program commands according to the LC Dictionary. In this case I'm dealing with an audio player.
Re: Player won't stop playing file, with 'wait' seconds
Simply put, is there a way to Stop or Pause and then Resume an audio player (not an audioclip) using a standard LC 'button'? It seems I must use the "wait x seconds with messages" to enable the stop/pause/play/resume buttons—otherwise the user interface buttons are deliberately frozen; it's not asynchronous. My LC program plays a list of audio files in a folder. With the "wait x seconds with messages" the audio continues playing until the x seconds have been reached, then continues with the next audio file in the folder. I cannot immediately stop the audio playing nor resume.
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Player won't stop playing file, with 'wait' seconds
Maybe I'm a bit stupid, but over "here" on Mac OS 11.5 beta 1 . . .
- -
Button "STOP":
Button "RESUME":
Everything works rather nicely.
- -
Button "STOP":
Code: Select all
on mouseUp
stop player "MOOZIK"
end mouseUp
Code: Select all
on mouseUp
start player "MOOZIK"
end mouseUp
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Player won't stop playing file, with 'wait' seconds
Of course if you want to control things via the keyboard it is time to start
getting into rawKeyUp . . .
-
- Livecode Opensource Backer
- Posts: 9762
- Joined: Fri Feb 19, 2010 10:17 am
Re: Player won't stop playing file, with 'wait' seconds
On my (antiquated) Apple keyboard the volume control keys 'talk' directly to the Macintosh system
and LiveCode is unable to trap any key signals from them.
- Attachments
-
- KK.livecode.zip
- Here's the stack.
- (929 Bytes) Downloaded 284 times
Re: Player won't stop playing file, with 'wait' seconds
Avoid "wait" and do this in the button script:smelly wrote: ↑Sun Jan 10, 2021 12:29 amThe problem I'm having with my LC scripts is that I cannot get it to skip to the next tune without playing the full chosen length. My 'stop' or 'skip' button is disabled by the player object unless I use the statement "wait gPlaySeconds seconds with messages". Although the "wait" statement does enable a button with stop or pause scripts, the audio file continues playing to the end of the chosen 'wait' length, such as 20 seconds, before going on to the next audio file.
Code: Select all
on mouseUp
start player tPlayer
send "stopPlayer" to me in 20 seconds
end mouseUp
on stopPlayer
stop player tPlayer
end stopPlayer
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Player won't stop playing file, with 'wait' seconds
jacque: Thanks for the help. Although your sample code works well with a simple audio player which I coded using your example, it doesn't work with a far more complex stack like mine, where I play a sequence of tunes loaded into a field from a list of files on the hard drive, for a specified length, e.g. 10 seconds, but want to be able to stop, pause, continue to the next tune, et al.
When I begin playing the tunes all the buttons on the card are disabled until it has finished the 10 seconds of play and then automatically begins the next tune in a repeat loop. As I understand from the LC Dictionary this is normal unless code similar to "wait 10 seconds with messages" is used. With my stack the tune waits for the 10 seconds to complete and then goes on to play the next tune. I can stop the play using wait 10 seconds with messages because the stop button is then enabled, not blocked, but then I hear dead silence for the remainder of time until the 10 seconds has elapsed. If I set the length to 30 seconds and stop the play at 10 seconds I have to wait another 20 seconds to hear the next tune. I want to skip to the next tune immediately when I click the stop or continue or whatever button. I also want to use pause to actually pause the play and continue from where I paused by clicking another button. All that functionality seems to require the wait seconds with messages or else all the buttons on the card are disabled.
I guess it just boils down to me figuring out the proper algorithm, now that I can enable the card buttons by using that 'wait seconds with messages' command. Such are the limitations of using a programming language that has little or no concurrent (multithreaded) functionality.
When I begin playing the tunes all the buttons on the card are disabled until it has finished the 10 seconds of play and then automatically begins the next tune in a repeat loop. As I understand from the LC Dictionary this is normal unless code similar to "wait 10 seconds with messages" is used. With my stack the tune waits for the 10 seconds to complete and then goes on to play the next tune. I can stop the play using wait 10 seconds with messages because the stop button is then enabled, not blocked, but then I hear dead silence for the remainder of time until the 10 seconds has elapsed. If I set the length to 30 seconds and stop the play at 10 seconds I have to wait another 20 seconds to hear the next tune. I want to skip to the next tune immediately when I click the stop or continue or whatever button. I also want to use pause to actually pause the play and continue from where I paused by clicking another button. All that functionality seems to require the wait seconds with messages or else all the buttons on the card are disabled.
I guess it just boils down to me figuring out the proper algorithm, now that I can enable the card buttons by using that 'wait seconds with messages' command. Such are the limitations of using a programming language that has little or no concurrent (multithreaded) functionality.
Re: Player won't stop playing file, with 'wait' seconds
Using wait inside a repeat loop isn't efficient or reliable; sending a message is LC's way of emulating multithreading and is the best way to go. When you say the buttons are disabled, do you mean buttons you've placed on the card or do you mean the player controller is disabled? The latter shouldn't happen so I assume you're using card buttons. I wonder why you disable the buttons at all?
When I get back to my computer I'll give you a sample script. You can do what you need using the send command, it's just a modification of the short example I posted.
Meanwhile, let me know what buttons you have on the card and what they do.
When I get back to my computer I'll give you a sample script. You can do what you need using the send command, it's just a modification of the short example I posted.
Meanwhile, let me know what buttons you have on the card and what they do.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Player won't stop playing file, with 'wait' seconds
Here is a skeletal outline of the basics you described. I have four buttons: Play Next, Pause, Resume, Stop. I do not disable any of them. The primary working handler is in the card script:
The four buttons have these simple scripts:
If you want to be able to click on a line in the list to play a particular song, put this in the list field:
This doesn't trigger the "Play Next" handler so if you want that, you'll either need to click the Play Next button, or let the song play through to the end, or revise the script.
Code: Select all
constant kPlaySecs = 10 -- default number of seconds to play
on playNext
stop player 1
put line lineoffset(the filename of player 1,fld "playList") + 1 of fld "playList" into tNextFile
if tNextFile = "" then exit playNext
set the filename of player 1 to tNextFile
send "playNext" to me in kPlaySecs seconds
start player 1
end playNext
on playStopped
if the currentTime of player 1 = the duration of player 1 then -- song has ended
playNext
end if
end playStopped
Code: Select all
Button Play Next:
on mouseUp
playNext
end mouseUp
Button Pause:
on mouseUp
stop player 1
end mouseUp
Button Resume:
on mouseUp
start player 1
end mouseUp
Button Stop (stops all automatic playback):
on mouseUp
stop player 1
repeat for each line l in the pendingMessages -- remove any pending messages that would trigger the next song
if l contains "playNext" then cancel item 1 of l
end repeat
set the filename of player 1 to empty
end mouseUp
Code: Select all
on mouseUp
set the filename of player 1 to the text of the clickline
start player 1
end mouseUp
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 670
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Player won't stop playing file, with 'wait' seconds
You're probably going to want to flush the pendingMessages queue so none of the callback check loop messages wind up overlapping.
Should take look at flushEvents() in the LC dictionary too, particularly like if using keyDown / arrowKeys to jump between playback tracks.
Should take look at flushEvents() in the LC dictionary too, particularly like if using keyDown / arrowKeys to jump between playback tracks.