AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
458 stars 15 forks source link

Adding a video player? #51

Open phuongnd08 opened 1 year ago

phuongnd08 commented 1 year ago

I was programming Delphi in 2000 and it's a cake adding a video player to the app. Wonder how would one do it with something like libui. There are several video player around but I guess there need a mechanism to wrap them to something before they can be used.

AndyObtiva commented 1 year ago

To compare a similar solution, Glimmer DSL for SWT already has a custom widget that is a video player: https://github.com/AndyObtiva/glimmer-cw-video

So, you just say video in its DSL syntax, and you pass it a file name, and that renders a video in the GUI:

video(file: video_file)

It can accept many options like automatic looping and event listeners:

  video(file: video_file, looped: true, background: :black) {
    on_playing {
      display_video_status(@video, 'Playing')
    }

    on_paused {
      display_video_status(@video, 'Paused')
    }
  }

So, ideally, we would have something similar in Glimmer DSL for LibUI.

But, a video control would have to be implemented in one of multiple ways:

All approaches require an effort to be completed in C, but could eventually get wrapped by Ruby code and exposed/used in Glimmer DSL for LibUI syntax.

Please keep in mind that Delphi was sponsored by big corporations that were loaded with software engineering time and salaries. LibUI and Glimmer are fully free and open-source projects and community efforts, so although everything is technically possible with them, the effort might be too big to complete in a short amount of time. That's unless some software engineers play the role of champions by creating their own open-source project that is fully focused on creating a video control. I think more software engineers should step up and start building their own custom controls on top of Glimmer DSL for LibUI and share with the community. SWT software engineers already did that, and for example produced the wonderful Nebula custom widget library. Here is the Glimmer wrapper for it just to see an example of that: https://github.com/AndyObtiva/glimmer-cw-nebula

In any case, I will keep this issue open until a video control is finally supported in Glimmer DSL for LibUI (following any of the approaches mentioned above or any other approaches).

Thank you for reporting.

AndyObtiva commented 1 year ago

By the way, if you only need to open a video player separately from the GUI of a Glimmer DSL for LibUI application (as opposed to embedding a video inside the GUI), then this is certainly doable today. I just remembered that rubio-radio, which is built with Glimmer DSL for LibUI, actually leverages an existing video player called VLC.

It simply calls out to it on the command line like in this Ruby code (but it only needs the audio support of the video player, so it intentionally does not display the video player, but I've gotten it to display the video player before as that depends on what options you pass to the vlc command, which you can experiment with outside of Ruby code):

backend = 'vlc -I rc'
@io = IO.popen("#{backend} \"#{url}\"", 'r+')

Full code is here (look at the initialize and play methods): https://github.com/kojix2/rubio-radio/blob/main/lib/rubio/model/player.rb

rubio-radio is a free and open-source project, so you are welcome to install it and play around with it. I actually use it everyday as my main Internet radio app.

Please let me know if this solution addresses your need (or if it addresses your need in the short term at least).

phuongnd08 commented 1 year ago

It’s doable using mpv but i want to be able to integrate controls on the view to provide a gaming experience. Delphi works because it use ActiveX which allow me to embed MPlayer control developed by microsoft. I think glimmer better provide a wrapper to different video players on different platform. On Windows there is MediaPlayer, on Mac there is Starling?

On Tue, 6 Jun 2023 at 09:31 Andy Maleh @.***> wrote:

By the way, if you only need to open a video player separately from the GUI of a Glimmer DSL for LibUI application (as opposed to embedding a video inside the GUI), then this is certainly doable today. I just remembered that rubio-radio https://github.com/kojix2/rubio-radio, which is built with Glimmer DSL for LibUI, actually leverages an existing video player called VLC https://github.com/videolan/vlc.

It simply calls out to it on the command line like in this Ruby code:

backend = 'vlc -I @.*** = IO.popen("#{backend} \"#{url}\"", 'r+')

Full code is here (look at the initialize and play methods): https://github.com/kojix2/rubio-radio/blob/main/lib/rubio/model/player.rb

rubio-radio https://github.com/kojix2/rubio-radio is a free and open-source project, so you are welcome to install it and play around with it.

Please let me know if this solution addresses your need, or if it addresses your need in the short term at least.

— Reply to this email directly, view it on GitHub https://github.com/AndyObtiva/glimmer-dsl-libui/issues/51#issuecomment-1577801895, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABM5ZJCRUG5LEKYSEL5FGTXJ2JA5ANCNFSM6AAAAAAYZXHEYU . You are receiving this because you authored the thread.Message ID: @.***>

Largo commented 1 year ago

Just wanted to add: I've written an app with python and python-vlc that includes VLC. I've tried to do it in ruby with gtk and FFI, but the problem was that you get a window handle and GTK didn't really let me add that without tricks. I haven't tried it with libui yet, but what we would need for that is basically being able to get a "window" handle of a control inside the window. I believe GTK didn't let me do that, but I found a workaround to do it via the windows api. That would not be crossplatform so I gave up.

Protip: ChatGPT is quite good at writing FFI Code for libraries.

https://gist.github.com/Largo/bf95d8d0089f7c411fb7bdc48c8e6a30

Writing a video player ontop of vlc in ruby and distributing it with ocran would be a very interesting project. GTK3 is starting a bit to slow on windows, but it would be awesome with libui

phuongnd08 commented 1 year ago

I guess making this available to mac and windows until a genius come along and add it for linux. The app simply render a blank view writing video not supported on linux

On Mon, 12 Jun 2023 at 10:10 Largo @.***> wrote:

Just wanted to add: I've written an app with python and python-vlc that includes VLC. I've tried to do it in ruby with gtk and FFI, but the problem was that you get a window handle and GTK didn't really let me add that without tricks. I haven't tried it with libui yet, but what we would need for that is basically being able to get a "window" handle of a control inside the window. I believe GTK didn't let me do that, but I found a workaround to do it via the windows api. That would not be crossplatform so I gave up.

Protip: ChatGPT is quite good at writing FFI Code for libraries.

https://gist.github.com/Largo/bf95d8d0089f7c411fb7bdc48c8e6a30

— Reply to this email directly, view it on GitHub https://github.com/AndyObtiva/glimmer-dsl-libui/issues/51#issuecomment-1586509258, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABM5ZOTPQMJLDOTRVVZRE3XK2CDZANCNFSM6AAAAAAYZXHEYU . You are receiving this because you authored the thread.Message ID: @.***>

phuongnd08 commented 1 year ago

To compare a similar solution, Glimmer DSL for SWT already has a custom widget that is a video player: https://github.com/AndyObtiva/glimmer-cw-video

@AndyObtiva FYI I tried glimmer-cw-video but looks like it's not working with latest version of jruby (and whatever dependencies of glimmer-dsl-swt and glimmer-dsl-xml that bundler resolved to). I submitted an issue on the repo.