[Gambas-user] mpris MediaPlayer2 interface

Bruce Steers bsteers4 at gmail.com
Tue Feb 28 16:15:04 CET 2023


On Sat, 25 Feb 2023 at 19:50, Bruce Steers <bsteers4 at gmail.com> wrote:

>
>
>
>>> MediaView will need a couple of enhancements though. it must fire events
>>> for it's internal controls, volume, position playstate.
>>>
>> Some of the MediaPlayer events could probably work.
>> State,
>> Duration,
>> Position (not constant, only on user change)
>> Volume (needed event)
>>
>
> I think I have a good way using an observer.
> It works for MediaPlayer.class
>
> Can MediaView FMediaPlayer.class have a hidden property/method to it's
> $hPlayer object ?
>
> I can find FMediaPlayer using MediaView1.Children[0]
>
> If I can see the MediaPlayer object inside MediaView I could observe it.
>
> FMediaPlayer._GetPlayer() would make mpris work for MediaView I think and
> just with inheritance.
>
> Respects
> BruceS
>

Okay I have got something a bit more "gambas component" like now.
https://gitlab.com/bsteers4/gambas/-/commits/gb.media.mpris2
that's a master branch with new component gb.media.mpris2 in comp

should I merge as draft/wip for your , er , amusement ;) lol ;)

My opinion of the component.
The classes MPRIS_Server, MPRIS_Reader and MPRIS_Metadata are almost there.
(Needs wiser eyes on it to check if my implementation is correct)

The test apps are rubbish and under-developed but meh,
The Reader test app is pretty nice.
The server app tries to use a FileChooser directly as a playlist via a ton
of workarounds.
Still developing them, ironing out the kinks.

what the component is...
Adds minor enhancements to MediaPlayer / MediaView

Has a MediaPlayer.class that adds some more event triggering.
Triggers Volume, PositionChanged and Duration events.
Duration event is modified to trigger not when file loads and duration is
zero but when file plays and duration is known.
Volume is checked during a Position event and raises Volume if it's changed
as it does not auto-fire.
IsMediaView property sets true if the MediaPlayer is in a MediaView object.

MediaView enhancements..
Events: Volume, Duration, State, Position, PositionChanged
(Position fires like MediaPlayer Position every half second,
PositionChanged fires when manually changed)

MPRIS_Server now has a MediaPlayer property and can be either a MediaPlayer
or MediaView object

SImple initiation
  MPRIS = New MPRIS_Server("gplayer") As "MPRIS"
  MPRIS.DesktopEntry = "multimedia-player"
  MPRIS.Identity = "Gambas MPRIS media player"
  MPRIS.MediaPlayer = MediaView1

then use MPRIS_ events to get and react to calls from other controllers
use MediaView_ events to set mpris fields.

Properties like MPRIS.CanQuit are automatic depending if it can raise the
event (using If Object.CanRaise(Me, "Quit"))

I tried to make it as "stand-alone" as possible where the MPRIS_Server does
not actually control the MediaView but fires events the programmer must
respond to.

As i'm pretty fresh at this i'm not sure of the exact correct
implementation so it's just kind of developing as needed.
So the code is in flux at present not really sure how to operate so
ever-changing but operating anyhow :)

The MediaPlayer/MediaView enhancements seem needed ,
MediaPlayer is much easier to integrate as it has no internal controls but
a little jiggery pokery with it's events was needed to make them mpris
compliant. possibly too much for some coders?
The other option would be new class names like MMediaPlayer MMediaView or
something to keep them separate from the native ones. Or if you could make
MediaPlayer fire Duration, Volume, PositionChanged events like i have (I
think it would not break anyones code) i could just make a MediaView clone
and MediaPlayer would be ready usable.

Have added comments to test apps like "the following are the MPRIS events"
, "the following are the MediaView events", etc

https://gitlab.com/bsteers4/gambas/-/commits/gb.media.mpris2
https://gitlab.com/bsteers4/gambas/-/tree/gb.media.mpris2/comp/src/gb.media.mpris2/.src

I'd like to put my name on this but i think I will need some guidance to
bring it up to gambas inclusion standard.
My assumption would be my code is far from acceptable and Ben (or someone)
will just make one the correct way 🙄
(whatever, mpris2 for gambas will be awesome either way :)

If anyone else wants to get on board and advise, fix, help get this to a
gambas inclusion level then please have a look at the code , try it out. if
you have a mediaplayer app try to add it and hit me with any "oh no , don't
do that!, you must do this..." I need :)
(you should be able to just drop the MPRIS_Server and MprisMediaPlayer
folders into your .src)

Considerations still in mind..
* Do not make the programmer do everything and allow automatic mpris
control of the player.
* Do not use inherited adapted MediaView, make a clone, renamed and adapted.


Respects
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230228/650d77c4/attachment-0001.htm>


More information about the User mailing list