34

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.

3
  • how are you playing your video? post some code. Commented Feb 24, 2012 at 22:56
  • The value is set automatically when needed. That is what document says for android. But if it is less than honeycomb then you should set it as shown in below replies Commented Apr 12, 2015 at 14:21
  • Deprecated .Still it will work . Commented Jun 22, 2016 at 12:39

1 Answer 1

57

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); 
Sign up to request clarification or add additional context in comments.

10 Comments

Oh, I see. Yes that would make since. I wish they would say when. I didn't realize the doc was the latest while developing in Eclipse for 2.2
Also, if you look at the source code for Android's VideoView you can see that it does this: getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
According to developer.android.com/guide/topics/media/camera.html, this is a deprecated setting, but required on Android versions prior to 3.0; please reflect this fact in your post. Thanks.
Until Java 8 (which is not relevant for Android), annotations can only be used on declarations of classes, variables, methods, etc. If you want to avoid applying that deprecation suppression too broadly, you can extract the questionable code into its own method and mark that method with @SuppressWarnings.
For 3.0 (honeycomb) and higher, you do not need to call this method at all. As the docs state, it is ignored and set automatically.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.