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.

bwoogie
  • 4,339
  • 12
  • 39
  • 72

1 Answers1

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);
Stan
  • 6,511
  • 8
  • 55
  • 87
lyricsboy
  • 2,999
  • 24
  • 21
  • 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 – bwoogie Feb 24 '12 at 22:58
  • 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);` – lyricsboy Feb 24 '12 at 22:58
  • its making me wait :) 4 minutes. – bwoogie Feb 24 '12 at 23:02
  • 1
    According to http://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. – Eric Chen Sep 12 '12 at 19:45
  • @lyricsboy I still get a deprecation warning even when I put this call inside of the SDK_INT conditional. The only option Eclipse gives me to to suppress "deprecation" for the entire method I am in. Is there not a way to suppress the warning only for this line? – David Doria Sep 26 '13 at 16:09
  • 2
    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`. – lyricsboy Sep 26 '13 at 20:43
  • and what do we do if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ???????????? – Anonymous Sep 24 '14 at 21:16
  • @user3051067 wondering the same thing if we need to use >= because the API was deprecated in that API level. – Sudhir Singh Khanger Sep 25 '14 at 13:00
  • 2
    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. – lyricsboy Sep 25 '14 at 17:49
  • Honestly this is worst suggestion IMHO, when its said deprecated , its deprecated , no matter you use it for which SDK and API level, also its clearly stated that it will be ignored for higher SDKs , so even in that case you don't have to check the SDK. – vishal dharankar Sep 24 '16 at 07:26