Player not playing audio when on another card

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
agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Player not playing audio when on another card

Post by agraham147 » Wed Aug 10, 2022 5:41 pm

Hi guys.

I hope you can help me. In my application, I have 10 players each with a wav audio file for a different sound effect, no video. When the players are objects in the current card they play out the audio without issue. However, I've noticed that when I navigate out the card and then come back to card with the players in it, the application takes quite a few seconds to come back to the card.

So to combat this, I thought I could house the players onto another card that can not be accessed by the user (sort of an invisible card). But when I try to play the players now, they don't sound any audio. There is no issues with my code as it's simply:

start player "10" on card "sounds"

Are players not able to be used if they are not objects on the current card?

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by Klaus » Wed Aug 10, 2022 6:11 pm

Hi Aaron,

Code: Select all

start player "10" on card "sounds"
first of all, NEVER EVER name a control with a number in LC!
If you have more than one player on a card LC will think you mean the 10th player on that card!
So name it something like "p10" if you need a number!

And since a player is just a control like e.g. a button, it needs to be on the card where you need it to appear/play!

Do this:
1. Rename you player as mentioned above
2. GROUP that single player and then place that group on all cards where you want the play to play.
3. Do the same for all player objects that you need in your stack.
That will fix your inconvenience.

Best

Klaus

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Player not playing audio when on another card

Post by agraham147 » Wed Aug 10, 2022 6:29 pm

Hi Klaus,

Thank you so much for your quick reply.

However, I don't need the players on any other cards. My reason for putting them on another card was because my application was slowing up by a few seconds whenever I had gone away from the card and then came back to it. The players aren't playing when this happens, it seems it's just the the fact of the players being present on the card.

Do you mean by grouping them that will stop the delay, or was that because you thought I needed them on other cards?

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by Klaus » Wed Aug 10, 2022 6:54 pm

Hi Aaron,

sorry, looks like I misunderstood your problem.

Code: Select all

Do you mean by grouping them that will stop the delay, or was that because you thought I needed them on other cards?
The latter one!
Grouping the player will only make it easier to place the same player object on different cards,
but that is not neccessary in your case.

What platform are you on? Windows?
... because my application was slowing up by a few seconds whenever I had gone away from the card and then came back to it.
So you start the player and you leave the card by NOT going to another card in the stack and the sound just stops?
It should play until the sound is finished of you STOP the player manually or by script.


Best

Klaus

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Player not playing audio when on another card

Post by agraham147 » Wed Aug 10, 2022 7:26 pm

Hi Klaus,

Let me try and explain my issue for you. Each of my sounds are only 1 second long. I have 10 players which are invisible objects as they only play out audio. My application is a snooker scoreboard for Windows. The scoreboard has two separate clocks, one which counts down from 15 minutes to 0, and the other is a shot clock that counts down from 20 seconds to 0.

The 10 sounds are a women's voice saying 1 to 10, so each sound file is 1 second long. So the clock script starts and stops the players, not a mouseUp handler or other user input. Everything currently works fine with the players, that's not the issue.

The issue I'm having now is my scoreboard application has a few more cards (i.e. a menu card and an end of game card when the main clock reaches 0). Now that I have created the players, I have an issue where whenever I go back to the scoreboard card from any other card my application takes 4 to 5 seconds before showing the card, as if the presence of the 10 players are somehow slowing the process.

If I delete the players, the application navigates back to the scoreboard card from another card instantly as it's always done before.

Is there any code to stop this delay from happening or is it unfixable?

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by Klaus » Wed Aug 10, 2022 7:37 pm

Hi Aaron,
Is there any code to stop this delay from happening or is it unfixable?
not sure, hard to say from afar.
But I guess this is the loading time of the players that is causing the delay.
Do you "set the filname of player..." in your card script?

However it sounds like you don't need player in your szenario, imported audio files will probably do here!
So import your sound as control (uncompressed WAV or AIFF of the compressed AU format!) and just: play ac "p10.wav"

Not sure this will fit your app but is at least worh a try.


Best

Klaus

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Player not playing audio when on another card

Post by agraham147 » Wed Aug 10, 2022 8:38 pm

Hi Klaus,

Unfortunately, I've already tried the audioClip method and it slows down my application to the point where the clock becomes inaccurate. The players work perfectly, but unfortunately I have that one issue now.

I will need to play around with different methods. Possibly edit some of the audio files together to reduce the number of players and then implement code to to start and stop the players from certain points.

Thank you for all your help and time Klaus, I very much appreciate it. If you know of any other methods that could possibly help me out then I would be very grateful.

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by Klaus » Wed Aug 10, 2022 8:55 pm

Hi Aaron,
Unfortunately, I've already tried the audioClip method and it slows down my application to the point where the clock becomes inaccurate.
hm, strange but possible...

Please answer these questions:
What platform do you run your app on?
When do you load the files into your players (on opencard?)

I just made a little test, loading a sound and starting a player took always less than 100 millisecs!

Code: Select all

...
set the filename of player 1 to EMPTY
put the millisecs into tMS
set the filename of player 1 to "/Volumes/1TB/Dokumente2/Musik2/Audio diverses/MUSIK etc/goodies_aiff/Buttons/BUTTON12.AIF"
start player 1
put the millisecs - tMS
...
Maybe you can get away with just ONE player object and only setting the filename accordingly?

Best

Klaus

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Player not playing audio when on another card

Post by agraham147 » Thu Aug 11, 2022 2:23 pm

Hi Klaus,

I run my app on Windows. The filenames of the players are set on openStack and then never touched again after that. My main clock only displays minutes and seconds and so I have it update after every second. I have a simple handler called updateClock that just repeats itself after 1 second using the send command. Is there a more efficient way of coding a clock which will stop it from slowing up if I use the audioClip method?

I've already tried your suggested method of the one player and just changing the filename every time I need a new sound, but like I said it slows the clock by half a second or so if I do that way.

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by Klaus » Thu Aug 11, 2022 2:42 pm

Hi Aaron,

sorry, no brilliant ideas in the moment... :(


Best

Klaus

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

Re: Player not playing audio when on another card

Post by Klaus » Thu Aug 11, 2022 2:51 pm

However I could offer to take a look at your stack and play a bit with it if you like!
If yes, send everything to: klaus AT major-k.de

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

Re: Player not playing audio when on another card

Post by jacque » Thu Aug 11, 2022 5:32 pm

I would group the players as Klaus suggested and place them on every card. Right now LC is unloading the sounds when you leave the card and needs to reload when you return, and since you have 10 of them the delay is noticeable. Making them a shared background group should prevent that.

If the players are offscreen or invisible then that's all you need to do. If they're visible then you can hide the group when you leave the card and show it when you return, but it sounds like they aren't visible since they're just sound effects.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Player not playing audio when on another card

Post by agraham147 » Thu Aug 11, 2022 6:21 pm

Hi Jacque,

So you believe that by grouping all the players together and copy and pasting them onto every card of my application, that will prevent the delays. So you are sure that won't cause a delay on navigating to every card? Yes, all the players are invisible as they are just playing out audio.

Thanks,
Aaron

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

Re: Player not playing audio when on another card

Post by jacque » Thu Aug 11, 2022 6:55 pm

No, don't paste the group, that will cause the same problem on every card. Instead, use the Place Group menu item (in the Objects menu) to place an instance on the other cards. This method shares the same instance as the one on the main card and so it should retain the sounds that were already loaded.

If you paste a copy instead, you will be creating new groups that each need to load the sounds independently.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”