From 0d95ad356fd0478caad08e8db2fe4cdf06e45baf Mon Sep 17 00:00:00 2001 From: Gangphon Date: Thu, 4 Jul 2024 17:45:56 +0800 Subject: [PATCH] player --- .../com/xixun/xixunplayer/MainActivity.java | 16 +++--- .../java/com/xixun/xixunplayer/Server.java | 10 +++- .../com/xixun/xixunplayer/SocketThread.java | 54 ++++++++++++++++--- .../com/xixun/xixunplayer/SrcEnviron.java | 9 +++- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java index 696ef82..6e908db 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java @@ -212,7 +212,10 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac var code = intent.getIntExtra("code", 0); Util.println(" remote_control "+code); if(progView == null || ! progView.isShown() || code > progView.pages.size()) return; - if(! progView.avas.isEmpty()) progView.curAva().hide(); + if(! progView.avas.isEmpty()) { + progView.curAva().hide(); + if(progView.avas.size()==1 && progView.avas.get(0)==code-1) for(var call : progView.calls) call.doFrame(System.currentTimeMillis()); + } var millis = (System.currentTimeMillis()+999)/1000*1000; if(code > 0) { progView.avas.clear(); @@ -255,16 +258,13 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac var zip = new ZipFile(path+"/program.zip"); if(zip.isEncrypted()) zip.setPassword(pass); long size = 0; - ByteArrayOutputStream progJson = null; + ByteArrayOutputStream jsonOut = null; var headers = zip.getFileHeaders(); for(var header : headers) { size += header.getUncompressedSize(); - if("program".equals(header.getFileName())) { - progJson = new ByteArrayOutputStream(); - IOs.writeClose(progJson, zip.getInputStream(header)); - } + if("program".equals(header.getFileName())) IOs.writeClose(jsonOut = new ByteArrayOutputStream(), zip.getInputStream(header)); } - if(progJson==null) { + if(jsonOut==null) { Util.println("No program File"); runOnUiThread(() -> Util.makeText(MainActivity.this, "No program File").show()); return; @@ -283,7 +283,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac fOut.getFD().sync(); fOut.close(); } - var json = progJson.toByteArray(); + var json = jsonOut.toByteArray(); runOnUiThread(() -> { Util.println("Import Succeed"); Util.makeText(MainActivity.this, "Import Succeed 导入成功\nDon't shut down within 1 minute, otherwise the program may be lost\n不要在 1 分钟内关机,否则节目可能丢失").show(); 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 b3ff60f..f6766d3 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Server.java @@ -34,7 +34,11 @@ public class Server extends Service { @Override public String getProgramName() throws RemoteException { try { - var name = MainActivity.ins!=null && MainActivity.ins.progView!=null && ! MainActivity.ins.progView.avas.isEmpty() ? MainActivity.ins.progView.curAva().name : null; + String name = null; + if(MainActivity.ins!=null) { + if(MainActivity.ins.insView!=null && ! MainActivity.ins.insView.avas.isEmpty()) name = MainActivity.ins.insView.curAva().name; + else if(MainActivity.ins.progView!=null && ! MainActivity.ins.progView.avas.isEmpty()) name = MainActivity.ins.progView.curAva().name; + } Util.println("Server getProgramName. <-"+name); return name; } catch (Exception e) { @@ -312,7 +316,9 @@ public class Server extends Service { @Override public int countOfPrograms(int type) throws RemoteException { - return 0; + var cnt = MainActivity.ins!=null && MainActivity.ins.progView!=null ? MainActivity.ins.progView.pages.size() : 0; + Util.println("Server countOfPrograms. <-"+cnt); + return cnt; } @Override 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 3d4c8ad..45cb919 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SocketThread.java @@ -11,6 +11,8 @@ import android.webkit.WebView; import androidx.annotation.OptIn; import androidx.media3.common.util.UnstableApi; +import net.lingala.zip4j.ZipFile; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -111,6 +113,45 @@ public class SocketThread extends Thread { progJson = null; main.runOnUiThread(() -> main.initProg(json)); } + } else if("playZipTask".equals(_type)) { + var zip = new ZipFile(Util.programDir+"/"+obj.stnn("proName")); + if(zip.isEncrypted()) zip.setPassword(new char[]{'8','8','8'}); + long size = 0; + ByteArrayOutputStream jsonOut = null; + try { + var headers = zip.getFileHeaders(); + for(var header : headers) { + size += header.getUncompressedSize(); + if("program".equals(header.getFileName())) IOs.writeClose(jsonOut = new ByteArrayOutputStream(), zip.getInputStream(header)); + } + if(jsonOut==null) { + Util.println("No 'program' File"); + new JSMap("success", false, "msg", "No 'program' File").write(out); + main.runOnUiThread(() -> Util.makeText(main, "No program File").show()); + } else if(size==0) { + Util.println("Zip Size is 0"); + new JSMap("success", false, "msg", "Zip Size is 0").write(out); + main.runOnUiThread(() -> Util.makeText(main, "zip size is 0").show()); + } else { + Util.deleteFiles(size, null); + for(var header : headers) if(! "program".equals(header.getFileName())) { + Util.println(" name: " + header.getFileName()); + var fOut = new FileOutputStream(Util.programDir + "/" + header.getFileName()); + IOs.writeCloseIn(fOut, zip.getInputStream(header)); + fOut.flush(); + fOut.getFD().sync(); + fOut.close(); + } + var json = jsonOut.toByteArray(); + main.runOnUiThread(()->main.initProg(json)); + Util.println(" Succeed"); + new JSMap("success", true).write(out); + } + } catch (Exception e) { + Util.printStackTrace(e); + new JSMap("success", false).write(out); + main.runOnUiThread(() -> Util.makeText(main, Util.toStr(e)).show()); + } } else if("DelPrograms".equals(_type)) { var latch = new CountDownLatch(1); var ok = new AtomicBoolean(false); @@ -217,12 +258,13 @@ public class SocketThread extends Thread { out.write(Util.buf.toString().getBytes()); } else if("ListProgFiles".equals(_type)) { var files = new File(Util.programDir).listFiles(); - if(files == null) return; - Arrays.sort(files, (f1, f2) -> (int) (f2.lastModified() - f1.lastModified())); - var writer = new OutputStreamWriter(out); - for(var file : files) writer.append(fmt.format(new Date(file.lastModified()))).append(' ').append(file.getName()).append(' ').append(String.valueOf(file.length())).append('\n'); - writer.append('\n'); - writer.flush(); + if(files!=null) { + Arrays.sort(files, (f1, f2) -> (int) (f2.lastModified() - f1.lastModified())); + var writer = new OutputStreamWriter(out); + for(var file : files) writer.append(fmt.format(new Date(file.lastModified()))).append(' ').append(file.getName()).append(' ').append(String.valueOf(file.length())).append('\n'); + writer.append('\n'); + writer.flush(); + } } else if("GetFile".equals(_type)) { var name = obj.str("name"); if(name==null) new JSMap("msg", "name is null").write(out); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java index a8ca205..cfc5153 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcEnviron.java @@ -126,8 +126,13 @@ public class SrcEnviron extends View implements Choreographer.FrameCallback, Int item.nums.clear(); if(item.unit==null) { var num = intent.getIntExtra(item.key, -1); - if(num>=0 && num<=15) item.nums.add(imgMap.get(directs[num])); - else { + if(num>=0 && num<=15) { + if(directs[num].length() < 3) item.nums.add(imgMap.get(directs[num])); + else { + item.nums.add(imgMap.get(directs[num].substring(0, 1))); + item.nums.add(imgMap.get(directs[num].substring(1))); + } + } else { var img = imgMap.get("-"); item.nums.add(img); item.nums.add(img);