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

Some examples of implementing Avalonia controls for displaying video (using OpenGL and Software rendering). #7

Open
homov opened this issue May 3, 2023 · 11 comments

Comments

@homov
Copy link

homov commented May 3, 2023

LibMpv.Client - a complete libmpv API wrapper and some examples of implementing Avalonia controls for displaying video (using OpenGL and Software rendering).

Works on Linux and Windows (maybe MacOS)

@mysteryx93
Copy link
Owner

Awesome thanks!

@mysteryx93
Copy link
Owner

For Desktop, there is OpenGlVideoView and NativeVideoView, what's the difference between both? NativeVideoView is not used.

And on Android, there is no OpenGlVideoView. Can't that renderer be used on Andrroid?

@mysteryx93
Copy link
Owner

Refactoring is done. Now got some pretty clean code.
https://github.com/mysteryx93/LibMpv-OpenGL

For some reason, your Android version runs under "AndroidSample" folder; but I can't make my version to run. Can't figure out what I'm missing.

Also, although your Android version runs, it crashes if we try to switch windows. There's still more work to do on the Android implementation; and then iOS.

@homov
Copy link
Author

homov commented Jun 22, 2023

For Desktop, there is OpenGlVideoView and NativeVideoView, what's the difference between both? NativeVideoView is not used.

You will have to read the libmpv documentation to understand the difference between these player embedding technologies
https://github.com/mpv-player/mpv-examples/blob/master/libmpv/README.md (Methods of embedding the video window)

Also, although your Android version runs, it crashes if we try to switch windows. There's still more work to do on the Android
implementation; and then iOS.

Yes you are right. There is a problem when switching windows. It's probably trivial, but I don't have time to fix this bug at the moment. My interest was just to try to run on android. Perhaps in the future I will return to this problem.

@homov
Copy link
Author

homov commented Jun 22, 2023

Notes about iOS. There is no easy way to get compiled libmpv library for iOS. Unfortunately, I don't have a macOS computer to try it out. You will most likely have to compile it yourself for that platform.

@homov
Copy link
Author

homov commented Jun 22, 2023

Notes about embedding the player. It seems to be better to use native embedding under Windows to achieve better video playback results.

In my example, the implementation of naive embedding is not complete.

How to implement better, you can look at the example of the implementation of LibVLC
https://github.com/radiolondra/libvlcsharp/tree/3.x/src/LibVLCSharp.Avalonia.Unofficial

In short, there is one problem with native embedding. It is not possible in a simple way to display the control element on top of the area in which the video is played. Therefore, it is necessary to take additional actions to achieve this result. In that example, LibvLC is used as a video player. For LibMPV it will be completely similar.

@mysteryx93
Copy link
Owner

I started implementing the full API of commands and properties but that's a lot of work. Properties work for basic data types, but strangely, GetAsync doesn't work on string values but works for other data types? Complex data types aren't yet implemented. Still a lot of work to do.

I'll leave it in the current state and add it to MediaPlayerUI.

Here's a TODO list.
https://github.com/mysteryx93/LibMpv-OpenGL#contributions-wanted

It may sit in the current state for a while unless someone picks up the work.

@homov
Copy link
Author

homov commented Jun 25, 2023

I started implementing the full API of commands and properties but that's a lot of work. Properties work for basic data types, but strangely, GetAsync doesn't work on string values but works for other data types? Complex data types aren't yet implemented. Still a lot of work to do.

Precisely because there are so many properties, I did not do this in my implementation. In addition to simple properties, there are many more properties for setting audio and video filters. Of course, the absence of mapping will not meet the classical requirements of MVVM, but this is the reality. It is not always appropriate.

@mysteryx93
Copy link
Owner

mysteryx93 commented Jun 25, 2023

I had already done the full API mapping for controlling the player via IPC controller, so I copy-pasted that; but there are quite a lot of differences and I did not finish fixing the changes.

MVVM does not apply to the library. You can create your own derived controls that implement the properties you need as MVVM, or it passes the MpvContext to the ViewModel, from there the ViewModel has full control. But the library itself doesn't care what UI or design pattern you use.

The main thing is to make it easy to test. I haven't looked into that. Your ViewModel currently takes a hard reference to MpvContext... that might need to be swapped with an interface. Could generate an interface once the API is stable.

@mysteryx93
Copy link
Owner

mysteryx93 commented Jun 26, 2023

With the full properties mapping, added auto-listening to property changes which is pretty cool. Binding to the property Changed event and it just works by magic.

It's now working with MediaPlayerUI so I'll just publish the packages as-is. They can be fixed and improved later, but I think a decent video player for Avalonia is just overdue.

Ah, there's also the issue of making the screen black on stop.

@mysteryx93
Copy link
Owner

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

2 participants