Здравствуйте, я нашел решение для моей проблемы:
в Kotlin Android:
класс VideoLiveWallpaperService: WallpaperService () {
override fun onCreateEngine(): WallpaperService.Engine {
return VideoEngine()
}
internal inner class VideoEngine : WallpaperService.Engine() {
private val TAG = javaClass.simpleName
private val mediaPlayer: MediaPlayer
init {
Log.i(TAG, "( VideoEngine )")
mediaPlayer = MediaPlayer.create(baseContext, R.raw.video1)
mediaPlayer.isLooping = true
}
override fun onSurfaceCreated(holder: SurfaceHolder) {
Log.i(TAG, "onSurfaceCreated")
mediaPlayer.setSurface(holder.surface)
mediaPlayer.start()
}
override fun onSurfaceDestroyed(holder: SurfaceHolder) {
Log.i(TAG, "( INativeWallpaperEngine ): onSurfaceDestroyed")
playheadTime = mediaPlayer.currentPosition
mediaPlayer.reset()
mediaPlayer.release()
}
}
companion object {
protected var playheadTime = 0
}
}
в Java:
public class VideoWallpaperService extends WallpaperService
{
protected static int playheadTime = 0;
@Override
public Engine onCreateEngine()
{
return new VideoEngine();
}
class VideoEngine extends Engine
{
private final String TAG = getClass().getSimpleName();
private final MediaPlayer mediaPlayer;
public VideoEngine()
{
super();
Log.i( TAG, "( VideoEngine )");
mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.wallpapervideo);
mediaPlayer.setLooping(true);
}
@Override
public void onSurfaceCreated( SurfaceHolder holder )
{
Log.i( TAG, "onSurfaceCreated" );
mediaPlayer.setSurface(holder.getSurface());
mediaPlayer.start();
}
@Override
public void onSurfaceDestroyed( SurfaceHolder holder )
{
Log.i( TAG, "( INativeWallpaperEngine ): onSurfaceDestroyed" );
playheadTime = mediaPlayer.getCurrentPosition();
mediaPlayer.reset();
mediaPlayer.release();
}
}
}
в манифесте: <service android:name=".VideoLiveWallpaperService"
android:label="Video live wallpaper" android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="@xml/wallpaper" />
</service>
в разрешении / xml / wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android" />