I create a PlayerView
programmatically:
PlayerView playerView = new PlayerView(context);
Instead of using SurfaceView
, I want it to use TextureView
. In the documentation, it says to do the following:
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
app:surface_type="texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
However, like I said, I'm creating it programmatically, so how would I set it to use TextureView
in my situation?
Step 1: Create an XML file:
<com.xxx.xxx.PlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:surface_type="texture_view"
/>
Step 2: Create an AttributeSet
val xmlAttributes = context.resources.getXml(R.xml.player_view).let {
try {
it.next()
it.nextTag()
} catch (e: Exception) {
// do something, log, whatever
}
Xml.asAttributeSet(it)
}
Step 3: Pass that into the constructor
PlayerView(context, xmlAttributes)
I'd like to note that this is stupid, you shouldn't have to do this, I hate that I had to, and I hate Exoplayer sometimes... (most times)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.