What's differences between Surfaceview and TextureView?

眉间皱痕 提交于 2019-11-29 22:57:00

TextureView

A TextureView can be used to display a content stream. Such a content stream can for instance be a video or an OpenGL scene.

Example :
https://github.com/dalinaum/TextureViewDemo

Document:
http://developer.android.com/reference/android/view/TextureView.html

SurfaceView

Provides a dedicated drawing surface embedded inside of a view hierarchy.

Examples :
http://www.mindfiresolutions.com/Using-Surface-View-for-Android-1659.php
http://blog.wisecells.com/2012/06/04/surface-view-android/

Document:
http://developer.android.com/reference/android/view/SurfaceView.html

SurfaceView and TextureView both are inherited from android.view.View class. However there are some structural difference between them.

When you want more control of the single drawing board, go for SurfaceView

  • You cannot overlay two SurfaceView.

TextureView has the following advantages over SurfaceView:

  • You can Animate, Transform and Scale a TextureView.

In addition to other answers, this could be beneficial for novice android developers or anyone who will see this.

In my case, using this snippet in OnCreate method helped me to find out which device can use SurfaceView

    if (
            GLES20.glGetString(GLES20.GL_RENDERER) == null ||
                    GLES20.glGetString(GLES20.GL_VENDOR) == null ||
                    GLES20.glGetString(GLES20.GL_VERSION) == null ||
                    GLES20.glGetString(GLES20.GL_EXTENSIONS) == null ||
                    GLES10.glGetString(GLES10.GL_RENDERER) == null ||
                    GLES10.glGetString(GLES10.GL_VENDOR) == null ||
                    GLES10.glGetString(GLES10.GL_VERSION) == null ||
                    GLES10.glGetString(GLES10.GL_EXTENSIONS) == null) {
        // try to use SurfaceView
    } else {
        // try to use TextureView
    }

Hope it helps people who develop video player apps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!