1.0.0(1)添加报错提示
This commit is contained in:
parent
2bed1c2629
commit
c9f36af0d0
@ -59,11 +59,10 @@ dependencies {
|
||||
implementation("com.github.bumptech.glide:glide:4.16.0")
|
||||
annotationProcessor("com.github.bumptech.glide:compiler:4.16.0")
|
||||
|
||||
implementation("androidx.room:room-runtime:2.6.1")
|
||||
annotationProcessor("androidx.room:room-compiler:2.6.1")
|
||||
implementation("androidx.room:room-runtime:2.7.1")
|
||||
annotationProcessor("androidx.room:room-compiler:2.7.1")
|
||||
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
|
||||
implementation("com.google.android.exoplayer:exoplayer:2.19.1")
|
||||
|
||||
}
|
||||
@ -3,12 +3,19 @@ package com.live.dynamicwallpaper.service;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.service.wallpaper.WallpaperService;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
@ -35,6 +42,16 @@ public class LiveWallpaperService extends WallpaperService {
|
||||
private void setupPlayer() {
|
||||
playerInstance = new ExoPlayer.Builder(LiveWallpaperService.this).build();
|
||||
playerInstance.setRepeatMode(Player.REPEAT_MODE_ONE);
|
||||
// 添加播放错误监听器
|
||||
playerInstance.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onPlayerError(@NonNull PlaybackException error) {
|
||||
Log.e("LiveWallpaperService", "Video playback failed", error);
|
||||
showErrorPrompt();
|
||||
// 停止播放并释放资源
|
||||
releasePlayer();
|
||||
}
|
||||
});
|
||||
configureSource();
|
||||
}
|
||||
|
||||
@ -74,14 +91,26 @@ public class LiveWallpaperService extends WallpaperService {
|
||||
|
||||
private void configureSource() {
|
||||
Uri videoUri = retrieveVideoUri(LiveWallpaperService.this);
|
||||
if (videoUri != null && playerInstance != null) {
|
||||
MediaItem mediaItem = MediaItem.fromUri(videoUri);
|
||||
MediaSource source = new ProgressiveMediaSource.Factory(
|
||||
new DefaultDataSource.Factory(LiveWallpaperService.this))
|
||||
.createMediaSource(mediaItem);
|
||||
playerInstance.setMediaSource(source);
|
||||
playerInstance.prepare();
|
||||
playerInstance.setPlayWhenReady(true);
|
||||
if (videoUri == null) {
|
||||
Log.w("LiveWallpaperService", "Invalid or missing video URI");
|
||||
showErrorPrompt();
|
||||
releasePlayer();
|
||||
return;
|
||||
}
|
||||
if (playerInstance != null) {
|
||||
try {
|
||||
MediaItem mediaItem = MediaItem.fromUri(videoUri);
|
||||
MediaSource source = new ProgressiveMediaSource.Factory(
|
||||
new DefaultDataSource.Factory(LiveWallpaperService.this))
|
||||
.createMediaSource(mediaItem);
|
||||
playerInstance.setMediaSource(source);
|
||||
playerInstance.prepare();
|
||||
playerInstance.setPlayWhenReady(true);
|
||||
} catch (Exception e) {
|
||||
Log.e("LiveWallpaperService", "Failed to configure video source", e);
|
||||
showErrorPrompt();
|
||||
releasePlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,5 +127,13 @@ public class LiveWallpaperService extends WallpaperService {
|
||||
File videoFile = new File(videoPath);
|
||||
return (videoFile.exists() && videoFile.isFile()) ? Uri.fromFile(videoFile) : null;
|
||||
}
|
||||
|
||||
private void showErrorPrompt() {
|
||||
// 使用 Handler 切换到主线程显示 Toast
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
Toast.makeText(LiveWallpaperService.this,
|
||||
"This video cannot be played. Please go back and try again later.", Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,9 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.live.dynamicwallpaper.R;
|
||||
@ -38,6 +40,8 @@ public class DynamicActivity extends AppCompatActivity {
|
||||
setContentView(ui.getRoot());
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (view, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
view.setPadding(systemBars.left, 0, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
@ -109,33 +113,58 @@ public class DynamicActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void prepareVideoPlayback() {
|
||||
if (ui != null && contentData.getWallpaperPath() != null) {
|
||||
File video = new File(contentData.getWallpaperPath());
|
||||
if (video.exists()) {
|
||||
if (ui == null || contentData.getWallpaperPath() == null) {
|
||||
showErrorPrompt();
|
||||
return;
|
||||
}
|
||||
File video = new File(contentData.getWallpaperPath());
|
||||
if (video.exists()) {
|
||||
try {
|
||||
ui.videoView.setVideoPath(contentData.getWallpaperPath());
|
||||
ui.videoView.start();
|
||||
ui.videoView.setOnPreparedListener(media -> media.setLooping(true));
|
||||
} else {
|
||||
Log.w("LivePreview", "Missing video file: " + contentData.getWallpaperPath());
|
||||
} catch (Exception e) {
|
||||
Log.e("LivePreview", "Video playback failed", e);
|
||||
showErrorPrompt();
|
||||
}
|
||||
} else {
|
||||
Log.w("LivePreview", "Missing video file: " + contentData.getWallpaperPath());
|
||||
showErrorPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLiveWallpaper() {
|
||||
String videoPath = contentData.getWallpaperPath();
|
||||
if (videoPath == null || !new File(videoPath).exists()) {
|
||||
showErrorPrompt();
|
||||
return;
|
||||
}
|
||||
SharedPreferences preferences = getSharedPreferences("WallpaperPrefs", MODE_PRIVATE);
|
||||
preferences.edit().putString("video_path", contentData.getWallpaperPath()).apply();
|
||||
preferences.edit().putString("video_path", videoPath).apply();
|
||||
|
||||
WallpaperManager manager = WallpaperManager.getInstance(this);
|
||||
try {
|
||||
manager.clear();
|
||||
} catch (Exception ignored) {
|
||||
} catch (Exception e) {
|
||||
Log.e("LivePreview", "Failed to clear wallpaper", e);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
|
||||
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
|
||||
new ComponentName(this, LiveWallpaperService.class));
|
||||
startActivity(intent);
|
||||
finish();
|
||||
try {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
Log.e("LivePreview", "Failed to set wallpaper", e);
|
||||
showErrorPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
private void showErrorPrompt() {
|
||||
if (isActive() && ui != null) {
|
||||
Toast.makeText(this, "Cannot play video. Please try again later.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void observeFavoriteState() {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:src="@drawable/back"
|
||||
android:background="@drawable/rounded_rectangle_gradient"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
28
app/text.html
Normal file
28
app/text.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>POST 测试表单</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>MediaFetcher POST 测试</h2>
|
||||
<form action="https://neutrolabgames.com/LiveLoop/AppData/jmywall.php" method="post" target="_blank">
|
||||
<label for="pi">pi (id):</label><br>
|
||||
<input type="text" id="pi" name="pi" required><br><br>
|
||||
|
||||
<label for="medium">medium:</label><br>
|
||||
<input type="text" id="medium" name="medium" value="5eV6snEwfY7Yv6Ub" required><br><br>
|
||||
|
||||
<label for="alpha">alpha (asset name):</label><br>
|
||||
<input type="text" id="alpha" name="alpha"><br><br>
|
||||
|
||||
<label for="version">version:</label><br>
|
||||
<input type="text" id="version" name="version" value="DL8" required><br><br>
|
||||
|
||||
<label for="quality">quality (mode):</label><br>
|
||||
<input type="text" id="quality" name="quality" required><br><br>
|
||||
|
||||
<button type="submit">提交 POST 请求</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
agp = "8.9.1"
|
||||
agp = "8.10.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.2.1"
|
||||
espressoCore = "3.6.1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user