1

Метод TextureView.setSurfaceTexture требует уровня API 16, но мой текущий min 14, как я могу использовать этот метод в 14, 15 API?TextureView setSurfaceTexture метод требует уровня API 16

UPDATE (добавить код)

Планировка:

<?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> 

и в методе 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; 
    } 
+0

Вы можете разместить некоторые из вашего кода? Вы не можете преодолеть это ограничение, используя методы совместимости уровня 14, подобные api, например. установка «SurfaceTextureListener» в вашей деятельности? – pleft

+0

Я приложил код –

+0

Прохладный, могу я спросить, почему вам нужно вызвать 'mTextureView.setSurfaceTexture (mSurfaceTexture);'? Поскольку вся работа, насколько я могу понять, выполняется внутри 'onSurfaceTextureAvailable', где вы создаете новую' Surface' с доступной 'SurfaceTexture' и устанавливаете ее на' MediaPlayer'? – pleft

ответ

1

метод TextureView.setSurfaceTexture Требуемый уровень API 16

TextureView.setSurfaceTexture требует Уровень API-16 или выше.

Нет #is нет, прямо сейчас. Вы должны вызывать API Level

Откройте ваш build.gradle раздел

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

}