diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index efd6c4a..c9fbc8f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,8 @@
+
implements SurfaceHolder.Callback {
+public class VideoActivity extends BaseActivity {
private CountDownTimer countDownTimer;
@@ -77,6 +69,7 @@ public class VideoActivity extends BaseActivity implements
image = intent.getStringExtra(KEY_image);
describe = intent.getStringExtra(KEY_image);
thumb = intent.getStringExtra(KEY_thumb);
+ vb.tvDescribe.setText(describe);
showLoading(true);
initFavorite();
@@ -94,7 +87,7 @@ public class VideoActivity extends BaseActivity implements
@Override
public void onVideoResult(boolean success, String path) {
- Common.logMsg("-------------success ="+success+"--path="+path);
+ Common.logMsg("-------------success =" + success + "--path=" + path);
runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -113,7 +106,7 @@ public class VideoActivity extends BaseActivity implements
}
- private void initFavorite(){
+ private void initFavorite() {
boolean b = Db.queryIsLike(id);
vb.imFavorite.setSelected(b);
}
@@ -137,19 +130,6 @@ public class VideoActivity extends BaseActivity implements
- @Override
- protected void onResume() {
- super.onResume();
-
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
-
- }
-
private void showLoading(boolean loading) {
if (loading) {
// vb.topLayout.setBackgroundColor(getColor(R.color.color_white_80));
@@ -199,7 +179,7 @@ public class VideoActivity extends BaseActivity implements
vb.imFavorite.setSelected(!vb.imFavorite.isSelected());
boolean selected = vb.imFavorite.isSelected();
if (selected) {
- LikeData likeData = new LikeData(describe, id, image, wallpaperType,thumb);
+ LikeData likeData = new LikeData(describe, id, image, wallpaperType, thumb);
Db.insertLike(likeData);
} else {
Db.deleteLike(id);
@@ -229,41 +209,23 @@ public class VideoActivity extends BaseActivity implements
}
- @Override
- public void surfaceCreated(@NonNull SurfaceHolder holder) {
- Common.logMsg("------------surfaceCreated");
- mySurfaceHolder = holder;
- checkPlay();
- }
-
- @Override
- public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
- Common.logMsg("------------surfaceChanged");
- }
-
- @Override
- public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
- Common.logMsg("------------surfaceDestroyed");
-
- }
-
@OptIn(markerClass = UnstableApi.class)
private void playMedia3() {
- try {
- Uri uriFromFilePath = Common.getUriFromFilePath(this, filePath);
- MediaItem mediaItem = MediaItem.fromUri(uriFromFilePath);
- ProgressiveMediaSource mediaSource = createMediaSource(mediaItem);
- exoPlayer.setMediaSource(mediaSource);
- exoPlayer.prepare();
- exoPlayer.play();
- }catch (Exception e){
- Common.logMsg("-------"+e.getMessage());
- }
+ try {
+ Uri uriFromFilePath = Common.getUriFromFilePath(this, filePath);
+ MediaItem mediaItem = MediaItem.fromUri(uriFromFilePath);
+ ProgressiveMediaSource mediaSource = createMediaSource(mediaItem);
+ exoPlayer.setMediaSource(mediaSource);
+ exoPlayer.prepare();
+ exoPlayer.play();
+ } catch (Exception e) {
+ Common.logMsg("-------" + e.getMessage());
+ }
}
@OptIn(markerClass = UnstableApi.class)
public ProgressiveMediaSource createMediaSource(MediaItem mediaItem) {
- DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
+ DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
this, "user-agent"
);
ProgressiveMediaSource.Factory factory = new ProgressiveMediaSource.Factory(dataSourceFactory);
@@ -271,33 +233,25 @@ public class VideoActivity extends BaseActivity implements
}
-
-
-
private void setLiveWallpaper() {
if (mFile.exists()) {
Shared.INSTANCE.setVideo_path(filePath);
Common.logMsg("----------setVideo_path---filePath=" + filePath);
}
- WallpaperManager instance = WallpaperManager.getInstance(VideoActivity.this);
+ WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
+ try {
+ wallpaperManager.clear();
+ Common.logMsg("----------clear=");
+ } catch (Exception e) {
+ Common.logMsg("---------e=" + e.getMessage());
+ }
ComponentName componentName = new ComponentName(VideoActivity.this, LiveWallpaperService.class);
- WallpaperInfo wallpaperInfo = instance.getWallpaperInfo();
-
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName);
startActivity(intent);
finish();
-// if((wallpaperInfo!= null)&&wallpaperInfo.getComponent()!= componentName){
-// Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
-// intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName);
-// startActivity(intent);
-// }else {
-// Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
-// intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName);
-// startActivity(intent);
-// }
}
diff --git a/app/src/main/java/com/live/mylivewallpaper/help/LiveWallpaperService.kt b/app/src/main/java/com/live/mylivewallpaper/help/LiveWallpaperService.kt
index 5c1c38c..2e76eb2 100644
--- a/app/src/main/java/com/live/mylivewallpaper/help/LiveWallpaperService.kt
+++ b/app/src/main/java/com/live/mylivewallpaper/help/LiveWallpaperService.kt
@@ -3,15 +3,14 @@ package com.live.mylivewallpaper.help
import android.content.Context
import android.net.Uri
import android.service.wallpaper.WallpaperService
-import android.view.Surface
import android.view.SurfaceHolder
import androidx.annotation.OptIn
+import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultDataSourceFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.ProgressiveMediaSource
-import com.live.mylivewallpaper.R
import java.io.File
@@ -25,10 +24,71 @@ class LiveWallpaperService : WallpaperService() {
inner class VideoWallpaperEngine : Engine() {
private var exoPlayer: ExoPlayer? = null
+
@OptIn(UnstableApi::class)
private fun initExoPlay() {
exoPlayer = ExoPlayer.Builder(this@LiveWallpaperService).build()
exoPlayer?.repeatMode = ExoPlayer.REPEAT_MODE_ONE
+ update()
+ }
+
+ override fun onCreate(surfaceHolder: SurfaceHolder?) {
+ super.onCreate(surfaceHolder)
+ Common.logMsg("-----Engine-----onCreate")
+ initExoPlay()
+
+ }
+
+ @OptIn(UnstableApi::class)
+ override fun onSurfaceCreated(holder: SurfaceHolder?) {
+ super.onSurfaceCreated(holder)
+ val surface = holder?.surface
+ if (surface != null) {
+ exoPlayer?.setVideoSurface(surface)
+ exoPlayer?.videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
+ }
+
+
+ }
+
+ override fun onVisibilityChanged(visible: Boolean) {
+ super.onVisibilityChanged(visible)
+ Common.logMsg("-------Engine---onVisibilityChanged visible=$visible")
+ if (visible) {
+ update()
+ exoPlayer?.play()
+ } else {
+ exoPlayer?.pause()
+ }
+ }
+
+
+ override fun onSurfaceDestroyed(holder: SurfaceHolder?) {
+ super.onSurfaceDestroyed(holder)
+ Common.logMsg("------Engine----onSurfaceDestroyed---")
+ exoPlayer?.release()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ Common.logMsg("-------Engine---onDestroy---")
+
+
+ }
+
+ @OptIn(UnstableApi::class)
+ override fun onSurfaceChanged(
+ holder: SurfaceHolder?,
+ format: Int,
+ width: Int,
+ height: Int
+ ) {
+ super.onSurfaceChanged(holder, format, width, height)
+
+ }
+
+ @OptIn(UnstableApi::class)
+ private fun update() {
val uri = getVideoUrl(this@LiveWallpaperService)
// val test = "android.resource://" + packageName + "/" + R.raw.test1
if (uri != null) {
@@ -40,81 +100,11 @@ class LiveWallpaperService : WallpaperService() {
exoPlayer?.prepare()
exoPlayer?.playWhenReady = true
}
-
-
- }
-
- override fun onCreate(surfaceHolder: SurfaceHolder?) {
- super.onCreate(surfaceHolder)
- Common.logMsg("-----Engine-----onCreate")
- initExoPlay()
- }
-
- override fun onSurfaceCreated(holder: SurfaceHolder?) {
- super.onSurfaceCreated(holder)
- val surface = holder?.surface
- if (surface != null) {
- exoPlayer?.setVideoSurface(surface)
- }
-
-
- }
-
- override fun onVisibilityChanged(visible: Boolean) {
- super.onVisibilityChanged(visible)
- Common.logMsg("-------Engine---onVisibilityChanged visible=$visible")
- if (visible) {
- exoPlayer?.play()
- } else {
- exoPlayer?.pause()
- }
- }
-
-
- override fun onSurfaceDestroyed(holder: SurfaceHolder?) {
- super.onSurfaceDestroyed(holder)
- Common.logMsg("------Engine----onSurfaceDestroyed---")
- }
-
- override fun onDestroy() {
- super.onDestroy()
- Common.logMsg("-------Engine---onDestroy---")
- exoPlayer?.release()
-
- }
-
- override fun onSurfaceChanged(
- holder: SurfaceHolder?,
- format: Int,
- width: Int,
- height: Int
- ) {
- super.onSurfaceChanged(holder, format, width, height)
- Common.logMsg("----------Engine---onSurfaceChanged")
-
}
}
- private fun adjustSurfaceViewSize(surface: Surface, containerWidth: Int, containerHeight: Int) {
- val videoWidth = 1920 // 假设视频宽度为 1920
- val videoHeight = 1080 // 假设视频高度为 1080
-
- // 计算视频的宽高比
- val videoAspectRatio = videoWidth.toFloat() / videoHeight
- var newWidth = containerWidth
- var newHeight = (containerWidth / videoAspectRatio).toInt()
-
- // 如果计算的高度大于容器高度,则调整为容器高度
- if (newHeight > containerHeight) {
- newHeight = containerHeight
- newWidth = (containerHeight * videoAspectRatio).toInt()
- }
-
- // 更新 SurfaceView 的布局参数
-// this.setLayoutParams(FrameLayout.LayoutParams(newWidth, newHeight))
- }
private fun getVideoUrl(con: Context): Uri? {
diff --git a/app/src/main/java/com/live/mylivewallpaper/paging/MyPagingSource.java b/app/src/main/java/com/live/mylivewallpaper/paging/MyPagingSource.java
index dfdded9..386cfad 100644
--- a/app/src/main/java/com/live/mylivewallpaper/paging/MyPagingSource.java
+++ b/app/src/main/java/com/live/mylivewallpaper/paging/MyPagingSource.java
@@ -36,7 +36,7 @@ public class MyPagingSource extends PagingSource {
int page = loadParams.getKey() != null ? loadParams.getKey() : 1;
List data = Db.queryData(wallpaperType,page);
- Common.logMsg("-----load---------"+wallpaperType+"----page="+page+"'--data="+data.size());
+// Common.logMsg("-----load---------"+wallpaperType+"----page="+page+"'--data="+data.size());
return new LoadResult.Page<>(
data,
page > 1 ? page - 1 : null,
diff --git a/app/src/main/res/layout/activity_video.xml b/app/src/main/res/layout/activity_video.xml
index 873c731..f76546d 100644
--- a/app/src/main/res/layout/activity_video.xml
+++ b/app/src/main/res/layout/activity_video.xml
@@ -8,18 +8,6 @@
android:background="@color/white"
tools:context=".activity.VideoActivity">
-
-
-
-
-
-
diff --git a/app/src/main/res/xml/wallpaper.xml b/app/src/main/res/xml/wallpaper.xml
index 0fb22c3..a8ad11a 100644
--- a/app/src/main/res/xml/wallpaper.xml
+++ b/app/src/main/res/xml/wallpaper.xml
@@ -2,5 +2,4 @@
-