Android Question Media player from sqlite database

aligol

Member
Hi I have saved about 30 words pronunciation with mp3 format in DirAssets and wrote audioes file name next to their words and meanings in my database.
I read words and meanings by cursor at two lables but don't know how to play theirs pronunciation by clicking in a button.
Can someone give me a hand?
How can i handle that?
 

Mahares

Expert
Licensed User
Longtime User
Can someone give me a hand?
This is how I envision it. Suppose you have a database in xui.defaultfolder with a table that has 2 columns: FileName and Description:
1. You can use a select query to populate an xCustomlistview from the database located in internal with an item layout that has 2 labels. One label shows the fileName, the other the Description. The xCLV returned value needs to be the text of the 1st label, exple: CustomListView1.Add(Pnl, Label1.Text)
2. In the CustomListView1_ItemClick you have this code:
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim  s As String = Value
    s = $"${s}.mp3"$   'note I add the extension of the file in Assets
    MP.Load(File.DirAssets, s)
    MP.play    
End Sub
You declare the media player in Sub Class_Globals if you use a B4XPages project: Private MP As MediaPlayer.
You initialize it in Sub B4XPage_Created with: MP.Initialize2("MP")
The files ' names in the Assets folder have the same name as the FileName column in the SQLite table. example: the assets shows sample1.mp3, but the table FileName has sampl1 without the extension. So when you click the xCLV item it adds the .mp3 extension as shown in the above code.
If you still have difficulty, post some sample files or your project, you will get help.
 
Upvote 0

aligol

Member
Thanks for your attention but Actually i confused, I'll be appreciate if you take a glance at my attachment project.
One more problem is with my designer layout, when I load Item of my disigner views that their position assigned by cording to a panel that i created for showing them , they display smaller than their actual size at designer.
 
Upvote 0
Top