mediaplayer class
Posted
#1
(In Topic #1850)
Enthusiast

mediaplayer events export to calling class
Hi folks,As the m3u/mp3 player test and learning app evolves, I am now at learning a little bit OOP.
My first try succeded in creating a class encapsulating most of the information we get
if playing an mp3 file.
Now I wanted to separate the GUI from the class, which also works.
However, information generated during playback, such as the current playback position,
song length, and song tags, is now only available in the class.
Now the question is: is there an easy way to return the information as an event to the calling instance?
My current approach - not yet implemented - is a timer that queries the class for the values every
xx milliseconds, stored in a collection.
E.g. the event in the class returns the actual song position, which is needed for the progressbar.
Or should I pass a variable by reference to the class and make the changes in the GUI there?
To do this, however, a clear interface would have to be created - such as for the progress bar.
Your thoughts?
Thanks a lot,
Regards
Yogi
Posted
Administrator

Assign that position to a propery that you can read outside the class
Code
Propetry CurrentPosition As Integer Use $iCurrentPosition
In above example you assign the position to private variable $iCurrentPosition in your loop
Outside the class you can approach the property as follows:
Code
<classname>.CurrentPosition
When the loop runs the CurrentPosition will change with it.
That's the first I came up with, but there are multiple roads to Rome…
You use $iCurrentPosition (a Private variable) inside the class and CurrentPosition (a Public variable) outside the class.
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Enthusiast

sub - mediaplayer calls at my knowledge periodically (position) and if something changes (_tag, _End)
this following events/subs I use:
and this are the ones from the description:
Code (gambas)
AudioChanged This event is raised whenever the number or order of the audio streams has changed.
SubtitlesChanged This event is raised whenever the number or order of the subtitles streams has changed.
VideoChanged This event is raised whenever the number or order of the video streams has changed.
Inherited events
AboutToFinish This event is raised when the current playing media is about to finish.
Buffering This event is raised when the pipeline is buffering data.
Duration Raised when the duration of a pipeline has changed.
End Raised when the end of stream has been reached while playing.
Event This event is raised when the Media object emits any internal event.
Message Raised when a child control emits a message.
Position
Since 3.13
This event is raised when the stream position changes.
Progress This event is raised while the media is played, and until it is stopped.
Start This event is raised when a new media starts playing.
State This event is raised when the state of the control has changed.
Tag Raised when some tags have been found.
SubtitlesChanged This event is raised whenever the number or order of the subtitles streams has changed.
VideoChanged This event is raised whenever the number or order of the video streams has changed.
Inherited events
AboutToFinish This event is raised when the current playing media is about to finish.
Buffering This event is raised when the pipeline is buffering data.
Duration Raised when the duration of a pipeline has changed.
End Raised when the end of stream has been reached while playing.
Event This event is raised when the Media object emits any internal event.
Message Raised when a child control emits a message.
Position
Since 3.13
This event is raised when the stream position changes.
Progress This event is raised while the media is played, and until it is stopped.
Start This event is raised when a new media starts playing.
State This event is raised when the state of the control has changed.
Tag Raised when some tags have been found.
But thanks for your input. It helped taking a new view and possibly I don't use the Player GUI modal
but just do a .show() instead of .showmodal() and do a loop and update the GUI there with the
class values till the GUI closes.
The .showmodal() is just a fixed GUI without any problems one has to check outside.
I don't know what I have to be aware if doing just the .show() part.
Kind regards,
Yogi
Posted
Administrator

Never worked with gb.media, but had a look at the wiki.
Untested what I do above, wrote it down right here.
Give it a go and let me know if it works
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Enthusiast

gbWilly said
Never worked with gb.media, but had a look at the wiki.
Untested what I do above, wrote it down right here.
Give it a go and let me know if it works
From “Post #12,659”, October 22nd 2025, 3:49 PM
Thanks Willi, the next steps in OOP …
kind regards
Yogi
Posted
Administrator

This syntax:
used to be (and still valid for backward compatibily):
So, it is a property with a read and write event as posted above, but the short form introduced somewhere in version 3 has some internal implementation.
In your case Property Read MyProgress As Float Use $fMyProgress would do as you do not need a write event.
Last edit: by gbWilly
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Enthusiast

I did in the class:
Code (gambas)
Code (gambas)
Dim cLFmp3 As New LFmp3 'create an instance of the mp3player
Dim id As Integer
cLFmp3.sGetFile() 'load an m3u File in the class
mp3Playerformsmall.cLFmp3 = cLFmp3 'give the GUI class the mp3 player reference
mp3Playerformsmall.Show() ' show the mp3player form with buttons
'I don't know how to detect if a form object exists, just a try
id = mp3Playerformsmall.Id
While mp3Playerformsmall.Id = id 'as long as the id is the ame of the form
If cLFmp3.cSong.Count > 0 Then 'if something is in the collection
'update the form values
mp3Playerformsmall.TextSong.Text = cLFmp3.cSong["TITEL"]
mp3Playerformsmall.lblDuration.Text = cLFmp3.cSong["DAUER"]
mp3Playerformsmall.ProgSong.Value = cLFmp3.cSong["POSITION"]
Endif
Wait 0.01
Wend
Dim id As Integer
cLFmp3.sGetFile() 'load an m3u File in the class
mp3Playerformsmall.cLFmp3 = cLFmp3 'give the GUI class the mp3 player reference
mp3Playerformsmall.Show() ' show the mp3player form with buttons
'I don't know how to detect if a form object exists, just a try
id = mp3Playerformsmall.Id
While mp3Playerformsmall.Id = id 'as long as the id is the ame of the form
If cLFmp3.cSong.Count > 0 Then 'if something is in the collection
'update the form values
mp3Playerformsmall.TextSong.Text = cLFmp3.cSong["TITEL"]
mp3Playerformsmall.lblDuration.Text = cLFmp3.cSong["DAUER"]
mp3Playerformsmall.ProgSong.Value = cLFmp3.cSong["POSITION"]
Endif
Wait 0.01
Wend
This works at the moment 😀
Thanks a lot,
kind regards
Yogi
Posted
Enthusiast

After a heavy last weekend (in short, screwed my backups 5TB USB drive AND my running system)
I'm back again.
The mp3 player story evolves. I'd like to use Tableview, it is nice to handle what to show, knows
immediatley the selections.
At the tests before doing the mp3 class all worked well. Now that I try to encapsulate all functions
into the class I get a problem.
On the form I create I have a tableview object. I prepare the view like
Code (gambas)
TableView1.Columns.Count = 2
TableView1.Columns[0].Title = ("Songs")
TableView1.Columns[0].Alignment = Align.Left
TableView1.Columns[0].Width = 300
TableView1.Columns[1].Width = 200
TableView1.Columns[1].Title = ("Title")
TableView1.Row = 1
TableView1.Columns[0].Title = ("Songs")
TableView1.Columns[0].Alignment = Align.Left
TableView1.Columns[0].Width = 300
TableView1.Columns[1].Width = 200
TableView1.Columns[1].Title = ("Title")
TableView1.Row = 1
and then it gets updated through
Now I have a mp3 class and give a reference to the tableview object on the form to the class.
Is it somehow possible to have the "Public Sub Tableview1_data" event inside the class
through the reference? Also other automatically called events like "Public Sub Tableview1_drop" etc?
Listbox reference would be a simple solution, because just setting the array to the reference it shows
the songs in the listbox, but also the problem with event handling inside the class…
Thanks a lot,
Kind regards,
Yogi
Posted
Guru

Code
Public Sub Form_Open()
Object.Attach(TableView1, MyClass, "TableView1")
End
Then all events will be handled by MyClass and not the form class.
Also do your fields need to be editable?
Ie. Is there a reason to choose TableView over GridView.
Posted
Guru

MPRIS2 with Mediaview
If your player has MPRIS2 it can display info and be controlled by other programs like the KDE desktop media controller.
Posted
Enthusiast

BruceSteers said
If your class is called MyClass.class then you can deal with the events in that class by attaching the TableView object to it…Code
Public Sub Form_Open()
Object.Attach(TableView1, MyClass, "TableView1")
End
Then all events will be handled by MyClass and not the form class.
Also do your fields need to be editable?
Ie. Is there a reason to choose TableView over GridView.
From “Post #12,752”, October 31st 2025, 4:40 AM
Dear Bruce,
Thanks for helping out, this seems to be the way I thought of - without knowing much about OOP.
I hope I understood the way where it should be positioned in the source.
Instead of using the TableView just used another "problem" which should be at the same level:
There is a mp3player form with the Sub Form_open, initializing the class.
A separate form "mp3visuell" is used for visual effects, contains the drawing area "dwaVisualisation".
Class name is "LFmp3"
So I did Sub form_Open() for the mp3player Form:
Object.Attach(mp3visuell.dwaVisualisation, LFmp3, "dwaVisualisation")
Did a cLFmp3 = New LFmp3(mp3visuell.dwaVisualisation) 'giving the object reference to the class
In the class created a Public variable
Public dwaVisualisation As DrawingArea
it gets the value of the given argument reference to the "mp3visuell.dwaVisualisation"
and a Sub
Public Sub dwaVisualisation_Draw()
but the Sub is never called.
So the problem is in front of the screen 😇
Where is the error?
Thanks a lot
Yogi
PS: As I have not used so many "views" of the object class since I began with Gambas in September I
used first the simple Listbox, then came aware of the TableView which suits better for viewing a
String[] Array with more columns
So will have a look also at the GridView…
Posted
Enthusiast

BruceSteers said
When you really feel like blowing your mind check out this post…
MPRIS2 with Mediaview
If your player has MPRIS2 it can display info and be controlled by other programs like the KDE desktop media controller.
From “Post #12,753”, October 31st 2025, 4:51 AM
I think this is beyond my skills …
Thanks again,
Regards
Yogi
Posted
Enthusiast

testmp3-0.0.1.tar.gz
1 guest and 0 members have just viewed this.


