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

in android •  5 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)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!