6

Am recently adding support for 4K in my app for Android TV users. My test device is SONY KD-49XF9005. While the built-in image viewer, as well as YouTube, can display in 4K without issue, I've got no luck getting it to work for my app so far.

My app uses a GLSurfaceView to render images. I've followed the 4K Display Mode API guide, and with that I hope to be able to select one of the 4K display modes available on my TV so that my GLSurfaceView can draw in physical resolution (code snippet shown below). However, the API constantly returns me one and only one display mode i.e. 1080p. This really bothers me, the hardware should support it as other built-in apps can use 4K, why doesn't it return a 4K display mode for my app?

I've also read through all relevant Android TV developer guide and wasn't able to find anything special. I'd really appreciate if anyone can shred me some light on this. Thanks!

public static void select4kDisplayMode(Context context, Window window) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }

    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Display.Mode[] modes = display.getSupportedModes();
    if (modes == null) {
        return;
    }

    Display.Mode selected = null;
    long max = 0;
    for (Display.Mode mode : modes) {
        FL.d(TAG, "available display mode: Mode %d: %dx%d/%.1ffps", mode.getModeId(),
                mode.getPhysicalWidth(), mode.getPhysicalHeight(),
                mode.getRefreshRate());
        long val = mode.getPhysicalWidth() * mode.getPhysicalHeight();
        if (val > max) {
            max = val;
            selected = mode;
        }
    }
    if (selected != null) {
        WindowManager.LayoutParams params = window.getAttributes();
        params.preferredDisplayModeId = selected.getModeId();
        window.setAttributes(params);

        FL.d(TAG, "selected display mode: Mode %d: %dx%d/%.1ffps", selected.getModeId(),
                selected.getPhysicalWidth(), selected.getPhysicalHeight(),
                selected.getRefreshRate());
    }
}
bosphere
  • 388
  • 3
  • 7
  • I'd recommend you to check related issue for ExoPlayer: https://github.com/google/ExoPlayer/issues/800 there're commits which adds detection of 4k on different API levels and devices – Michael Sotnikov Jun 20 '18 at 19:20
  • @MichaelSotnikov Thanks but I've already checked those. My understanding is if you want to display 4K, you need to firstly inform OS your choice of Display mode so that OS allocates you a Surface in native resolution. What's tracked in that issue is what I think the 2nd step: when you have a high-res surface to draw, you need to be able to choose your content in the matching quality. – bosphere Jun 21 '18 at 05:40
  • @bosphere I have the same problem. My conclusion is that low cost ARM CPU SoC can only manage 4K video but fullHD apps sufaces. I can get much more than fullHD in mobile phones and tablets, but no in android TV Xiaomi box S and low cost Amlogic S905X devices ... – Miguel Angel Pons Feb 13 '19 at 11:41

1 Answers1

1

I am a coder in China, I found that Android TV only support 1080p resolution to the Android App. It`s so confused me that I print the params of TV, and you can see the doc, it shows that you can render 4K video with the API in Android 6.0, but the native app only support 1080p in TV. here: android 6.0 how supports 4K

UsherChen
  • 11
  • 2