How to set video as live wallpaper and keep video aspect ratio(width and height)

in #android5 years ago

How to set video as live wallpaper and keep video aspect ratio(width and height)
Article from: https://medium.com/@rorocotech/how-to-set-video-as-live-wallpaper-and-keep-video-aspect-ratio-width-and-height-f4599c7b0619
Source code: https://gum.co/FDpFtSource code backup: https://www.patreon.com/posts/34436289
I see this https://sh.alynx.moe/posts/Android-Video-Wallpaper-Implementation/
and here is above article’s source: https://github.com/AlynxZhou/alynx-live-wallpaper
the key point is following code, use GLSurfaceView instead default WallpaperService surface, glsurfaceview can use opengl, the question become “how to use glsurfaceview play video” or “how to use opengl play video”
public class GLWallpaperService extends WallpaperService {... class GLWallpaperEngine extends Engine {... private class GLWallpaperSurfaceView extends GLSurfaceView { @SuppressWarnings("unused") private static final String TAG = "GLWallpaperSurface"; public GLWallpaperSurfaceView(Context context) { super(context); } /** * This is a hack. Because Android Live Wallpaper only has a Surface. * So we create a GLSurfaceView, and when drawing to its Surface, * we replace it with WallpaperEngine's Surface. */ @Override public SurfaceHolder getHolder() { return getSurfaceHolder(); } void onDestroy() { super.onDetachedFromWindow(); } }
above code override GLSurfaceView#getHolder will make GLSurfaceView instead of default surface
and in WallpaperService.Engine#onSurfaceCreated, use following
glSurfaceView = new GLWallpaperSurfaceView(context)

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 62182.25
ETH 2437.70
USDT 1.00
SBD 2.61