I am trying to play a Sound file, but am missing something in the process… I already have loaded a FolderItem sound file succesfully, but I can’t track down this NilException. I just started with Xojo yesterday and can’t believe how FAST I’m prototyping things… however documentation could be better I guess. Hopefully the community is active
Code below
Var selectedIndex As Integer
selectedIndex = FIleListbox.selectedRowIndex
Var selectedString As String
selectedString = FileListbox.CellValueAt(selectedIndex, 1)
// Fetch the FolderItem located at FilesMap with a Key of the selected Filename
Var selectedFolderItem As New FolderItem
selectedFolderItem = FilesMap.value(selectedString)
Var soundFile As New Sound
If selectedFolderItem.Exists Then
Try
soundFile = soundFile.Open(selectedFolderItem)
soundFile.Play
Catch error As IOException
MessageBox("Error")
End Try
End If
selectedIndex is >-1 ?
or >=0
do you set the list box to required selection?
use also System.DebugLog("…") as help
if Open return nil then perhaps xojo can’t read this file, have you tried other sound file?
this part works for me in xojo2019r3.1 at a windows desktop project.
Var f As FolderItem = SpecialFolder.Documents.Child("test.mp3")
If f.Exists Then
Try
Var s As Sound = Sound.Open(f)
s.Play
Catch error As IOException
MessageBox("The sound file could not be opened. Error: " + error.Message)
End Try
End If
This is great info, now I know how to print out debug messages and also how to set breakpoints and step over the code. Thanks to both of you!!!
I found out what the issue was, and it was that my sound files were OGG and that file type is just not supported. I was somehow assuming I would get a different type of error if that was the case.