-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
No way to create the "IAttributeSet" required by Android ExoPlayer constructor in .NET/C# #102300
Comments
Tagging subscribers to this area: @dotnet/area-meta |
Android API for .NET lives in https://github.com/xamarin/xamarin-android. Discussions should go there. Searching for the corresponding API of kotlin, I can find an API at https://learn.microsoft.com/en-us/dotnet/api/android.content.res.resources.getxml . |
Thank you actually @huoyaoyuan ! Your reply made me realize the Kotlin solution I posted was not programmatically creating the XML but just loading from resources. It seems Android offers no way to allow one to programmatically do this. One must save the XML to resources and then load it. Absolutely absurd in my opinion, but this does work. .NET SOLUTION
This does work. |
Description
ExoPlayer is the Android video player recommended by Google and used by the MAUI Community Toolkit for video playback.
It has the following constructor in .NET:
public unsafe StyledPlayerView (global::Android.Content.Context? context, global::Android.Util.IAttributeSet? attrs) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
ExoPlayer can be constructed with a SurfaceView, TextureView, or none type of
surface_type
. Thissurface_type
determines rendering behavior of the video player. It can only be declared on construction of the ExoPlayer.In order to specify this, we are intended by Google to create or load some XML stating the
surface_type
, convert it to anIAttributeSet
and then pass it to this constructor.However, this does not work in .NET/C# and there is therefore currently no way to build a TextureView type ExoPlayer. SurfaceView is the default but TextureView is needed in many situations, and there is no way in .NET to get it.
Prior Discussion
See:
Despite two Android discussions, two MAUI discussions, and two StackOverflow discussions, no one anywhere can propose a working method for this to be done. Thus it seems this is a C#/.NET bug that must be fixed so we can use this properly.
By contrast a supposedly working Kotlin method is proposed here, but the functions referenced don't have matching C# equivalents so this is a dead end.
My Best Attempt
My best attempt to do this is is with adding the following code to a default .NET Android Application:
Error
However, this returns the error:
**Java.Lang.ClassCastException:** 'android.util.XmlPullAttributes cannot be cast to android.content.res.XmlBlock$Parser'
The only reference I can find to this error suggests it is an insurmountable dead end: https://stackoverflow.com/questions/33331935/xmlpullattributes-cannot-be-cast-to-xmlblockparser#45918669
So what is the solution? Can .NET be fixed so that we can use this constructor and build ExoPlayer with a TextureView rather than SurfaceView?
Bug Project
See reproduction bug Project here: https://github.com/jonmdev/AndroidIAttributeSetBug
Reproduction Steps
Play bug project above. Or, to remake it, in Visual Studio 2022:
Xam.Plugins.Android.ExoPlayer
Expected behavior
Should be able to make a TextureView ExoPlayer.
Actual behavior
Dead end error - cannot do so.
Regression?
I can find no reference anywhere on the Internet that suggests this ever worked or anyone has ever successfully made it work.
Known Workarounds
None known seemingly by anyone anywhere.
Other information
Any help toward a solution is greatly appreciated.
The text was updated successfully, but these errors were encountered: