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;
ArrayList<Item> items = new ArrayList<>();
MainActivity act;
int spaceWidth;
int spaceWidth, digitHeight;
int interval, cur, end, step;
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("bPM10")) items.add(new Item("pm10", imgMap.remove("labelpm10"), imgMap.get("unit_pm10")));
}
digitHeight = imgMap.get("0").getHeight();
var scrollSpeed = json.dbl("scrollSpeed");
if(scrollSpeed==0) {
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);
x += title.getWidth() + spaceWidth<<1;
}
var y = (int) Math.round((getHeight() - digitHeight) / 2);
for(var item : items) {
var y = (int) Math.round((getHeight() - item.lable.getHeight()) / 2);
canvas.drawBitmap(item.lable, x, y, null);
x += item.lable.getWidth();
for(var num : item.nums) {
if(item.lable!=null) {
canvas.drawBitmap(item.lable, x, y, null);
x += item.lable.getWidth();
}
for(var num : item.nums) if(num!=null) {
canvas.drawBitmap(num, x, y, null);
x += num.getWidth();
}
@ -150,10 +153,13 @@ public class EleEnviron extends View implements Choreographer.FrameCallback {
int i = 0;
if(title!=null) canvas.drawBitmap(title, 0, Math.round(itemH * i++ + (itemH - title.getHeight()) / 2), null);
for(var item : items) {
var y = (int) Math.round(itemH * i++ + (itemH - item.lable.getHeight()) / 2);
canvas.drawBitmap(item.lable, 0, y, null);
var x = item.lable.getWidth();
for(var num : item.nums) {
var y = (int) Math.round(itemH * i++ + (itemH - digitHeight) / 2);
var x = 0;
if(item.lable!=null) {
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);
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);
} else canvas.drawBitmap(img, 0, 0, null);
if(freshCnt==0 && effect!=0 && interval!=0) choreographer.postFrameCallback(this);
} catch (RuntimeException e) {
((Page) getParent()).remove(this);
} catch (Throwable e) {
setVisibility(GONE);
img = null;
e.printStackTrace();
}
}

View File

@ -2,9 +2,10 @@ package com.xixun.xixunplayer;
import android.content.Context;
import android.media.MediaPlayer;
import android.view.Choreographer;
import android.widget.VideoView;
public class EleVideo extends VideoView {
public class EleVideo extends VideoView implements Choreographer.FrameCallback {
float vol = 1;
@ -12,9 +13,10 @@ public class EleVideo extends VideoView {
super(context);
setVideoPath(path);
setOnPreparedListener((MediaPlayer player)->{
player.setLooping(true);
if(! isShown()) {
player.pause();
player.seekTo(0);
player.pause();
}
if(vol!=1) player.setVolume(vol, vol);
setOnPreparedListener(null);
@ -24,6 +26,7 @@ public class EleVideo extends VideoView {
return true;
});
start();
choreographer.postFrameCallback(this);
}
@Override
@ -37,11 +40,24 @@ public class EleVideo extends VideoView {
if(isVisible) {
if(! isPlaying()) start();
} else {
pause();
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) {
if(code==MediaPlayer.MEDIA_ERROR_UNKNOWN) return "UNKNOWN";
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 androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -37,8 +38,6 @@ import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@ -75,9 +74,9 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
}
}
@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);
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() {
@ -100,9 +99,11 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
System.out.println("Bind cardsystem aidl service success");
var service = CardService.Stub.asInterface(iBinder);
try {
Util.isScreenOn = service.isScreenOpen();
backView = new BackView(MainActivity.this, service.getScreenWidth(), service.getScreenHeight());
state = 5;
initProg();
if(Util.isScreenOn) initProg();
else state = 8;
if(progView==null) setContentView(backView);
} catch (RemoteException e) {
Util.makeText(MainActivity.this, e.getMessage()).show();
@ -118,7 +119,8 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("Receive PAUSE_PLAYER");
if(intent.getBooleanExtra("pause", false)) {
Util.isScreenOn = ! intent.getBooleanExtra("pause", false);
if(! Util.isScreenOn) {
state = 8;
if(progView!=null) {
progView.setVisibility(GONE);
@ -334,12 +336,10 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
var milli = System.currentTimeMillis();
var lastPage = page(curAva);
if(milli >= syncMilli) {
lastPage.setVisibility(GONE);
if(lastPage.hasVideo && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1);
lastPage.hide();
syncProg(milli-syncMilli>=1000 ? milli : syncMilli);
} else if(milli >= lastPage.endMilli) {
lastPage.setVisibility(GONE);
if(lastPage.hasVideo && curTimes==lastPage.repeatTimes && progView.getChildCount()>1) lastPage.setLeft(lastPage.getRight()+1);
lastPage.hide();
if(curTimes < lastPage.repeatTimes) curTimes++;
else {
curTimes = 1;
@ -353,23 +353,18 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
page(curAva).setMillis(lastPage.endMilli);
} else {
for(var layer : lastPage.layers) {
for(var ele : layer.eles) if(ele.isShort) {
if(ele.view.getVisibility()!=VISIBLE) {
if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE);
} else {
if(milli >= ele.endMilli) ele.view.setVisibility(GONE);
}
for(var ele : layer.eles) {
if(ele.view.getVisibility()==VISIBLE) {
if(milli >= ele.endMilli) ele.hide();
} else if(milli < ele.endMilli && milli >= ele.startMilli) ele.show();
}
if(milli >= layer.endMilli) {
layer.endMilli += layer.dur;
for(var ele : layer.eles) {
ele.endMilli += layer.dur;
ele.startMilli += layer.dur;
if(ele.view.getVisibility()!=VISIBLE) {
if(milli < ele.endMilli && milli >= ele.startMilli) ele.view.setVisibility(VISIBLE);
} else {
if(milli >= ele.endMilli) ele.view.setVisibility(GONE);
}
if(ele.startTime > 0) ele.hide();
else ele.show();
}
}
}
@ -400,7 +395,7 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
avas.clear();
var dur = 0;
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);
dur += page.dur * page.repeatTimes;
}
@ -408,6 +403,6 @@ public class MainActivity extends ComponentActivity implements Choreographer.Fra
}
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;
import android.content.Context;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.view.View;
import android.widget.AbsoluteLayout;
import java.time.LocalDate;
import java.time.LocalTime;
@ -12,24 +13,36 @@ import gnph.util.Dates;
import gnph.util.JSList;
import gnph.util.JSMap;
public class Page extends AbsoluteLayout {
public class Page {
public static class EleBase {
View view;
long startMilli;
long endMilli = Long.MAX_VALUE;
long startMilli = Long.MAX_VALUE;
int startTime;
int endTime;
int x;
String id;
String type;
boolean isShort;
}
public static class Layer {
boolean isVideo;
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<>();
long endMilli = Long.MAX_VALUE;
int dur;
boolean repeat;
boolean isLoop;
}
public static class Sche {
@ -42,36 +55,19 @@ public class Page extends AbsoluteLayout {
ArrayList<Sche> sches;
long endMilli = Long.MAX_VALUE;
int dur, repeatTimes;
boolean hasVideo = false;
public Page(Context context) {
super(context);
void hide() {
for(var layer : layers) for(var ele : layer.eles) ele.hide();
}
public void setMillis(long milli) {
endMilli = milli + dur;
for(var layer : layers) {
if(layer.repeat) layer.endMilli = milli + layer.dur;
for(var ele : layer.eles) if(ele.isShort) {
if(ele.startTime > 0) {
ele.startMilli = milli + ele.startTime;
ele.view.setVisibility(GONE);
} else ele.view.setVisibility(VISIBLE);
if(layer.isLoop) layer.endMilli = milli + layer.dur;
for(var ele : layer.eles) {
ele.endMilli = milli + ele.endTime;
}
}
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;
ele.startMilli = milli + ele.startTime;
if(ele.startTime == 0) ele.show();
}
}
}

View File

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

View File

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

BIN
xixuncard Normal file

Binary file not shown.