import Context from 'android.content.Context';
import Engine from 'android.service.wallpaper.WallpaperService.Engine';
import WallpaperService from 'android.service.wallpaper.WallpaperService';
import SurfaceHolder from 'android.view.SurfaceHolder';
import MediaPlayer from 'android.media.MediaPlayer';
import UTSAndroid from 'io.dcloud.uts.UTSAndroid';
import * as SpUtil from "./SpUtil.uts"
export class JnWallpaperService extends WallpaperService {
constructor() {
super()
}
override onCreateEngine(): Engine {
console.log('onCreateEngine');
return MyEngine();
}
MyEngine = class extends Engine {
private mp: MediaPlayer | null = null
constructor() {
super()
this.mp = new MediaPlayer()
}
override onCreate(surfaceHolder: SurfaceHolder) {
console.log('引擎创建');
super.onCreate(surfaceHolder);
}
override onDestroy() {
console.log('引擎注销');
super.onDestroy()
}
override onVisibilityChanged(visible: boolean) {
}
override onSurfaceCreated(holder: SurfaceHolder) {
console.log('Surface创建3');
this.mp!.setSurface(holder.getSurface());
try {
let tmp ='https://mp-c286fa93-2e46-4ca6-8f4b-bd8f0dca1b03.cdn.bspapp.com/VKCEYUGU-c286fa93-2e46-4ca6-8f4b-bd8f0dca1b03/8c6bb959-319a-4ecd-9db3-7e44b151a2a8.mp4'
this.mp!.setDataSource(tmp);
this.mp!.setLooping(true);
this.mp!.prepare();
this.mp!.start();
} catch (e) {
console.log(e);
}
}
override onSurfaceDestroyed(holder: SurfaceHolder) {
console.log('Surface注销');
this.mp!.release();
this.mp = null;
}
}
}
打了个结
重启系统已经有了
2023-07-20 08:17