B4A Library [Lib] MediaBrowser

mlc

Active Member
Licensed User
Longtime User
Did you add the permission to read the SD card? (look at the manifest of my demo)

Hi Frederic,

I added the permission, so it looks my manifest:

B4X:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

but the map, continues return size = 0

I tried with :

Dim extt As String = "/mnt/sdcard/external_sd/dcim/Camera/20141231_235818.jpg"
and
Dim extt As String = "mnt/sdcard/external_sd/dcim/Camera/20141231_235818.jpg"

What you think that might be?

Thanks
 

Informatix

Expert
Licensed User
Longtime User
Are you able to see this picture with my demo app?
 

mlc

Active Member
Licensed User
Longtime User
yes, now I was trying and works
 

mlc

Active Member
Licensed User
Longtime User
I already know what the problem is, is the directory name.
DCIM must be in uppercase.

"/mnt/sdcard/external_sd/DCIM/Camera/20141231_235749.jpg"

Thanks and sorry
 

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello my friend,
I have a question about ScanNewMedia method. Heres is my code:
B4X:
Dim dir As String
dir = File.DirRootExternal & "/Selfie/"
media.ScanNewMedia(dir)
but throws me error while i try compile it:
B4X:
Error compiling program.
Error description: Cannot cast type: {Type=String,Rank=0, RemoteObject=True} to: {Type=String,Rank=1, RemoteObject=True}
Occurred on line: 270
media.ScanNewMedia(dir)
Word: dir
I see that accepts strings, but why thows error?
Thanks for your time.

EDIT: I figured out why comes error:
B4X:
Dim paths() As String = Array As String(File.Combine(dir,filename)) 'files to scan
But at photo gallery still shows broken thumbnail of the deleted images. Any ideas? (Samsung Note 4, ver. 4.4.4)
 
Last edited:

Traiser

Member
Licensed User
Longtime User
hi all,
i have one little problem with MediaCompleted event, only this don't work... it' a bug?
play, stop ecc. works greats.

B4X:
Sub listaudio_MediaCompleted
    Msgbox("test","test")
    listaudio.MediaStop
End Sub

the event is not called

sorry for my english

tnx ^^
 

Alisson

Active Member
Licensed User
Hello, Informatix
How can defined the variable with all images?
My exemple:
B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: MediaBrowser demo
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public CurrentMediaTab As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim MB As MediaBrowser
    Dim tabMedias As TabHost
    Dim pnlAudio, pnlImage, pnlVideo As Panel
    Dim svAudio, svImage, svVideo As ScrollView
    Dim lstAudio, lstImage, lstVideo As ClsCheckList
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ' Initializations
    Activity.LoadLayout("MediaGallery")

    MB.Initialize("MB")
  
    'pnlAudio.Initialize("")
    'tabMedias.AddTabWithIcon2("Audio", CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnson_inactif.png"), 32, 32), _
                                                  'CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnson.png"), 32, 32), pnlAudio)
    pnlImage.Initialize("")
    tabMedias.AddTabWithIcon2("Imagem", CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnpict_inactif.png"), 32, 32), _
                                                  CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnpict.png"), 32, 32), pnlImage)
    'pnlVideo.Initialize("")
    'tabMedias.AddTabWithIcon2("Video", CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnvideo_inactif.png"), 32, 32), _
                                                  'CreateScaledBitmap(LoadBitmap(File.DirAssets, "btnvideo.png"), 32, 32), pnlVideo)
End Sub

Sub Activity_Resume

        RefreshMediaList
  
End Sub

Sub Activity_Pause(UserClosed As Boolean)
    ' Stop playing music
  
End Sub



Sub ReadImages
    ' Read the image list from the MediaStore and populate the ScrollView
    ProgressDialogShow2("Send...", False)
    DoEvents
    Dim m As Map
    Dim extt As String = "/storage/emulated/0/DCIM/Camera/*.jpg"
    m = MB.GetExtImageFileInfo(extt)
    'm = MB.GetMediaImageList(True, "_display_name COLLATE UNICODE")
    lstImage.Initialize(Me, svImage, "", "Image_Click", "", 0)
    lstImage.ExtensionColor = Colors.ARGB(50, 255, 255, 255)
    DoEvents
    For i = 0 To (m.Size / 7) - 1
        Dim bmp As Bitmap
        Dim Location As String
        bmp = MB.GetImgThumbnailByID(m.Get("ID" & i), False)
        lstImage.AddItemNoChkbx(m.Get("ID" & i), m.Get("DisplayName" & i), m.Get("Location" & i), bmp)
      
    Next
    lstImage.ResizePanel
    ProgressDialogHide
End Sub



Sub RefreshMediaList
    ' Stop playing music
  
      
          
                svImage.Initialize(0)
                pnlImage.AddView(svImage, 0, 0, pnlImage.Width, pnlImage.Height)
          
            ReadImages
      
End Sub



Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
    Dim r As Reflector
    Dim b As Bitmap
    b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
            Array As Object(Original, Width, Height, True), _
            Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
    Return b
End Sub

I need read all images, after send to one server ftp.

I wait your feedback!

Thanks!
 

Informatix

Expert
Licensed User
Longtime User
Sorry but I don't understand the question. What's wrong with your code ?
 

Alisson

Active Member
Licensed User
I want read all images the path:

/storage/emulated/0/Android/cache/folder/*.jpg

This is my code:

B4X:
Sub ReadImages
    ' Read the image list from the MediaStore and populate the ScrollView
    ProgressDialogShow2("Send...", False)
    DoEvents
    Dim m As Map
    Dim extt As String = "/storage/emulated/0/DCIM/Camera/*.jpg"
    m = MB.GetExtImageFileInfo(extt)
    'm = MB.GetMediaImageList(True, "_display_name COLLATE UNICODE")
    lstImage.Initialize(Me, svImage, "", "Image_Click", "", 0)
    lstImage.ExtensionColor = Colors.ARGB(50, 255, 255, 255)
    DoEvents
    For i = 0 To (m.Size / 7) - 1
        Dim bmp As Bitmap
        Dim Location As String
        bmp = MB.GetImgThumbnailByID(m.Get("ID" & i), False)
        lstImage.AddItemNoChkbx(m.Get("ID" & i), m.Get("DisplayName" & i), m.Get("Location" & i), bmp)
    
    Next
    lstImage.ResizePanel
    ProgressDialogHide
End Sub

Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…