Skip to content

Exoplayer cannot be constructed with a specification for "surface_type" programmatically? Why not? #1375

Closed
@jonmdev

Description

@jonmdev

Version

Media3 main branch

More version details

As noted here:

There exists no way to create an ExoPlayer programmatically while declaring the surface type in the constructor in C#/.NET. The only proposed way to do this in Android is explained here but even this is extremely clumsy and illogical.

No equivalent to this Android code exists in C#/.NET. No one is able to propose a method to make this possible in C#/.NET.

It seems obvious then the simplest solution is to simply add a constructor (which should exist either way) where we can declare the surface type on construction.

For example, we could have a simple enum:

enum ExoPlayerSurfaceType {
    surfaceView,
    textureView,
    none
}

We have the currently unhelpful constructor:

public unsafe StyledPlayerView (global::Android.Content.Context? context, global::Android.Util.IAttributeSet? attrs)

We could add the following option:

public unsafe StyledPlayerView (global::Android.Content.Context context, ExoPlayerSurfaceType surfaceType)

Or we could have an entire new class for ExoPlayerConstructorAttributes which we could create an object of and set the surface type inside (along with any other "only available on construction" parameters if they exist).

Why is this not the case already? If you agree this is a logical solution, how can we add it?

Thanks.

Devices that reproduce the issue

All ExoPlayer developments

Devices that do not reproduce the issue

n/a

Reproducible in the demo app?

Yes

Reproduction steps

See demo code and the problems this issue is causing in links above, or again, at:

Expected result

One should be able to easily create an ExoPlayer with any type of surface (TextureView, SurfaceView, none) easily from a simple constructor in Android or C#/.NET.

Actual result

It is currently very circuitous to do this in native Android code and completely impossible in C#/.NET. No solutions or answers are available anywhere.

Media

Open Visual Studio 2022. Go File > New > Android Application. Copy and paste the code here into MainActivity.cs:

protected override void OnCreate(Bundle? savedInstanceState) {
    base.OnCreate(savedInstanceState);
    
    string xmlString =
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
        "<Com.Google.Android.Exoplayer2.UI.PlayerView " +           
        "android:id=\"@+id/player_view\" " +
        "app:surface_type=\"texture_view\" " + //KEY NEEDED LINE FOR GOAL
        "android:layout_width=\"match_parent\" " +
        "android:layout_height=\"match_parent\"/>";
    
    XmlReader xmlReader = XmlReader.Create(new StringReader(xmlString));
    xmlReader.Read();
    System.Diagnostics.Debug.WriteLine("XML READER " + xmlReader.AttributeCount);
            
    Android.Util.IAttributeSet attributes = Android.Util.Xml.AsAttributeSet(xmlReader);
    System.Diagnostics.Debug.WriteLine("ATTRIBUTES " + attributes.AttributeCount);
    
    Com.Google.Android.Exoplayer2.UI.StyledPlayerView styledPlayerView = new(this, attributes);            

Receive errors as there is no current working workflow available to do this.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions