From d7409bc19fb561e7d5322feb2776401da9205eeb Mon Sep 17 00:00:00 2001 From: Gangphon Date: Fri, 2 Feb 2024 19:34:33 +0800 Subject: [PATCH] player --- .../com/xixun/xixunplayer/MainActivity.java | 4 +- .../main/java/com/xixun/xixunplayer/Prog.java | 16 ++-- .../{EleBorder.java => SrcBorder.java} | 4 +- .../{EleScroll.java => SrcScroll.java} | 4 +- .../{EleVideo.java => SrcVideo.java} | 4 +- .../com/xixun/xixunplayer/SrcVisitor.java | 95 +++++++++++++++++++ 6 files changed, 111 insertions(+), 16 deletions(-) rename XixunPlayer/app/src/main/java/com/xixun/xixunplayer/{EleBorder.java => SrcBorder.java} (95%) rename XixunPlayer/app/src/main/java/com/xixun/xixunplayer/{EleScroll.java => SrcScroll.java} (97%) rename XixunPlayer/app/src/main/java/com/xixun/xixunplayer/{EleVideo.java => SrcVideo.java} (97%) create mode 100644 XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVisitor.java 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 040342f..9851759 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/MainActivity.java @@ -577,8 +577,8 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra var page = page(progView.curAva); for(var layer : page.layers) for(var src : layer.srcs) if(src.view.getVisibility()==VISIBLE) { try { - if(src.view instanceof EleVideo) { - var view = (EleVideo) src.view; + if(src.view instanceof SrcVideo) { + var view = (SrcVideo) src.view; if(view.ijkPlayer!=null) { writer.append("VideoPlaying: ").append(String.valueOf(view.ijkPlayer.isPlaying())).append("\tCur/Dur: ").append(String.valueOf(view.ijkPlayer.getCurrentPosition())).append("/").append(String.valueOf(view.ijkPlayer.getDuration())).append("\n"); var mediaInfo = view.ijkPlayer.getMediaInfo(); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java index b4377c1..8726b0a 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/Prog.java @@ -73,16 +73,16 @@ public class Prog extends AbsLayout { var page = new Page(); page.repeatTimes = pageMap.intg("repeatTimes", 1); page.parse(pageMap.jslist("schedules")); - HashMap videoMap = new HashMap<>(); + HashMap videoMap = new HashMap<>(); for(int ll=layers.size()-1; ll>=0; ll--) { var layer = new Layer(); layer.isLoop = layers.get(ll).bool("repeat"); JSList sources = layers.get(ll).jslist("sources"); var border = layers.get(ll).jsmap("border"); - EleBorder bdEle = null; + SrcBorder bdEle = null; int bdWidth = 0, bdStart = 0xffff, bdEnd = 0; if(border!=null) { - bdEle = new EleBorder(Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"), context); + bdEle = new SrcBorder(Util.programDir+"/"+border.stnn("img"), border.stnn("eff"), border.intg("speed"), context); bdWidth = bdEle.img.getHeight(); } var src = new Source(); @@ -174,7 +174,7 @@ public class Prog extends AbsLayout { var speechRate = (float) source.dbl("voiceRate"); if(mode!=null ? mode.endsWith("roll") : (imgs.size()==1 && imgs.get(0).intg("picDuration")==0)) { var img = imgs.get(0); - src.view = new EleScroll(context, img); + src.view = new SrcScroll(context, img); if(hasTTS) { src.text = img.str("text"); if(src.text!=null) { @@ -225,7 +225,7 @@ public class Prog extends AbsLayout { } else if(src.type.equals("DigitalClock")) src.view = new SrcDigitalClock(context, source); else if(src.type.startsWith("DigitalClock")) src.view = new SrcDigiClock(context, source); else if(src.type.equals("AnalogClock")) src.view = new SrcAnaClock(geo.width, geo.height, Util.programDir + "/" + id, source, context); - else if(src.type.equals("Audio")) src.view = new EleVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, false); + else if(src.type.equals("Audio")) src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, false); else if(src.type.endsWith("Video")) { var isLive = src.type.startsWith("Live"); var url = source.str("url"); @@ -241,8 +241,8 @@ public class Prog extends AbsLayout { src.view = new SrcCopy(context, videoView); ((SrcCopy) src.view).scaleX = 0; } else { - src.view = new EleVideo(context, isLive ? url : Util.programDir+"/"+id, source.intg("vol", 100) / 100.0f, isLive); - videoMap.put(key, (EleVideo) src.view); + src.view = new SrcVideo(context, isLive ? url : Util.programDir+"/"+id, source.intg("vol", 100) / 100.0f, isLive); + videoMap.put(key, (SrcVideo) src.view); } } else if(src.type.equals("WebURL")) { var webView = new WebView(context); @@ -307,7 +307,7 @@ public class Prog extends AbsLayout { try { setVisibility(GONE); View view; - for(int cc=0; cc imgs = new ArrayList<>(); Rect rect = new Rect(); @@ -25,7 +25,7 @@ public class EleScroll extends View implements Choreographer.FrameCallback { int interval, cur, end, step; char effect; - public EleScroll(Context context, JSMap json) { + public SrcScroll(Context context, JSMap json) { super(context); var img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id")); imgsWidth = img.getWidth(); diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java similarity index 97% rename from XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java rename to XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java index f15c370..a6e2bc8 100644 --- a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/EleVideo.java +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVideo.java @@ -16,7 +16,7 @@ import androidx.media3.exoplayer.SeekParameters; import tv.danmaku.ijk.media.player.IMediaPlayer; import tv.danmaku.ijk.media.player.IjkMediaPlayer; -public class EleVideo extends TextureView implements TextureView.SurfaceTextureListener { +public class SrcVideo extends TextureView implements TextureView.SurfaceTextureListener { String path; float vol; @@ -25,7 +25,7 @@ public class EleVideo extends TextureView implements TextureView.SurfaceTextureL long bitRate; boolean isLive; - public EleVideo(Context context, String path, float vol, boolean isLive) { + public SrcVideo(Context context, String path, float vol, boolean isLive) { super(context); this.path = path; this.vol = vol; diff --git a/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVisitor.java b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVisitor.java new file mode 100644 index 0000000..86f4406 --- /dev/null +++ b/XixunPlayer/app/src/main/java/com/xixun/xixunplayer/SrcVisitor.java @@ -0,0 +1,95 @@ +package com.xixun.xixunplayer; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.webkit.WebView; + +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.regex.Pattern; + +import gnph.util.IOs; +import gnph.util.JSList; +import gnph.util.JSMap; +import gnph.util.NumFmts; +import gnph.util.Txts; +import gnph.util.URLConn; + +@SuppressLint("ViewConstructor") +public class SrcVisitor extends WebView { + + String html, lineHeight, prefix, url; + + public SrcVisitor(Context context, JSMap json) { + super(context); + setBackgroundColor(Color.TRANSPARENT); + setVerticalScrollBarEnabled(false); + setHorizontalScrollBarEnabled(false); + setInitialScale(100); + html = json.stnn("html").replace("%{yesterday.", "%{arr.-1."); + lineHeight = json.str("lineHeight"); + url = json.str("url"); + prefix = ""; + } + + public void refresh() { + try { + var htm = html; + try { + var res = JSMap.fromClose(new URLConn(url).in()).jsmap("data"); + int lastEnd = 0, appendIdx = 0; + var buf = new StringBuilder(htm.length()*3/2); + int start; + while((start = htm.indexOf("%{", lastEnd)) > -1) { + int fds = start+2, fde = start+2; + try { + for(; fde<=fds+16; fde++) if(htm.charAt(fde)=='}') break; + if(fde > fds+16) { + lastEnd = fds; + continue; + } + lastEnd = fde+1; + if(fde == fds) continue; + var fd = htm.substring(fds, fde); + var replace = res.str(fd); + if(replace!=null) { + buf.append(htm, appendIdx, start).append(replace); + appendIdx = lastEnd; + } + Util.println("Found: " + htm.substring(start, lastEnd)+" fd "+fd); + } catch (Exception e) { + lastEnd = fds; + Util.printStackTrace(e); + } + } + if(buf.length()>0) { + if(appendIdx < htm.length()) buf.append(htm, appendIdx, htm.length()); + htm = buf.toString(); + } + } catch (Exception e) { + Util.printStackTrace(e); + } + loadDataWithBaseURL(null, prefix+htm+"", "text/html", "UTF-8", null); + } catch (Exception e) { + Util.printStackTrace(e); + } + } + + long nextMs; + + @Override + public void onVisibilityAggregated(boolean isVisible) { + super.onVisibilityAggregated(isVisible); + if(isVisible) { + var ms = System.currentTimeMillis(); + if(ms>=nextMs) { + nextMs += 15000; + refresh(); + } + } + } +}