I have sound files (WAV) that I have included by dragging in a folder named ‘Sounds’ into the IDE. So there is now a folder named Sounds that has those WAV files. What I would like to do is add the name of each WAV sound file into a PopUp so I could select that sound to be played when a timer ends.
Cycle through the folder inside Special.ApplicationData and add the FileName (without extension) to the popup menu and add the NativePath as the RowTag. When the popup SelectionChanged Event fires, read the RowTag into a FolderItem, then Play the sound.
Var f As FolderItem
f = SpecialFolder.ApplicationData
If f <> Nil Then
MessageBox(f.NativePath)
Sound_CB.RemoveAllRows
For Each file As FolderItem In f.Children
If file = Nil Then
// inaccessible
Return
End If
Var filename(-1) As String = file.Name.Split(".")
Sound_CB.AddRow filename(0)
Sound_CB.RowTagAt(Sound_CB.LastAddedRowIndex) = file.NativePath
Next
Else
MessageBox("There is no Application Data Sounds folder on this computer.")
End If
When completed there is a list of files (In my instance on a MAC) of items however none of them are the sound files I have in a folder in the Contents area of the IDE named ‘Sounds’
I have modified to add XOJO to see if there is anything in there and nothing is visible.
f = SpecialFolder.ApplicationData.Child("XOJO")
Not certain where to look while debugging and also have this be correct when complied. Any thoughts?
RowTags are variants and sounds are objects, this can be done without FolderItems.
Sub Open() Handles Open
me.AddRow("activate.wav")
me.RowTagAt(me.LastAddedRowIndex) = activate_wav
me.AddRow("click.wav")
me.RowTagAt(me.LastAddedRowIndex) = click_wav
End Sub
Sub Change() Handles Change
if me.SelectedRowIndex < 0 then return
var oTag as Variant = me.RowTagAt(me.SelectedRowIndex)
if oTag isa Sound then
Sound(oTag).Play
end
End Sub
Background: As a base I used @GarryPettet stopwatch desktop application then modified it to include sound files. I have been looking to integrate an internal count down timer into a Science Olympiad application I developed a few years ago that measures time between two points using lasers.
So in Open I do this
mWatch = New StopWatch
Var f As FolderItem
f = SpecialFolder.Resources
If f <> Nil Then
Sound_CB.RemoveAllRows
For Each file As FolderItem In f.Children
If file = Nil Then
// inaccessible
Return
End If
Var filename(-1) As String = file.Name.Split(".")
Sound_CB.AddRow filename(0)
Sound_CB.RowTagAt(Sound_CB.LastAddedRowIndex) = file.NativePath
Next
Else
MessageBox("There is no Resource folder on this computer.")
End If
Then inside Timer this
If mWatch = Nil Then Return
If Not mWatch.IsRunning Then Return
If ProgressBar1.Value < ProgressBar1.MaximumValue Then
Data.RemoveAllRows
Data.AddRow(mWatch.ElapsedAsString)
ProgressBar1.Value = ProgressBar1.Value + 1
Else
Data.RemoveAllRows
Data.AddRow(mWatch.ElapsedAsString)
mWatch.Stop
ProgressBar1.Value = 0
ButtonStop.Enabled = False
ButtonStart.Enabled = True
ButtonReset.Enabled = True
ProgressBar1.Enabled = False
Minutes_CB.Enabled = True
Seconds_CB.Enabled = True
Var f As New FolderItem( Sound_CB.RowTagAt(Sound_CB.SelectedRowIndex), FolderItem.PathModes.Native)
If f <> Nil And f.Exists Then
Var SoundToPlay As Sound
SoundToPlay = SoundToPlay.Open(f)
SoundToPlay.Play
End
End
Works pretty good. I will now integrate into the Science Olympiad laser timer app. Thanks to everyone in this thread especially @GarryPettet for his application, @David_Cox for the main solution to read these sound files and @Jared_Feder for the correct folder location