B4J Question [SOLVED] Open B4J app by double clicking on a file

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

I've developed with B4J, a custom video encoder to be used to encode videos that Arduino, ESP8266 and ESP32 can read as fast
possible from micro SD card, play the video on a TFT screen and play audio in sync with video.

This my encoder accept a series of images, and convert them to a single custom video file.
The encoder show the video while encoder process create the it.

All this works and on Arduino side, I can read the file header and all video data and play them.

My problem now is that, because this is a custom format, Windows, Linux and other OS don't see them
as video files and they cannot be played on desktop side.

So now I want to develop a video player to open these files.

Here there are things I do not know, B4J apps accept arguments when launched, but how to extract the path ?

B4X:
Sub AppStart (Form1 As Form, Args() As String)

I explain better, on desktop I want to double click my file, then my player open with that file,
so at least I need the file path passed, in a way I can open the file and manage to play it.

Note that this should be done without an additional bat file, just double click on a file in any position to launch the player with it.

I want to ask if it is that possible, and if yes what is the best approach to do it.

Many thanks
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Here there are things I do not know, B4J console apps accept arguments when launched, but it is possible to
have something similar for GUI applications ?
Yes, Gui apps accept arguments too.

Automation will be different for each OS.
If it's just for you, then you can manually associate the file extension by using Open With on the Windows context menu and selecting your app and click always.

To automate this you would need to edit the Windows Registry during installation. I think Inno Setup could probably help for windows. (I've not needed to try it).

I haven't used other OS's much, but would guess that packagers for each would have similar options.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks for reply and advices @stevel05

If someone have already managed it please post some advices.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks @byz So there are no modifications we have to do on Inno Setup ?

How I can get the file path on Args here ? It is passed as Args(0) ?
B4X:
Sub AppStart (Form1 As Form, Args() As String)
I Need B4J know what file to open, is not only the link to the OS to the executable jar file.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
In Inno Setup Script this looks so (for ".orionlab" file extention):
[Registry]
Root: HKCR; SubKey: .orionlab; ValueType: string; ValueData: OrionLab Sensor File; Flags: uninsdeletekey noerror; Tasks: ; Languages:
Root: HKCR; SubKey: OrionLab Sensor File; ValueType: string; ValueData: OrionLab Sensor File; Flags: uninsdeletekey noerror
Root: HKCR; SubKey: OrionLab Sensor File\Shell\Open\Command; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletevalue noerror
Root: HKCR; Subkey: OrionLab Sensor File\DefaultIcon; ValueType: string; ValueData: {app}\{#MyAppExeName},0; Flags: uninsdeletevalue noerror
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks @peacemaker, I'm not pratical to Inno Setup scripts, and don't know orionlab
I can use like that to associate my custom raw file format to the executable jar file ?
I don't see where file extension is on this script, is the SubKey: .orionlab ?
But this is is like associate it on the right-click/open with ?

I have to get the file path on Args.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks @peacemaker, I'm not pratical to Inno Setup scripts, and don't know orionlab
I can use like that to associate my custom raw file format to the executable jar file ?
I don't see where file extension is on this script, is the SubKey: .orionlab ?
But this is is like associate it on the right-click/open with ?
.orionlab file extension - it's my custom invented extension for my OrionLab app, and it was invented just for the way to open my app from Console. And maybe open app's file project (but it's optional, not used now)


B4X:
Sub AppStart (Form1 As Form, Args() As String)
    If Args.Length > 0 Then
        Try
            If File.Exists(Args(0), "") Then 'don't assume that it is a valid path
                Log("File argument = " & Args(0))
            End If
        Catch
            Log(LastException)
        End Try
    End If
...

Invent the file extension for YOUR app, replacing Inno Setup texts of "orionlab".
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks for your example code, I know it is not so difficult,
the problem is how to pass the file path from the OS so I can get it as Args(0).

With old version of Java I had the option to test it on the command prompt like that:
B4X:
java -jar MyVideoPlayer.jar C:/Path/to/the/file
so may instruct the Operating System to execute java -jar MyVideoPlayer.jar %File or something like that should be worked,
but now with Java19 is not too simple to me test it.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
A slight tangent, but for most of my apps I implement drag and drop for loading files. Not quite as immediate, but simple, functional and cross platform.
Yes for certains apps this is beatiful way, but for a simple video player that just play a video on canvas with help of BitmapCreator, I imagine that is simpler double click on files to open every file a new instance of player app.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Build a standalone package and run the .exe from the command line with the argument. Or use the #CommandLineArgs directive to test in the IDE.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Because this won't work ?
I expects it print on the log (the command prompt) the argument I passed:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
    
    For i = 0 To Args.Length-1
        Log("(" & i & " -> " & Args(i))
    Next
End Sub
Here the result:
1751544617291.png
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
on desktop I want to double click my file, then my player open with that file
I do exactly what you're asking on a couple of apps, using Inno Setup in the way that @peacemaker has described.

See also:
When you do it this way, and double-click on a file that has the correct file extension, your app will open and the path to the file is passed to your app as Args(0) in the way that @peacemaker described in post #8.

@stevel05 suggestion to use drag & drop is another perfectly viable route.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Excellent @Chris2 , I will try that
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Yes @peacemaker it is just Windows 11 that by default with right click open on Command Prompt open it in PowerShell
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Many thanks all for help,
I will try your advices.... I see very active forum today o_O
probably is a good day to release my next WebGL tutorial, time permitting.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
p:\GoogleDrive\1Sources\Sensors_ORION\B4J\Objects\temp\build>orionlab.exe sample.orionlab
If i use such start line (or double click over file "sample.orionlab", if really created) - my app just runs OK (file name is in log).
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
@peacemaker I'm on Inno Setup, did you see something wrong here ?
[Registry]
Root: HKCR; SubKey: .rvb; ValueType: string; ValueData: Raw Video Bitmap File; Flags: uninsdeletekey noerror; Tasks: ; Languages:
Root: HKCR; SubKey: Raw Video Bitmap File; ValueType: string; ValueData: Raw Video Bitmap File; Flags: uninsdeletekey noerror
Root: HKCR; SubKey: Raw Video Bitmap File\Shell\Open\Command; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletevalue noerror
Root: HKCR; Subkey: Raw Video Bitmap File\DefaultIcon; ValueType: string; ValueData: {app}\{#MyAppExeName},0; Flags: uninsdeletevalue noerror
How do I get the icon file ? Here there is some confusion, this point to the video player icon app or custom file icon ?
It associate the app icon to the custom file icon ?
 
Upvote 0
Top