B4A Library [B4X] MediaChooser - cross platform videos and images chooser

This library makes it simple to let the user choose or capture media.

1715610738023.png


Features:
  • Allows the user to capture videos and still pictures (B4A and B4i only).
  • Allows the user to pick videos and pictures.
  • Very easy to use together with SimpleMediaManager.
  • Detects images mime types. Jpeg and Gifs.
  • Works with a progress bar that shows when items need to be copied. This is currently only relevant to B4A.
  • B4A - no permissions needed.
Usage instructions: see the example. It is quite simple.

Notes:
Updates:

- v1.02 - (B4A) KeepRunningService.NotificationTitle field. Default value is "Taking picture".
- v1.01 - (B4A) adds support for targetSdkVersion=34. New requirement in manifest editor: SetServiceAttribute(KeepRunningService, android:foregroundServiceType, shortService)
 

Attachments

  • MCExample.zip
    182.4 KB · Views: 403
  • MediaChooser.b4xlib
    4.3 KB · Views: 250
Last edited:

f0raster0

Well-Known Member
Licensed User
Longtime User
Hey everyone, I've been encountering an issue (when using frotal camare) where the image token changes in the preview.
Is there a way to maintain consistency with the image token throughout, without it flipping in the preview?
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
Excellent library! Congratulations to Erel and everyone who contributes to improving B4X!

Please add a way to select documents in the library:

B4X:
...
Public Sub ChooseDocument (TypeFile as String, Text as String) As ResumableSub
    Wait For (MediaFromContentChooserTypeFile(TypeFile, Text)) Complete (Result As MediaChooserResult)
    Return Result
End Sub
...
'code for b4a
Private Sub MediaFromContentChooser (Video As Boolean) As ResumableSub
'    Dim cc As ContentChooser
'    cc.Initialize("cc")
'    Wait For (StartForegroundService) Complete (unused As Boolean)
'    If Video Then
'        cc.Show("video/*", "Choose video")
'    Else
'        cc.Show("image/*", "Choose image")
'    End If
'    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
'    StopForegroundService
'    If Success Then
'        Dim TargetFileName As String = GetTempFile
'        Dim Complete(1) As Boolean
'        MonitorTargetFile(TargetFileName, 0, Complete)
'        Wait For (File.CopyAsync(Dir, FileName, TempFolder, TargetFileName)) Complete (Success As Boolean)
'        Complete(0) = True
'        Return CreateMediaChooserResult(True, TempFolder, TargetFileName, IIf(Video, "video/*", DetectImageMime(TempFolder, TargetFileName)))
'    End If
'    Return NO_RESULT
    If Video Then
        Wait For (MediaFromContentChooserTypeFile("video/*", "Choose video")) Complete (Result As MediaChooserResult)
        Return Result
    Else
        Wait For (MediaFromContentChooserTypeFile("image/*", "Choose image")) Complete (Result As MediaChooserResult)
        Return Result
    End If
    Return NO_RESULT
End Sub

Private Sub MediaFromContentChooserTypeFile(TypeFile as String, Text As String) As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    Wait For (StartForegroundService) Complete (unused As Boolean)
    cc.Show(TypeFile, Text)
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    StopForegroundService
    If Success Then
        Dim TargetFileName As String = GetTempFile
        Dim Complete(1) As Boolean
        MonitorTargetFile(TargetFileName, 0, Complete)
        Wait For (File.CopyAsync(Dir, FileName, TempFolder, TargetFileName)) Complete (Success As Boolean)
        Complete(0) = True
        Return CreateMediaChooserResult(True, TempFolder, TargetFileName, TypeFile)
    End If
    Return NO_RESULT
End Sub
...
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
Selecting documents is simple with ContentChooser. What to do with the document is a different question and is very specific to the type of document. Or maybe you are referring to PDF documents? Android doesn't natively support displaying PDF documents which make it non-trivial to show.

Thank you for your response and concern. Android does not open PDF documents natively, but nowadays most cell phones already come with an application that views PDFs, and when they do not open, the user downloads an application that views the PDF.

The main idea is to be able to select a file, so that the user can decide what to do with the file, view, attach, send through a system API, share the document.

I myself use the modified class with the code I sent, so that the user can search for PDF documents to send to our ERP system.

I left it there in the function so that the user can choose the file type, that way he can choose whether it is a .ZIP, .PDF or any other type of file that he wants the user to select.

The best thing is to keep everything in a single class, think about selecting a photo, video, taking a photo or recording a video, we have your wonderful class! When you can implement this command, you will allow users to select other types of files in a simple and effective way, as is your class.
 
Top