I’m a newbie and learning how to use sound component. I made a simple app that has 2 buttons showing a cat and a dog, and a sound component. I want to make it play a cat mp3 file when the cat button is clicked, play a dog mp3 file when the dog button is clicked.
But when the app is started, no sound is played during the first click. Then when I clicked the cat button the 2nd time, cat mp3 file was played as expected. But then when I clicked the dog button, the cat mp3 file was played again. If I clicked dog button again, the dog mp3 file will play this time.
I think I might use the sound component wrongly. Somebody please help!
With your code, the 2 buttons can trigger corresponding sound files only if I click the buttons alternatively. If I click any of the buttons consecutively, only the first time will play the correct sound file, then no matter how many times I click the same button no sound is played.
The use of sound component really confuses me. Originally I tried with only one button and used a listviewer to select the 2 animals. I changed both the picture of button and sound source after an item in listviewer was clicked. But sound played immediately after item in listviewer was picked, without waiting for me to click the picture-button. That’s why I removed the listviewer to try the more straightforward approach I showed in the first post.
Your use of “on source loaded” gave me a hint, so I added some waiting time before playing. Then it works now.
But I still not sure why this happens. Is it because it needs time to load the sound file? But the sound files are assets added into the app, why do they need time to load? Originally I thought “on source loaded” is for files in URL, so there will be time lag before the app getting the sound file. But this case makes me wonder whether my concept is correct.
Evidently, the file needs time.
The .mp3 files can greatly vary in size, and having them as asset simply means that they are packaged with the app, not that they can dispense with the loading. The point is that sound player is only an interface to the device sound player, i.e. the component that actually drives the speaker is part of the operating system, NOT part of your application. Passing that file across has to take some time, particularly since modern portable devices tend to have multiple core CPU. The loading of the file could therefore be handled by one core, while the request to start playing the sound may be done by a different core, which will not even have noticed that the file to play was changed.
Thank you! Your code is certainly much much better than mine.
Actually I DO have concern about setting the waiting time too short and still not get the sound file loaded, if the system runs too slow.
In Thunkable Classic, I did not need to consider the problem of whether sound file has been loaded when the sound is played. So the coding is simpler. I wonder whether this is an enhanced function (though I cannot see any insufficiency in Thunkable Classic) or a problem that may be handled automatically (like Thunkable Classic) in future development?
Thunkable X has done a lot differently than Classic. I think that in Thunkable X, the Play component is performed in an asynchronous manner. That is, you can download a large mp3 and simultaneously perform other operations. You can check it if you wish.
Hi Thunkers, I have a list of songs on the firebase storage. Im a newbie to programming. How can I link a button to play 1 of the songs on the data base.
After your sound1.play add a line to set the source for sound1 to a blank string. If you do this, then you can hit the button as many times as you want and it will play it each time.
Olá pode me ajudar a adicionar um som. coloquei uma imagem de uma maquina fotografica ao clicar na imagem abre a camera e a foto e tirada e lançada em outro campo de imagem, eu gostaria que o usuário ao clicar na camera, fosse emitido um som de click igual de um botão