Page 1 of 1
Play wav files via selection
Posted: Mon Feb 08, 2021 11:12 pm
by fhs14647
Dear experts
Is it possible to load all songs in a music folder into a field with name. Then an entry is selected and this song is played in liveCode.
That is what I made up to now for only one song:
Code: Select all
on mouseUp
put specialFolderPath("desktop") into myPath
## all songs are in the folder desktop\sound
put myPath & "\sound\sheeran.wav" into mySound
play audioClip mySound
end mouseUp
Thanks a lot
Mike
Re: Play wav files via selection
Posted: Tue Feb 09, 2021 8:13 am
by richmond62
I wonder which Operating system you are using.
This (LC 9.6.1 / macOS 11.3 Beta 1) did not play anything:
Code: Select all
on mouseUp
put specialFolderPath("desktop") into myPath
put myPath & "\sound\1. Pizdets I Meyk The Hevi Metals_mast.wav" into mySound
play audioClip mySound
end mouseUp

- ATM.jpg (178.45 KiB) Viewed 3582 times
Re: Play wav files via selection
Posted: Tue Feb 09, 2021 9:17 am
by fhs14647
I am using LC indy 9.6.2, os Windows 10 and my solution works fine. But it plays only one certain song ('sheeran.wav'). I want to select the wav file from a textfield, option field or preferably with an os 'open file' dialog.
Thanks a lot
Mike
Re: Play wav files via selection
Posted: Tue Feb 09, 2021 11:15 am
by Klaus
Hi friends,
important facts:
1. internally LC uses the SLASH as a path delimiter on ANY platform!
2. LC only supports UNCOMPRESSED AIF and WAV files and the compressed AU format with the PLAY command.
I want to select the wav file from a textfield, option field or preferably with an os 'open file' dialog.
So you want to click a line in a list field which hoilds all sounds in a folder and player that sound?
OK, set up a list field and fill it with sounds from a folder:
Code: Select all
...
## Ask user to select a folder:
answer folder "Select a folder with sound files!"
put it into tSoundFolder
## Put files in that folder into a variable:
put files(tSoundFolder) into Files
## Only let WAV files get through
filter tFiles with "*.wav"
## Create FULL path to files:
repeat for each line tFile in tFiles
put tSoundFolder & "/" & tFile & CR after tNewFIleList
end repeat
## Delete trailing CR in new list
delete char -1 of tNewFIleList
## Put into field:
put tNewFIleList into fld "your list field here"
...
And the script for your list field:
Code: Select all
on mouseup
put the selectedtext of me into tFileToPlay
## Always check everything
if there is a file tFileToPlay then
play ac tFileToPlay
end if
end mouseup
Hope that helps.
Best
Klaus
Re: Play wav files via selection
Posted: Tue Feb 09, 2021 12:54 pm
by fhs14647
your solution works perfect Klaus! Thanks a lot, it is so a great help!!
Mike

Re: Play wav files via selection
Posted: Sat Jun 05, 2021 12:25 pm
by saltbaytwo
This solution worked for me, thanks a lot.