gpt4 book ai didi

java - 在android中将视频设置为SET WALLPAPER?

转载 作者:行者123 更新时间:2023-11-29 23:22:34 33 4
gpt4 key购买 nike

我想将视频设置为墙纸,就像 ZEDGE Wallpaper 和其他墙纸应用程序在 Play 商店中所做的那样。以下是 ZEDGE Wallpaper 应用程序的屏幕截图,该应用程序将视频设置为 android 中的墙纸。 enter image description here

我使用下面的代码将图像用作墙纸:

  val intentt = Intent(Intent.ACTION_ATTACH_DATA)
.setDataAndType(uri, "image/*")
.putExtra("mimeType", "image/*")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)


startActivityForResult(Intent.createChooser(intentt, getString(R.string.setas)), 1)

如何将视频设置为墙纸?

最佳答案

您好,我找到了解决问题的方法:

在 Kotlin Android 中:

    class 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();
}
}

在 list 中:

<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>

在 res/xml/wallpaper.xml 中:

<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android" />

关于java - 在android中将视频设置为SET WALLPAPER?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53995053/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com