Android TextureView setSurfaceTexture方法需要API 16级别

Android TextureView setSurfaceTexture方法需要API 16级别,android,textureview,android-textureview,android-min-sdk,Android,Textureview,Android Textureview,Android Min Sdk,TextureView.setSurfaceTexture方法需要API级别16,但我目前的最低级别为14,如何在14、15 API中使用此方法 更新(添加代码) 布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com

TextureView.setSurfaceTexture方法需要API级别16,但我目前的最低级别为14,如何在14、15 API中使用此方法

更新(添加代码)

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".view.MainActivity"
    tools:showIn="@layout/activity_main">

    <FrameLayout
        android:id="@+id/videoSurfaceContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextureView
            android:id="@+id/texture_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </FrameLayout>
</RelativeLayout>
表面纹理侦听器:

@Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
        mSurfaceTexture = surfaceTexture;
        Surface surface = new Surface(mSurfaceTexture);
        mMediaPlayer.setSurface(surface);
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
        mSurfaceTexture = surfaceTexture;
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        mSurfaceTexture = surfaceTexture;
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        mSurfaceTexture = surfaceTexture;
    }
TextureView.setSurfaceTexture方法需要API级别16

TextureView.setSurfaceTexture需要API级别16或更高级别

不,现在不行。您必须调用API级别16

打开
build.gradle
部分

 defaultConfig {
    minSdkVersion 16    // must use 16 for this 
    targetSdkVersion 19 // set yours as per requirement 

}

你能发布一些代码吗?您能否通过使用api级别14兼容的方法来克服此限制,例如在您的活动中设置
surfacetextrelistener
?很酷,请问您为什么需要调用
mTextureView.setSurfaceTexture(mSurfaceTexture)?因为据我所知,所有的工作都是在SurfaceTexture available的
内部完成的,在这里,您可以使用可用的
SurfaceTexture创建一个新的
曲面
,并将其设置在
MediaPlayer上
?没有设置SurfaceTexture方法,由于方向改变,我的屏幕是白色的,但声音仍在继续播放。一般来说,我希望视频不会停止播放时,方向发生变化。我的片段使用setRetainInstance(true);
 defaultConfig {
    minSdkVersion 16    // must use 16 for this 
    targetSdkVersion 19 // set yours as per requirement 

}