1

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>

Fragment の onCreateView メソッドで:

View rootView = inflater.inflate(R.layout.content_main, container, false);
    mVideoContainer = rootView.findViewById(R.id.videoSurfaceContainer);
            mTextureView = (TextureView) rootView.findViewById(R.id.texture_view);
            if (mSurfaceTexture != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    mTextureView.setSurfaceTexture(mSurfaceTexture);
                }
            }
            mVideoControllerView.setAnchorView((FrameLayout) mVideoContainer);
            mTextureView.setSurfaceTextureListener(this);

表面テクスチャ リスナー:

@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;
    }
4

1 に答える 1

1

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 

}
于 2016-03-01T14:25:14.413 に答える