Refresh MediaState

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey everyone,

i'm looking for a way in Basic4Android on how to refresh the MediaState.
I'm updating some information in MP3's ID3 tags, and when viewing in the default 's media player, I can't see it's updated unless i unmount and remount my sdcard. Then I can see the updated MP3 File.

In Java, I already tries this:

B4X:
public void refreshMediaState(final String path) {
      
      scanner=new MediaScannerConnection(ba.applicationContext, new MediaScannerConnectionClient() {
   
            @Override
            public void onScanCompleted(String arg0, Uri arg1) {
               // TODO Auto-generated method stub
               ba.raiseEvent(this, eventName + "_onscancompleted", arg1.toString() );            
            }

            @Override
            public void onMediaScannerConnected() {
               // TODO Auto-generated method stub
               scanner.scanFile(path, "audio/*");
               ba.raiseEvent(this, eventName + "_onmediascannerconnected");
            }
           });
   
           scanner.connect();
   }

I don't know if there are any other solutions in B4A or Java.

Thanks,
Tomas
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Thanks a lot Erel!

If anyone is looking for the code:

B4X:
'Refreshes the MediaState
Sub RefreshMediaState(Dir As String, FileName As String)
   Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(Dir, FileName))
    Dim p As Phone
    p.SendBroadcastIntent(i)
End Sub

Tomas
 
Upvote 0
Top