iOS Question Play a custom wav file

WhiteWizard

Member
Licensed User
I wanted to play a simple .wav file in B4i, but after searching and searching I couldn't find a clear example of how to do it. An example of how to play a default IOS sound would also be useful. Thank you very much.

From what I read, I came with this useless code:
B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(NavControl)
    NavControl.NavigationBarVisible = False
    ' Codigo personalizado
    OriginalServer = Servidor
    App.RegisterUserNotifications(True,True,True)
    .....

Sub PlaySound(Archivo)
    Dim n As Notification
    n.Initialize(DateTime.Now)
    Dim no As NativeObject = n
    n.PlaySound = True
    n.AlertBody = "Mi mensaje."
    If App.OSVersion >= 8.2 Then
        no.SetField("alertTitle", "Check point")
        'Custom sound
        no.SetField("soundName", Archivo)
        n.Register
    End If
    
End Sub

The .WAV file is located in Project\B4i\Files\Special
 

Semen Matusovskiy

Well-Known Member
Licensed User
This is useful code but for another purpose :)
For custom sounds see https://www.b4x.com/b4i/help/mediaplayer.html#mediaplayer (you need to use iMedia library).

For system sounds you don't need this library.
Add to the bottom
B4X:
#If OBJC
#import <AudioToolbox/AudioToolbox.h>
- (void) PlaySystemSound: (SystemSoundID) audioID { AudioServicesPlaySystemSound (audioID); }
#End If

To play sytem sound (for example, with id 1015) use
B4X:
    Dim no As NativeObject = Me
    no.RunMethod ("PlaySystemSound:", Array (1015))

A list of valid id - see, for example, https://github.com/TUNER88/iOSSystemSoundsLibrary
 
Last edited:
Upvote 0
Top