Git Product home page Git Product logo

Comments (7)

pictos avatar pictos commented on June 14, 2024 1

@jonmdev, you can take a look on the CameraView implementation for XCT, we used the TextureView there. The code part is here and here and xml part is here.

The easiest way will be to create your own mediaElement control and reuse our handler. For me this isn't a bug, since the MediaElement was designed to show videos and not provide features like call videos, as you mentioned on your report. So I'm changing this to be an enhancement.

from maui.

ne0rrmatrix avatar ne0rrmatrix commented on June 14, 2024 1

Wow. This looks like something I want to get involved in. :)
I will be looking into this and seeing if I can figure out a way to implement this. I will start in a few days. I am currently writing tests for another PR and as soon as that is done and PR is updated I will switch and to implementing texture view. It would be great to be able to dim the view and do other fancy stuff! Using transparencies and stuff is a wonderful idea.

from maui.

jonmdev avatar jonmdev commented on June 14, 2024 1

Hey @ne0rrmatrix , I managed to figure out a working method to construct the ExoPlayer as a TextureView in .NET. It is actually quite simple but a bit silly. One must save a short snippet of an XML file into the Android Resources folder like say: Resources/layout/textureview.xml

<?xml version="1.0" encoding="utf-8" ?> 
<com.google.android.exoplayer2.ui.StyledPlayerView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:surface_type="texture_view" />

Then one can use it in Android code as:

XmlReader xmlResource = this.Resources.GetXml(Resource.Layout.textureview);
xmlResource.Read();
Android.Util.IAttributeSet attributes = Android.Util.Xml.AsAttributeSet(xmlResource);

Com.Google.Android.Exoplayer2.UI.StyledPlayerView styledPlayerView = new(this, attributes);
xmlResource.Dispose();

System.Diagnostics.Debug.WriteLine("SURFACE TYPE " + styledPlayerView.VideoSurfaceView.GetType()); //default is SurfaceView, need to make TextureView

This therefore seems like it should hopefully be a relatively straight forward feature to add. Hopefully it can be. I made a proposal here explaining further if it is any help:

#1891

from maui.

jonmdev avatar jonmdev commented on June 14, 2024

Thanks for the info. I will try to do that. But also as noted, @pictos, it is the only way to fix the bug here:

#1730

Without a way to make the MediaElement work as a TextureView, we can't get it to crop/overlap correctly in Android like it does in iOS/Windows.

from maui.

jonmdev avatar jonmdev commented on June 14, 2024

That would be amazing @ne0rrmatrix! Thanks for any help. Otherwise I must recreate my own video player (which I already started work on but it is tedious). It seems unnecessary for me to reproduce all the work of your team just to have one toggle essentially to switch over the ExoPlayer construction to TextureView. I was also stuck on how to use XML (or how to set the attribute) to make it a TextureView in .NET.

Current Method

The ExoPlayer is constructed here:

PlayerView = new StyledPlayerView(MauiContext.Context)
		{
			Player = Player,
			UseController = false,
			ControllerAutoShow = false,
			LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.CenterHorizontal)
		};

		return (Player, PlayerView);

Android states this is obsolete (we are supposed to use Media3) but in any case, this StyledPlayerView constructor is supposed to take an extra argument as per: public unsafe StyledPlayerView (global::Android.Content.Context? context, global::Android.Util.IAttributeSet? attrs)

It is through the attributes we are supposed to set the type of view:

https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/StyledPlayerView.html

The following attributes can be set on a StyledPlayerView when used in a layout XML file:

surface_type - The type of surface view used for video playbacks. Valid values are surface_view, texture_view, spherical_gl_surface_view, video_decoder_gl_surface_view and none. Using none is recommended for audio only applications, since creating the surface can be expensive. Default: surface_view

But I was stuck on how to create an attributes object that would accomplish this. Presumably we can make an attributes file then based on the constructor just in C# to pass in, right? I am not familiar with Android .NET sufficiently to know how to create this. Do you have any ideas? I am happy to continue my experiment on my end as well if I can get past this point but I couldn't figure it out.

Or if we need to make an XML file and convert it like I posted in the OP, can we make the XML file programmatically (ie. just from a text string of the necessary contents) to convert to attributes on the fly in the code right there (rather than making an actual XML file to load from disk or the object pointlessly)?

If you are not sure as well, let me know. I can post on StackOverflow or other forums and see if anyone can help. That was my next step I was planning in any case.

Media3

Perhaps also of interest, I noted in my research Media3 is being integrated into AndroidX: xamarin/AndroidX#779

I don't know enough about GitHub or how these updates work to know when we will have that available. Is it available now based on comments here? #1511

I'm not sure if that will make the job any easier or if it makes no difference. Google states the designation of TextureView vs. SurfaceView should be very easy:

For video apps that implement their own UI, the target SurfaceView, TextureView, SurfaceHolder or Surface can be set using ExoPlayer's setVideoSurfaceView, setVideoTextureView, setVideoSurfaceHolder, and setVideoSurface methods respectively.

https://developer.android.com/media/media3/exoplayer/hello-world

TextureView vs. SurfaceView

Once created, this article describes the differences between TextureView and SurfaceView in terms of events, etc and how to switch from one to the other in much more detail:

https://medium.com/androiddevelopers/android-hdr-migrating-from-textureview-to-surfaceview-part-1-how-to-migrate-6bfd7f4b970e

Again, thanks for any help with this. If you are able it will save me weeks of learning the nitty gritty of these video players to make my own from scratch just for this change. Please let me know if anything is giving you any special difficulty and I am happy to look at it also or help in any way.

If you can help me figure out the XML/attributes issue I may still just finish up my video player I have started in any case so I'd appreciate that as well.

from maui.

ne0rrmatrix avatar ne0rrmatrix commented on June 14, 2024

This looks like a great idea. I fully support it and would like to help if you want to do it yourself. If you do not I would be happy to collaborate with you and we could do it as a team. Otherwise I fully support you trying this yourself. It is up to you.

from maui.

jonmdev avatar jonmdev commented on June 14, 2024

This looks like a great idea. I fully support it and would like to help if you want to do it yourself. If you do not I would be happy to collaborate with you and we could do it as a team. Otherwise I fully support you trying this yourself. It is up to you.

Hey @ne0rrmatrix - Thanks! I appreciate it. Unfortunately, I have never modified or even built anything like a library or nuget in C#. So while I can figure out how it should work in my own project experiments and dig through the library code, I am not sure of how to do anything else like actually integrating it into the code and then building the library so it can be tested, etc.

I am only a self taught programmer. For example, with MAUI I can identify bugs and fill reports, but I must leave it to the MAUI team to fix as that is as far as I can go. Similarly for this, I can think it through, but I don't think I can implement it.

I am not sure if you'd be willing to try implementing it. It would be great if so and you can.

Either way, for the best I can provide, here are what I think the steps would be:

#1891 (comment)

What do you think? I believe I have thought this through to the maximum I can without actually doing it and testing the outcome, which as I said is a bit above my capacity or knowledge.

Is it something you could try to implement? If you try and hit any walls I'm happy to investigate them or figure out solutions. But the actual doing I think needs to be saved for someone more expert than me. Thanks either way.

from maui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.