Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a video player? #51

Open
phuongnd08 opened this issue Jun 4, 2023 · 6 comments
Open

Adding a video player? #51

phuongnd08 opened this issue Jun 4, 2023 · 6 comments

Comments

@phuongnd08
Copy link

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
Copy link
Owner

AndyObtiva commented Jun 6, 2023

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:

  • Implement a video decoding custom control in Glimmer DSL for LibUI on top of the area control once the area control starts supporting native rendering of bitmap graphics, aka images. area image bitmap support is an upcoming feature in the underlying libui-ng C library. Once implemented, then a Ruby developer could use a 3rd-party or custom-made library to decode video into bitmap graphics and then render images on area with a typical video frame rate of 24 fps or faster.
  • Add a new native video control to the underlying libui-ng C library and use it in Glimmer DSL for LibUI. I just opened an issue for this approach under libui-ng: Video control support libui-ng/libui-ng#209 This approach could leverage pre-existing C video libraries (or wrap existing video players if that made more sense).
  • Build a 3rd-party library extension video control for libui-ng as a separate effort from libui-ng (also leveraging pre-existing C video libraries or wrapping existing video players). This is similar to the 2nd approach above, but it could be done by 3rd party software engineers who do not want to wait for the libui-ng software engineers to get to supporting the video control.

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
Copy link
Owner

AndyObtiva commented Jun 6, 2023

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
Copy link
Author

phuongnd08 commented Jun 6, 2023 via email

@Largo
Copy link

Largo commented Jun 12, 2023

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
Copy link
Author

phuongnd08 commented Jun 12, 2023 via email

@phuongnd08
Copy link
Author

phuongnd08 commented Jun 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants