Play wav files via selection

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
fhs14647
Posts: 21
Joined: Sat May 16, 2020 11:40 am

Play wav files via selection

Post by fhs14647 » Mon Feb 08, 2021 11:12 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Play wav files via selection

Post by richmond62 » Tue Feb 09, 2021 8:13 am

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
ATM.jpg (178.45 KiB) Viewed 2626 times

fhs14647
Posts: 21
Joined: Sat May 16, 2020 11:40 am

Re: Play wav files via selection

Post by fhs14647 » Tue Feb 09, 2021 9:17 am

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

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

Re: Play wav files via selection

Post by Klaus » Tue Feb 09, 2021 11:15 am

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

fhs14647
Posts: 21
Joined: Sat May 16, 2020 11:40 am

Re: Play wav files via selection

Post by fhs14647 » Tue Feb 09, 2021 12:54 pm

your solution works perfect Klaus! Thanks a lot, it is so a great help!!
Mike

:D :D

saltbaytwo
Posts: 1
Joined: Sat Jun 05, 2021 9:42 am

Re: Play wav files via selection

Post by saltbaytwo » Sat Jun 05, 2021 12:25 pm

This solution worked for me, thanks a lot.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”