Android Tutorial [B4X] TextEditor - Save and load external files

LucaMs

Expert
Licensed User
Longtime User
Where is the code used and the full stacktrace? I donΒ΄t think anyone can help without.
The source code is in my post; also, it uses the FileHandler class which is part of the Erel's example project.
You can see the data of the selected file (log).
The only code that is missing is the one about the MediaPlayer:
B4X:
    mMediaPlayer.Load(Result.FileName, Result.RealName)
    mMediaPlayer.Play
I also tried:
B4X:
    mMediaPlayer.Load(Result.Dir, Result.RealName)
    mMediaPlayer.Play
although it seems to me that neither could have worked and indeed it is.

DIR: ContentDir
FN : content://com.android.providers.media.documents/document/audio%3A2247
RN : Dream_It_Possible.flac
Error occurred on line: 85 (B4XMainPage)
java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer._prepare(Native Method)
at android.media.MediaPlayer.prepare(MediaPlayer.java:1313)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.loadAfterReset(MediaPlayerWrapper.java:101)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:66)
at b4a.example.b4xmainpage$ResumableSub_pnlKey_LongClick.resume(b4xmainpage.java:274)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
- 9/2023 - Fixed an issue in B4A where overwriting existing files didn't trim file. Thanks @noeleon for reporting!

The change is in FileHandler.SaveAs:
B4X:
Dim ContentResolver As JavaObject = ctxt.InitializeContext.RunMethodJO("getContentResolver", Null)
Dim out As OutputStream = ContentResolver.RunMethod("openOutputStream", Array(jo.RunMethod("getData", Null), "wt")) 'wt = Write+Trim
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…