SurfaceHolder.setType is deprecated... But required?

26,675

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);
Share:
26,675
bwoogie
Author by

bwoogie

I like to program, sometimes. SOreadytohelp

Updated on July 09, 2022

Comments

  • bwoogie
    bwoogie almost 2 years

    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
    bwoogie over 12 years
    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
  • lyricsboy
    lyricsboy over 12 years
    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)‌​;
  • bwoogie
    bwoogie over 12 years
    its making me wait :) 4 minutes.
  • Eric Chen
    Eric Chen almost 12 years
    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.
  • David Doria
    David Doria almost 11 years
    @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?
  • lyricsboy
    lyricsboy almost 11 years
    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.
  • Anonymous
    Anonymous almost 10 years
    and what do we do if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ????????????
  • Sudhir Singh Khanger
    Sudhir Singh Khanger almost 10 years
    @user3051067 wondering the same thing if we need to use >= because the API was deprecated in that API level.
  • lyricsboy
    lyricsboy almost 10 years
    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.
  • vishal dharankar
    vishal dharankar almost 8 years
    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.