I\'m making a live wallpaper that can show a video. In the beginning I thought this is going to be very hard, so some people suggested using OpenGL solu
I find this article: How to set video as live wallpaper and keep video aspect ratio(width and height)
above article has simple source, just click "set wallpaper" button, if you wanna full feature app, see https://github.com/AlynxZhou/alynx-live-wallpaper
the keypoint is use glsurfaceview instead of wallpaperservice default surfaceview, make custom glsurfaceview renderer, glsurfaceview can use opengl to display, so the question become "how to use glsurfaceview play video" or "how to use opengl play video"
how to use glsurfaceview instead of wallpaperservice default surfaceview:
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();
}
}