How to play an chimes.wav? - Android

Hi,
i took the chimes.wav file from the Xojo Code Example.
And imported the file into the Andriod projekt (icon shows that ist an Sound file)
And made an very simple app - Button event pressed …

I cant get ist to work with Andriod!
I got ist to work with Mac with this example code from XOJO Docs:

Var soundFile As FolderItem = SpecialFolder.Ressorces.Child(“chimes.wav”)
If soundFile.Exists Then
Try
Var tada As Sound = Sound.Open(soundFile)
tada.Play
Catch error As IOException
MessageBox("The sound file could not be opened. Error: " + error.Message)
End Try
End If

Running Android its gets an IOExpeption at first Code Line “Var soundFile…”

Questions:
How can i access the sound file within the build .apk ? ( .apk is like zipped folder, i can see that there are files in an folder res - also the .wav file but named BN.wav (??? why) not chimes.wav.

I added an build copy to put the file in Ressources.
That worked on Mac OS but not here!
I can see in the debugger that the app looks for the file in /Andriod/data… and not within the .apk build.

How can i put files within the .apk and how can i access them from the mobileapp Andriod?

What are the really names of the SpecialFolder Ressources ect.?
Perhaps they aren’t implemented already?
But make an Android app without playing an sound file (.wav) would be really alpha XOJO :wink:

I miss really some more Andriod examples - for simple things wie play an sound…

Select “Resources Folder” as Destination Folder in the Androids Copy Files Step.

Works fine here.

' Var soundFile As FolderItem = SpecialFolder.Resources.Child("chimes.wav") ' This works also fine here
Var soundFile As FolderItem = SpecialFolder.Resource("chimes.wav")
If soundFile.Exists Then
  Try
    Var tada As Sound = Sound.Open(soundFile)
    tada.Play
  Catch error As IOException
    MessageBox("The sound file could not be opened. Error: " + error.Message)
  End Try
End If
1 Like

Why? That is the ONLY folder that works that way. It introduces inconsistency if you ask me, and should be recommended against.

I clearly wrote about it as a comment that SpecialFolder.Resources.Child(“chimes.wav”) also works.

I assume he just selected the wrong destination folder.

This works the same as it does for other project types. You can drag a sound file into the project and play it by using its name. There is an Android example that demonstrates this:

If you instead want to put the file in resources, the you would use a Copy File Build Step to copy it to Destination of Resources Folder and then use SpecialFolder.Resource() or SpecialFolder.Resources.Child() to get it by its filename.

1 Like