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?
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.
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.
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
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