B4J Question JAudioTagger ext. Lib

Patent

Member
Licensed User
Hi Community,

need some Help with the exernal JAudioTagger Lib:

B4X:
#Region
#AdditionalJar: jaudiotagger-2.2.5
#EndRegion

Sub xx
Dim jo As JavaObject
jo.InitializeStatic("org.jaudiotagger.audio.AudioFileIO")

Dim dir As String ="C:\Work"
Dim Name As String=Music.mp3"

Dim jo2 As JavaObject=jo.RunMethod("checkFileExists, Array(File.Combine(dir,Name)))
End Sub

I get a java.lang.RuntimeExeption: Method: checkFileExists not matched

So i think the second Parameter is wrong!?
Whats my mistake here?

thanks
patent
 

Patent

Member
Licensed User
i found the solution:
it works with a JavaObject 'File'

B4X:
Dim javafile As JavaObject
javafile.InitilaizeNewInstanve("Java.io.File", Array (File.Combine(dir,name)))

' forgotten in last post:
Dim jo2 As JavaObject=jo.RunMethod(getDefaultAudioFileIO", Null)

jo2.RunMethod("checkFileExists",Array As Object(javafile)))

'the Tags for instance:
log(jo2.RunMethod("read", Array As Object(javafile)))


Problem:
the checkFileExists Method crashes when the File didnt exist.....!!!??? lol

Any ideas?
 
Upvote 0

fixit30

Active Member
Licensed User
Why are you using JavaObject to test if the file exists?

In B4J you can do:

B4X:
Dim dir As String ="C:\Work"
Dim Name As String="Music.mp3"

If File.Exists(dir, Name) then
'Do something here...
End If
 
Upvote 0

Patent

Member
Licensed User
Thank you fixit30,

I know the solution in the wonderful B4J.

I tryed the checkFileExists Method from the jAudioTagger lib just to see if i do the Java-Object-Calls in the right way.
Just for learning this.
Using the jAudiotagger Lib is just a example for me, it could be any other Lib with no Wrapper.

Because i get an error with the call of the checkFileExists Method (if the file not exists), i think i am doing something wrong in my code.
Any error to see?
 
Upvote 0

billzhan

Active Member
Licensed User
Try.
B4X:
' https://www.b4x.com/android/forum/threads/get-the-fileicon-from-a-file.63866/#content
'"File" should be a java File object, not full path string.
Dim JavaFile As JavaObject
JavaFile.InitializeNewInstance("java.io.File", Array(File.Combine(dir, name)))


'edit
 
Last edited:
Upvote 0

billzhan

Active Member
Licensed User
I meant to say,
B4X:
Array As Object(javafile) -> Array(javafile)

Now I think this makes no difference
 
Last edited:
Upvote 0

Daestrum

Well-Known Member
Licensed User
Looking at the API docs - checkFileExists doesn't return a value to say the file exists.(It's declared void) It simply raises an exception if the file doesn't exist.

So you probably need to put the 'checkFileExists' code in a try - catch block

If it doesn't get caught - the fie exists.

B4X:
...
    Dim ja As JavaObject
    ja.InitializeNewInstance("org.jaudiotagger.audio.AudioFileIO",Null)
    Dim dir As String ="c:/temp/"
    Dim Name As String = "test.mp3"
    Dim jo As JavaObject
    Try
        ja.RunMethod("checkFileExists", Array(jo.InitializeNewInstance("java.io.File",Array(dir & Name))))
    Catch
        If LastException.Message.Contains("FileNotFoundException") Then
            Log("the file is missing")
        Else
            Log("something else broke")
        End If
    End Try
...
 
Last edited:
Upvote 0

Patent

Member
Licensed User
thanks a lot, billzhan and Daestrum for your contribution.

ok, now this behavior make sense for me.
I thougt that in general a "check for something" method gives back a value for this.
So i learned: not to be sure of a matter of course.......:cool:
 
Upvote 0
Top