From db4c46e7e9b41ffc0817d793d7970d9c78a982b9 Mon Sep 17 00:00:00 2001 From: Gangphon Date: Sat, 11 May 2024 21:12:39 +0800 Subject: [PATCH] player --- XixunPlayer/app/build.gradle | 2 +- .../com/xixun/command/reply/ReplyBase.java | 10 ++++++ .../command/reply/TaskProgressReply.java | 18 ++++++++++ .../java/com/xixun/xixunplayer/BackView.java | 7 ++-- .../java/com/xixun/xixunplayer/Server.java | 35 ++++++++++++------- .../com/xixun/xixunplayer/SocketThread.java | 2 +- .../java/com/xixun/xixunplayer/SrcVideo.java | 2 +- .../main/java/com/xixun/xixunplayer/Util.java | 5 +++ 8 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 XixunPlayer/app/src/main/java/com/xixun/command/reply/ReplyBase.java create mode 100644 XixunPlayer/app/src/main/java/com/xixun/command/reply/TaskProgressReply.java diff --git a/XixunPlayer/app/build.gradle b/XixunPlayer/app/build.gradle index 6dddf53..2bcaf2e 100644 --- a/XixunPlayer/app/build.gradle +++ b/XixunPlayer/app/build.gradle @@ -11,7 +11,7 @@ android { minSdk 21 targetSdk 34 versionCode 1 - versionName "2.1" + versionName "2.1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/XixunPlayer/app/src/main/java/com/xixun/command/reply/ReplyBase.java b/XixunPlayer/app/src/main/java/com/xixun/command/reply/ReplyBase.java new file mode 100644 index 0000000..d2f446a --- /dev/null +++ b/XixunPlayer/app/src/main/java/com/xixun/command/reply/ReplyBase.java @@ -0,0 +1,10 @@ +package com.xixun.command.reply; + +import java.io.Serializable; + + +public abstract class ReplyBase implements Serializable{ + + private static final long serialVersionUID = -3630726876519388513L; + public String commandId; +} diff --git a/XixunPlayer/app/src/main/java/com/xixun/command/reply/TaskProgressReply.java b/XixunPlayer/app/src/main/java/com/xixun/command/reply/TaskProgressReply.java new file mode 100644 index 0000000..54b2a64 --- /dev/null +++ b/XixunPlayer/app/src/main/java/com/xixun/command/reply/TaskProgressReply.java @@ -0,0 +1,18 @@ +package com.xixun.command.reply; + +public class TaskProgressReply extends ReplyBase { + + private static final long serialVersionUID = 6264049742389542806L; + public int percent; + public String taskItemId; + public int speed; + public int remainingSeconds; + + public TaskProgressReply(String commandId, String taskItemId, int percent, int sp, int rs) { + this.commandId = commandId; + this.taskItemId = taskItemId; + this.percent = percent; + this.speed = sp; + this.remainingSeconds = rs; + } +} \ No newline at end of file diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/BackView.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/BackView.java index cd40933..d8a129c 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/BackView.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/BackView.java @@ -10,13 +10,14 @@ import android.view.View; public class BackView extends View { - public Bitmap img, cosImg; + private Bitmap img; + Bitmap cosImg; Rect rect = new Rect(); public BackView(Context context, int width, int height) { super(context); - img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back); - cosImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/XixunPlayer/background"); + img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back, Util.noScaled); + cosImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/XixunPlayer/background", Util.noScaled); rect.right = width; rect.bottom = height; } diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java index 0a22f64..b3ff60f 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java @@ -7,12 +7,12 @@ import android.graphics.BitmapFactory; import android.os.IBinder; import android.os.RemoteException; +import com.xixun.command.reply.TaskProgressReply; import com.xixun.util.PlayerInfo; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; @@ -181,24 +181,35 @@ public class Server extends Service { Util.printStackTrace(e); } cnt++; - if(notificationURL!=null && cnt!=needDown.srcs.size()) { - try { - new URLConn(notificationURL).timeout(5000).writeJson(new JSMap( - "commandId", finalCommandId, - "taskItemId", needDown.prog, - "progress", cnt*100/needDown.srcs.size()).toStr()).read(); - } catch (IOException e) { - Util.printStackTrace(e); + var progress = cnt*100/needDown.srcs.size(); + if(cnt != needDown.srcs.size()) { + if(notificationURL==null) { + var intent = new Intent("xixun.intent.action.REPLY"); + intent.putExtra("reply", new TaskProgressReply(finalCommandId, needDown.prog, progress, 500, 3)); + MainActivity.ins.sendBroadcast(intent); + } else { + try { + new URLConn(notificationURL).timeout(5000).writeJson(new JSMap( + "commandId", finalCommandId, + "taskItemId", needDown.prog, + "progress", progress).toStr()).read(); + } catch (Exception e) { + Util.printStackTrace(e); + } } } } - if(notificationURL!=null) { + if(notificationURL==null) { + var intent = new Intent("xixun.intent.action.REPLY"); + intent.putExtra("reply", new TaskProgressReply(finalCommandId, needDown.prog, 100, 400, 0)); + MainActivity.ins.sendBroadcast(intent); + } else { try { new URLConn(notificationURL).timeout(5000).writeJson(new JSMap( "commandId", finalCommandId, "taskItemId", needDown.prog, "progress", 100).toStr()).read(); - } catch (IOException e) { + } catch (Exception e) { Util.printStackTrace(e); } } @@ -240,7 +251,7 @@ public class Server extends Service { fout.close(); } MainActivity.ins.runOnUiThread(() -> { - MainActivity.ins.backView.cosImg = url==null ? null : BitmapFactory.decodeFile(Util.backImgFile); + MainActivity.ins.backView.cosImg = url==null ? null : BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled); MainActivity.ins.backView.invalidate(); }); return new JSMap( diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java index 1fe7043..38cbde8 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java @@ -86,7 +86,7 @@ public class SocketThread extends Thread { fout.getFD().sync(); fout.close(); main.runOnUiThread(() -> { - main.backView.cosImg = BitmapFactory.decodeFile(Util.backImgFile); + main.backView.cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled); main.backView.invalidate(); }); } else if("imgFileEnd".equals(_type)) { diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java index 457fca5..d1c0cd8 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java @@ -46,7 +46,7 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL } void initIjk() { ijkPlayer = new IjkMediaPlayer(); - ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1); + //ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java index c6a57e6..f603080 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Util.java @@ -1,6 +1,7 @@ package com.xixun.xixunplayer; import android.content.Context; +import android.graphics.BitmapFactory; import android.os.Environment; import android.os.StatFs; import android.view.Gravity; @@ -25,6 +26,10 @@ public class Util { public static int screenWidth, screenHeight; public static boolean isScreenOn; + public static final BitmapFactory.Options noScaled = new BitmapFactory.Options(); + static { + noScaled.inScaled = false; + } public static final Vector socketThreads = new Vector<>(); public static final HashMap stateDescs = new HashMap<>(); static {