SurfaceHolder.setType is deprecated… But required?

时光怂恿深爱的人放手 提交于 2019-11-29 04:44:57

问题


void android.view.SurfaceHolder.setType(int type)

public abstract void setType (int type) Since: API Level 1

This method is deprecated. this is ignored, this value is set automatically when needed.

Sets the surface's type.

http://developer.android.com/reference/android/view/SurfaceHolder.html

It says it's set automatically but, without it my video doesn't play. What's going on here? Is there something that replaces it? I'm having a time getting video to play correctly on Android.


回答1:


The trick is in knowing when it was deprecated, which is kind of hard to determine from my experience. The documentation is always current for the latest API available, but you are probably not running this app on the latest API, if I had to guess. So you still have to use this method (typically with PUSH_BUFFERS) to make it work on older platforms.

EDIT: it was deprecated in Android 3.0, which the docs now reflect.
So we can use it like following:

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


来源:https://stackoverflow.com/questions/9439186/surfaceholder-settype-is-deprecated-but-required

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