Android Question OpenSLSoundPlayer: FileNotFoundException

danijel

Active Member
Licensed User
Longtime User
I am using OpenSLSoundPlayer Lib to play simple sounds.
Everything works great in Release Mode. But when I switch to Debug Mode I get an Exception:

Logs:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 32 (Main)
java.io.FileNotFoundException: down.wav
    at android.content.res.AssetManager.openAssetFd(Native Method)
    at android.content.res.AssetManager.openFd(AssetManager.java:699)
    at flm.b4a.openslplayer.OpenSLSoundPlayer.LoadSoundFromAssets(OpenSLSoundPlayer.java:47)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:761)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6523)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
** Activity (main) Resume **


Code:
B4X:
Sub Globals

    Dim SP As OpenSLSoundPlayer
    Dim SND As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    SP.Initialize(8, False)
    SND=SP.LoadSoundFromAssets("down.wav")
    SP.Play(SND, 1, 0)
    
End Sub


down.wav is in Default Group in Assets Files.
What is wrong with this?
 

npsonic

Active Member
Licensed User
You may want to test if this makes any difference
B4X:
#DebuggerForceStandardAssets: True
 
Upvote 0

npsonic

Active Member
Licensed User
I had same kind of problem with one of my app. If I remember correctly I never did solve the problem, so I just copied files to DirInternal and used them from there.
You can just check every time app starts that files exists in DirInternal if not then use copy.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
I had same kind of problem with one of my app. If I remember correctly I never did solve the problem, so I just copied files to DirInternal and used them from there.
You can just check every time app starts that files exists in DirInternal if not then use copy.
In fact that works as a workaround solution. Thank you!
 
Upvote 0

porvenir

New Member
Licensed User
Longtime User
Hello Danijel.

You can put the code to resolve that issue. Because I got the same problem.

Thank's a lot.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
You can put the code to resolve that issue. Because I got the same problem.
B4X:
Sub Globals
    Dim SP As OpenSLSoundPlayer
    Dim MySound As Int    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    File.Copy(File.DirAssets, "snd.wav", File.DirInternal, "snd.wav")
    SP.Initialize(8, True)
    MySound = SP.LoadSoundFromDisk(File.DirInternal & "/" & "snd.wav")
    SP.Play(MySound, 1, 0)
End Sub

This should work. Just keep this in mind:
You can just check every time app starts that files exists in DirInternal if not then use copy
 
Upvote 0

porvenir

New Member
Licensed User
Longtime User
B4X:
Sub Globals
    Dim SP As OpenSLSoundPlayer
    Dim MySound As Int   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    File.Copy(File.DirAssets, "snd.wav", File.DirInternal, "snd.wav")
    SP.Initialize(8, True)
    MySound = SP.LoadSoundFromDisk(File.DirInternal & "/" & "snd.wav")
    SP.Play(MySound, 1, 0)
End Sub

This should work. Just keep this in mind:

Thank's a lot Danijel for you response. I will change my code... ;)
 
Upvote 0
Top