xixunplayer

This commit is contained in:
Gangphon 2023-11-10 09:47:38 +08:00
parent 930982c3d6
commit 9b9141ddf7
9 changed files with 110 additions and 79 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -36,7 +36,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
Bitmap title; Bitmap title;
ArrayList<Item> items = new ArrayList<>(); ArrayList<Item> items = new ArrayList<>();
MainActivity act; MainActivity act;
int spaceWidth; int spaceWidth, digitHeight;
int interval, cur, end, step; int interval, cur, end, step;
boolean isScroll, isFirst = true; boolean isScroll, isFirst = true;
@ -70,6 +70,7 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
if(json.bool("bPM25")) items.add(new Item("pm2.5", imgMap.remove("labelpm25"), imgMap.get("unit_pm10"))); if(json.bool("bPM25")) items.add(new Item("pm2.5", imgMap.remove("labelpm25"), imgMap.get("unit_pm10")));
if(json.bool("bPM10")) items.add(new Item("pm10", imgMap.remove("labelpm10"), imgMap.get("unit_pm10"))); if(json.bool("bPM10")) items.add(new Item("pm10", imgMap.remove("labelpm10"), imgMap.get("unit_pm10")));
} }
digitHeight = imgMap.get("0").getHeight();
var scrollSpeed = json.dbl("scrollSpeed"); var scrollSpeed = json.dbl("scrollSpeed");
if(scrollSpeed==0) { if(scrollSpeed==0) {
var scrollDur = json.dbl("iScrollSpeed"); var scrollDur = json.dbl("iScrollSpeed");
@ -128,11 +129,13 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
canvas.drawBitmap(title, x, Math.round((getHeight() - title.getHeight()) / 2), null); canvas.drawBitmap(title, x, Math.round((getHeight() - title.getHeight()) / 2), null);
x += title.getWidth() + spaceWidth<<1; x += title.getWidth() + spaceWidth<<1;
} }
var y = (int) Math.round((getHeight() - digitHeight) / 2);
for(var item : items) { for(var item : items) {
var y = (int) Math.round((getHeight() - item.lable.getHeight()) / 2); if(item.lable!=null) {
canvas.drawBitmap(item.lable, x, y, null); canvas.drawBitmap(item.lable, x, y, null);
x += item.lable.getWidth(); x += item.lable.getWidth();
for(var num : item.nums) { }
for(var num : item.nums) if(num!=null) {
canvas.drawBitmap(num, x, y, null); canvas.drawBitmap(num, x, y, null);
x += num.getWidth(); x += num.getWidth();
} }
@ -150,10 +153,13 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
int i = 0; int i = 0;
if(title!=null) canvas.drawBitmap(title, 0, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null); if(title!=null) canvas.drawBitmap(title, 0, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null);
for(var item : items) { for(var item : items) {
var y = (int) Math.round(itemH * i++ + (itemH - item.lable.getHeight()) / 2); var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2);
canvas.drawBitmap(item.lable, 0, y, null); var x = 0;
var x = item.lable.getWidth(); if(item.lable!=null) {
for(var num : item.nums) { canvas.drawBitmap(item.lable, 0, y, null);
x += item.lable.getWidth();
}
for(var num : item.nums) if(num!=null) {
canvas.drawBitmap(num, x, y, null); canvas.drawBitmap(num, x, y, null);
x += num.getWidth(); x += num.getWidth();
} }

View File

@ -58,8 +58,9 @@ public class EleScroll extends View implements Choreographer.FrameCallback {
canvas.drawBitmap(img, 0, cur-img.getHeight(), null); canvas.drawBitmap(img, 0, cur-img.getHeight(), null);
} else canvas.drawBitmap(img, 0, 0, null); } else canvas.drawBitmap(img, 0, 0, null);
if(freshCnt==0 && effect!=0 && interval!=0) choreographer.postFrameCallback(this); if(freshCnt==0 && effect!=0 && interval!=0) choreographer.postFrameCallback(this);
} catch (RuntimeException e) { } catch (Throwable e) {
((Page) getParent()).remove(this); setVisibility(GONE);
img = null;
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -2,9 +2,10 @@ package com.xixun.xixunplayer;
import android.content.Context; import android.content.Context;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.view.Choreographer;
import android.widget.VideoView; import android.widget.VideoView;
public class EleVideo extends VideoView { public class EleVideo extends VideoView implements Choreographer.FrameCallback {
float vol = 1; float vol = 1;
@ -12,9 +13,10 @@ public class EleVideo extends VideoView {
super(context); super(context);
setVideoPath(path); setVideoPath(path);
setOnPreparedListener((MediaPlayer player)->{ setOnPreparedListener((MediaPlayer player)->{
player.setLooping(true);
if(! isShown()) { if(! isShown()) {
player.pause();
player.seekTo(0); player.seekTo(0);
player.pause();
} }
if(vol!=1) player.setVolume(vol, vol); if(vol!=1) player.setVolume(vol, vol);
setOnPreparedListener(null); setOnPreparedListener(null);
@ -24,6 +26,7 @@ public class EleVideo extends VideoView {
return true; return true;
}); });
start(); start();
choreographer.postFrameCallback(this);
} }
@Override @Override
@ -37,11 +40,24 @@ public class EleVideo extends VideoView {
if(isVisible) { if(isVisible) {
if(! isPlaying()) start(); if(! isPlaying()) start();
} else { } else {
pause();
seekTo(0); seekTo(0);
pause();
choreographer.postFrameCallback(this);
} }
} }
Choreographer choreographer = Choreographer.getInstance();
@Override
public void doFrame(long frameTimeNanos) {
if(isShown()) return;
if(isPlaying()) {
seekTo(0);
pause();
System.out.println("pause in doFrame()");
}
choreographer.postFrameCallback(this);
}
static String getErrorName(int code) { static String getErrorName(int code) {
if(code==MediaPlayer.MEDIA_ERROR_UNKNOWN) return "UNKNOWN"; if(code==MediaPlayer.MEDIA_ERROR_UNKNOWN) return "UNKNOWN";
if(code==MediaPlayer.MEDIA_ERROR_SERVER_DIED) return "SERVER_DIED"; if(code==MediaPlayer.MEDIA_ERROR_SERVER_DIED) return "SERVER_DIED";

View File

@ -20,6 +20,7 @@ import android.os.StatFs;
import android.view.Choreographer; import android.view.Choreographer;
import androidx.activity.ComponentActivity; import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -37,8 +38,6 @@ import java.net.ServerSocket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -75,9 +74,9 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
} }
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode==999 && grantResults!=null && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED && backView==null) init(); if(requestCode==999 && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED && backView==null) init();
} }
public void init() { public void init() {
@ -100,9 +99,11 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
System.out.println("Bind cardsystem aidl service success"); System.out.println("Bind cardsystem aidl service success");
var service = CardService.Stub.asInterface(iBinder); var service = CardService.Stub.asInterface(iBinder);
try { try {
Util.isScreenOn = service.isScreenOpen();
backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight()); backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight());
state = 5; state = 5;
initProg(); if(Util.isScreenOn) initProg();
else state = 8;
if(progView==null) setContentView(backView); if(progView==null) setContentView(backView);
} catch (RemoteException e) { } catch (RemoteException e) {
Util.makeText(MainActivity.this, e.getMessage()).show(); Util.makeText(MainActivity.this, e.getMessage()).show();
@ -118,7 +119,8 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
System.out.println("Receive PAUSE_PLAYER"); System.out.println("Receive PAUSE_PLAYER");
if(intent.getBooleanExtra("pause", false)) { Util.isScreenOn = ! intent.getBooleanExtra("pause", false);
if(! Util.isScreenOn) {
state = 8; state = 8;
if(progView!=null) { if(progView!=null) {
progView.setVisibility(GONE); progView.setVisibility(GONE);
@ -334,12 +336,10 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
var milli = System.currentTimeMillis(); var milli = System.currentTimeMillis();
var lastPage = page(curAva); var lastPage = page(curAva);
if(milli >= syncMilli) { if(milli >= syncMilli) {
lastPage.setVisibility(GONE); lastPage.hide();
if(lastPage.hasVideo && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1);
syncProg(milli-syncMilli>=1000 ? milli : syncMilli); syncProg(milli-syncMilli>=1000 ? milli : syncMilli);
} else if(milli >= lastPage.endMilli) { } else if(milli >= lastPage.endMilli) {
lastPage.setVisibility(GONE); lastPage.hide();
if(lastPage.hasVideo && curTimes==lastPage.repeatTimes && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1);
if(curTimes < lastPage.repeatTimes) curTimes++; if(curTimes < lastPage.repeatTimes) curTimes++;
else { else {
curTimes = 1; curTimes = 1;
@ -353,23 +353,18 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
page(curAva).setMillis(lastPage.endMilli); page(curAva).setMillis(lastPage.endMilli);
} else { } else {
for(var layer : lastPage.layers) { for(var layer : lastPage.layers) {
for(var ele : layer.eles) if(ele.isShort) { for(var ele : layer.eles) {
if(ele.view.getVisibility()!=VISIBLE) { if(ele.view.getVisibility()==VISIBLE) {
if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE); if(milli >= ele.endMilli) ele.hide();
} else { } else if(milli < ele.endMilli && milli >= ele.startMilli) ele.show();
if(milli >= ele.endMilli) ele.view.setVisibility(GONE);
}
} }
if(milli >= layer.endMilli) { if(milli >= layer.endMilli) {
layer.endMilli += layer.dur; layer.endMilli += layer.dur;
for(var ele : layer.eles) { for(var ele : layer.eles) {
ele.endMilli += layer.dur; ele.endMilli += layer.dur;
ele.startMilli += layer.dur; ele.startMilli += layer.dur;
if(ele.view.getVisibility()!=VISIBLE) { if(ele.startTime > 0) ele.hide();
if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE); else ele.show();
} else {
if(milli >= ele.endMilli) ele.view.setVisibility(GONE);
}
} }
} }
} }
@ -400,7 +395,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
avas.clear(); avas.clear();
var dur = 0; var dur = 0;
Page page; Page page;
for(int i=0; i<progView.getChildCount(); i++) if((page = (Page)progView.getChildAt(i)).isSchedule(milli+dur)) { for(int i=0; i<progView.pages.size(); i++) if((page = progView.pages.get(i)).isSchedule(milli+dur)) {
avas.add(i); avas.add(i);
dur += page.dur * page.repeatTimes; dur += page.dur * page.repeatTimes;
} }
@ -408,6 +403,6 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
} }
Page page(int i) { Page page(int i) {
return (Page) progView.getChildAt(avas.get(i)); return progView.pages.get(avas.get(i));
} }
} }

View File

@ -1,8 +1,9 @@
package com.xixun.xixunplayer; package com.xixun.xixunplayer;
import android.content.Context; import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.view.View; import android.view.View;
import android.widget.AbsoluteLayout;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
@ -12,24 +13,36 @@ import gnph.util.Dates;
import gnph.util.JSList; import gnph.util.JSList;
import gnph.util.JSMap; import gnph.util.JSMap;
public class Page extends AbsoluteLayout { public class Page {
public static class EleBase { public static class EleBase {
View view; View view;
long startMilli;
long endMilli = Long.MAX_VALUE; long endMilli = Long.MAX_VALUE;
long startMilli = Long.MAX_VALUE;
int startTime; int startTime;
int endTime; int endTime;
int x;
String id; String id;
String type; String type;
boolean isShort; boolean isVideo;
}
public static class Layer {
void show() {
if(view.getVisibility()==VISIBLE) return;
view.setVisibility(VISIBLE);
if(isVideo) view.setLeft(x);
}
void hide() {
if(view.getVisibility()!=VISIBLE) return;
if(isVideo) view.setLeft(8000);
view.setVisibility(GONE);
}
}
public static class Layer {
ArrayList<EleBase> eles = new ArrayList<>(); ArrayList<EleBase> eles = new ArrayList<>();
long endMilli = Long.MAX_VALUE; long endMilli = Long.MAX_VALUE;
int dur; int dur;
boolean repeat; boolean isLoop;
} }
public static class Sche { public static class Sche {
@ -42,36 +55,19 @@ public class Page extends AbsoluteLayout {
ArrayList<Sche> sches; ArrayList<Sche> sches;
long endMilli = Long.MAX_VALUE; long endMilli = Long.MAX_VALUE;
int dur, repeatTimes; int dur, repeatTimes;
boolean hasVideo = false;
public Page(Context context) { void hide() {
super(context); for(var layer : layers) for(var ele : layer.eles) ele.hide();
} }
public void setMillis(long milli) { public void setMillis(long milli) {
endMilli = milli + dur; endMilli = milli + dur;
for(var layer : layers) { for(var layer : layers) {
if(layer.repeat) layer.endMilli = milli + layer.dur; if(layer.isLoop) layer.endMilli = milli + layer.dur;
for(var ele : layer.eles) if(ele.isShort) { for(var ele : layer.eles) {
if(ele.startTime > 0) {
ele.startMilli = milli + ele.startTime;
ele.view.setVisibility(GONE);
} else ele.view.setVisibility(VISIBLE);
ele.endMilli = milli + ele.endTime; ele.endMilli = milli + ele.endTime;
} ele.startMilli = milli + ele.startTime;
} if(ele.startTime == 0) ele.show();
if(getLeft() != 0) setLeft(0);
setVisibility(VISIBLE);
}
public void remove(View view) {
view.setVisibility(GONE);
removeView(view);
for(int ll=0; ll<layers.size(); ll++) {
var layer = layers.get(ll);
for(int ee=0; ee<layer.eles.size(); ee++) if(layer.eles.get(ee).view == view) {
if(layer.eles.size() > 1) layer.eles.remove(ee);
else layers.remove(ll);
return;
} }
} }
} }

View File

@ -5,9 +5,11 @@ import android.net.Uri;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.AbsoluteLayout; import android.widget.AbsoluteLayout;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import gnph.util.JSList; import gnph.util.JSList;
import gnph.util.JSMap; import gnph.util.JSMap;
@ -15,20 +17,22 @@ import pl.droidsonroids.gif.GifImageView;
public class ProgView extends AbsoluteLayout { public class ProgView extends AbsoluteLayout {
ArrayList<Page> pages = new ArrayList<>();
public ProgView(JSMap task, int width, int height, Context context) { public ProgView(JSMap task, int width, int height, Context context) {
super(context); super(context);
JSList<JSMap> pages = task.jslist("items"); JSList<JSMap> jpages = task.jslist("items");
for(var pageMap : pages) { for(var pageMap : jpages) {
var _program = pageMap.jsmap("_program"); var _program = pageMap.jsmap("_program");
JSList<JSMap> layers = _program.jslist("layers"); JSList<JSMap> layers = _program.jslist("layers");
if(layers.isEmpty()) continue; if(layers.isEmpty()) continue;
var splitWidths = _program.jslist("splitWidths"); var splitWidths = _program.jslist("splitWidths");
var page = new Page(context); var page = new Page();
page.repeatTimes = pageMap.intg("repeatTimes"); page.repeatTimes = pageMap.intg("repeatTimes");
page.parse(pageMap.jslist("schedules")); page.parse(pageMap.jslist("schedules"));
for(int ll=layers.size()-1; ll>=0; ll--) { for(int ll=layers.size()-1; ll>=0; ll--) {
var layer = new Page.Layer(); var layer = new Page.Layer();
layer.repeat = layers.get(ll).bool("repeat"); layer.isLoop = layers.get(ll).bool("repeat");
JSList<JSMap> sources = layers.get(ll).jslist("sources"); JSList<JSMap> sources = layers.get(ll).jslist("sources");
var border = layers.get(ll).jsmap("border"); var border = layers.get(ll).jsmap("border");
EleBorder bdEle = null; EleBorder bdEle = null;
@ -99,9 +103,11 @@ public class ProgView extends AbsoluteLayout {
} else if(ele.type.equals("DigitalClockNew")) ele.view = new EleDigiClock(Util.programDir+"/", source, context); } else if(ele.type.equals("DigitalClockNew")) ele.view = new EleDigiClock(Util.programDir+"/", source, context);
else if(ele.type.equals("AnalogClock")) ele.view = new EleAnaClock(w, h, Util.programDir+"/"+ele.id, source, context); else if(ele.type.equals("AnalogClock")) ele.view = new EleAnaClock(w, h, Util.programDir+"/"+ele.id, source, context);
else if(ele.type.equals("Video")) { else if(ele.type.equals("Video")) {
page.hasVideo = true; ele.isVideo = true;
var videoView = new EleVideo(Util.programDir + "/" + ele.id, context); var videoView = new EleVideo(Util.programDir + "/" + ele.id, context);
ele.view = videoView; var frame = new FrameLayout(context);
frame.addView(videoView);
ele.view = frame;
var vol = source.intg("vol", 100); var vol = source.intg("vol", 100);
if (vol < 100) videoView.vol = vol / 100.0f; if (vol < 100) videoView.vol = vol / 100.0f;
} else if(ele.type.equals("Audio")) { } else if(ele.type.equals("Audio")) {
@ -124,7 +130,10 @@ public class ProgView extends AbsoluteLayout {
else if(ele.type.equals("EnvironmentalMonitoring")) ele.view = new EleEnviron(Util.programDir+"/", source, context); else if(ele.type.equals("EnvironmentalMonitoring")) ele.view = new EleEnviron(Util.programDir+"/", source, context);
else continue; else continue;
if(ele.view==null) continue; if(ele.view==null) continue;
if(w>0) page.addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); if(w > 0) {
ele.view.setVisibility(GONE);
addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y));
}
layer.eles.add(ele); layer.eles.add(ele);
ele = new Page.EleBase(); ele = new Page.EleBase();
} }
@ -137,7 +146,8 @@ public class ProgView extends AbsoluteLayout {
ele.startTime = bdStart; ele.startTime = bdStart;
ele.endTime = bdEnd; ele.endTime = bdEnd;
ele.view = bdEle; ele.view = bdEle;
page.addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y)); ele.view.setVisibility(GONE);
addView(ele.view, new AbsoluteLayout.LayoutParams(w, h, x, y));
layer.eles.add(ele); layer.eles.add(ele);
} }
if(! layer.eles.isEmpty()) page.layers.add(layer); if(! layer.eles.isEmpty()) page.layers.add(layer);
@ -156,12 +166,11 @@ public class ProgView extends AbsoluteLayout {
continue for_layer; continue for_layer;
} }
} else if(ele.endTime > page.dur) ele.endTime = page.dur; } else if(ele.endTime > page.dur) ele.endTime = page.dur;
ele.isShort = ele.startTime > 0 || ele.endTime < page.dur;
} }
if(layer.dur > page.dur) layer.dur = page.dur; if(layer.dur > page.dur) layer.dur = page.dur;
if(layer.dur == page.dur) layer.isLoop = false;
} }
page.setVisibility(GONE); pages.add(page);
addView(page, new AbsoluteLayout.LayoutParams(width, height, 0, 0));
} }
} }
} }

View File

@ -13,6 +13,8 @@ import gnph.util.IOs;
public class Util { public class Util {
public static boolean isScreenOn;
public static final HashMap<Integer, String[]> stateDescs = new HashMap<>(); public static final HashMap<Integer, String[]> stateDescs = new HashMap<>();
static { static {
stateDescs.put(1, new String[]{"Initialize", "初始化"}); stateDescs.put(1, new String[]{"Initialize", "初始化"});

BIN
xixuncard Normal file

Binary file not shown.