Android Question initialization of WAV file

Lakhtin_V

Active Member
Licensed User
Longtime User
I am working on an example of how to use audio recording in a WAV file. At the initialization stage, an error occurs: file not found...
Error WAV file initial:
....
Dir = File.DirInternal
FileName = "1.wav"
....

Sub StartWaveFile(Dir As String, FileName As String, SampleRate As Int, Mono As Boolean _
        , BitsPerSample As Int) As OutputStream
    File.Delete(Dir, FileName)
    Dim raf As RandomAccessFile
    raf.Initialize2(Dir, FileName, False, True)
    raf.WriteBytes("RIFF".GetBytes("ASCII"), 0, 4, raf.CurrentPosition)
    .....
    
    --------- beginning of main
** Activity (main) Create (first time) **
** Activity (main) Resume **
[SIZE=4]main_btnplay_click (java line: 389)
java.io.FileNotFoundException: /storage/emulated/0/1.wav: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileInputStream.<init>(FileInputStream.java:179)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1212)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1190)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1155)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.loadAfterReset(MediaPlayerWrapper.java:99)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:66)
    at b4a.example.main._btnplay_click(main.java:389)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7527)
    at android.view.View.performClickInternal(View.java:7500)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29538)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7941)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7825)
    at libcore.io.IoBridge.open(IoBridge.java:560)
    ... 24 more
java.io.FileNotFoundException: /storage/emulated/0/1.wav: open failed: ENOENT (No such file or directory)
[IDE message - 12:00:41]
An error occurred.
Error loading IDE layout file.
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **[/SIZE]


but initially it cannot be there in principle. Additionally, the author tries to delete such a file, what is the reason for the error?
 

Lakhtin_V

Active Member
Licensed User
Longtime User
The error happens when you call MediaPlayer.Load. I cannot say why the file isn't there. You can check whether it exists with File.Exists.
Have fun with this reaction. I fined error. This name of file has not been formed for the initial process...
 
Upvote 0
Top