This commit is contained in:
Gangphon 2024-11-11 18:22:45 +08:00
parent 586583ddfd
commit 997ed20c5e
11 changed files with 214 additions and 119 deletions

View File

@ -1,4 +1,9 @@
<project version="4"> <project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="android.webkit.JavascriptInterface" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />

View File

@ -11,7 +11,7 @@ android {
minSdk 21 minSdk 21
targetSdk 34 targetSdk 34
versionCode 1 versionCode 1
versionName "2.1.15" versionName "2.1.21"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" > xmlns:tools="http://schemas.android.com/tools" >
<!-- android:sharedUserId="android.uid.system"-->
<!-- android:sharedUserMaxSdkVersion="32">-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

View File

@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Environment;
import android.view.View; import android.view.View;
public class BackView extends View { public class BackView extends View {
@ -14,17 +13,18 @@ public class BackView extends View {
Bitmap cosImg; Bitmap cosImg;
Rect rect = new Rect(); Rect rect = new Rect();
public BackView(Context context, int width, int height) { public BackView(Context context) {
super(context); super(context);
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back, Util.noScaled); img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back, Util.noScaled);
cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled); cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled);
rect.right = width;
rect.bottom = height;
} }
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
rect.right = Util.screenWidth;
rect.bottom = Util.screenHeight;
canvas.clipRect(rect);
if(cosImg!=null) canvas.drawBitmap(cosImg, null, rect, null); if(cosImg!=null) canvas.drawBitmap(cosImg, null, rect, null);
else if(img!=null) for(int y=0; y<rect.bottom; y+=img.getHeight()) for(int x=0; x<rect.right; x+=img.getWidth()) canvas.drawBitmap(img, x, y, null); else if(img!=null) for(int y=0; y<rect.bottom; y+=img.getHeight()) for(int x=0; x<rect.right; x+=img.getWidth()) canvas.drawBitmap(img, x, y, null);
} }

View File

@ -71,6 +71,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) init(); if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) init();
else { else {
Util.println("---- No permission, Try again ..."); Util.println("---- No permission, Try again ...");
Util.makeText(this, "No permission, Try again ...").show();
ActivityCompat.requestPermissions(this, new String[]{ ActivityCompat.requestPermissions(this, new String[]{
android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_EXTERNAL_STORAGE,
@ -80,6 +81,16 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
}, 999); }, 999);
} }
} }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(backView!=null) return;
if(requestCode==999 && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED) init();
else {
Util.println("---- Request Permission Failed");
Util.makeText(this, "Request Permission Failed").show();
}
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
@ -132,44 +143,39 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
Util.println(" ==<< MainActivity onPause << "+hashCode()); Util.println(" ==<< MainActivity onPause << "+hashCode());
} }
CardService serviCard;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode==999 && grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED && backView==null) init();
}
ConnService serviXy; ConnService serviXy;
Intent intenCard;
ServiceConnection connCard;
@SuppressLint("UnspecifiedRegisterReceiverFlag") @SuppressLint("UnspecifiedRegisterReceiverFlag")
public void init() { public void init() {
var dir = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ? Environment.getExternalStorageDirectory().getAbsolutePath() + "/XixunPlayer" : getExternalFilesDir(null).getAbsolutePath(); var dir = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ? Environment.getExternalStorageDirectory().getAbsolutePath() + "/XixunPlayer" : getExternalFilesDir(null).getAbsolutePath();
var msg = "---- dir "+dir; Util.println("\n---- Init ----\n dir "+dir);
Util.println(msg);
Util.programDir = dir + "/program"; Util.programDir = dir + "/program";
Util.backImgFile = dir + "/background"; Util.backImgFile = dir + "/background";
setContentView(backView = new BackView(MainActivity.this));
state = 5;
var program = new File(Util.programDir); var program = new File(Util.programDir);
if(program.isFile()) program.delete(); if(program.isFile()) program.delete();
msg = "---- mkdir: "+program.mkdirs(); Util.println(" mkdir: "+program.mkdirs());
Util.println(msg);
var cardConn = new ServiceConnection() { connCard = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
serviCard = null;
Util.println("<-<- AIDL Service cardsystem Disconnected"); Util.println("<-<- AIDL Service cardsystem Disconnected");
} }
public void onServiceConnected(ComponentName name, IBinder iBinder) { public void onServiceConnected(ComponentName name, IBinder iBinder) {
unbindService(this); unbindService(this);
Util.println("->-> AIDL Service cardsystem aidl service Connected"); Util.println("->-> AIDL Service cardsystem Connected");
var service = CardService.Stub.asInterface(iBinder); serviCard = CardService.Stub.asInterface(iBinder);
try { try {
Util.isScreenOn = service.isScreenOpen(); Util.isScreenOn = serviCard.isScreenOpen();
Util.screenWidth = service.getScreenWidth(); Util.screenWidth = serviCard.getScreenWidth();
Util.screenHeight = service.getScreenHeight(); Util.screenHeight = serviCard.getScreenHeight();
Util.println(" IsScreenOn: "+Util.isScreenOn+" screen: "+Util.screenWidth+" x "+Util.screenHeight); Util.println(" IsScreenOn: "+Util.isScreenOn+" screen: "+Util.screenWidth+" x "+Util.screenHeight);
setContentView(backView = new BackView(MainActivity.this, Util.screenWidth, Util.screenHeight)); backView.invalidate();
state = 5;
if(Util.isScreenOn) initProg(); if(Util.isScreenOn) initProg();
else state = 8; else state = 8;
} catch (Exception e) { } catch (Exception e) {
@ -178,14 +184,14 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
}; };
var intent = new Intent("com.xixun.joey.aidlset.SettingsService"); intenCard = new Intent("com.xixun.joey.aidlset.SettingsService");
intent.setPackage("com.xixun.joey.cardsystem"); intenCard.setPackage("com.xixun.joey.cardsystem");
bindService(intent, cardConn, Context.BIND_AUTO_CREATE); bindService(intenCard, connCard, Context.BIND_AUTO_CREATE);
var connXy = new ServiceConnection() { var connXy = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
Util.println("<-<- AIDL Service xy.conn Disconnected");
serviXy = null; serviXy = null;
Util.println("<-<- AIDL Service xy.conn Disconnected");
} }
public void onServiceConnected(ComponentName name, IBinder iBinder) { public void onServiceConnected(ComponentName name, IBinder iBinder) {
unbindService(this); unbindService(this);
@ -278,27 +284,27 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
var code = intent.getIntExtra("code", 0); var code = intent.getIntExtra("code", 0);
Util.println(" remote_control "+code); Util.println(" remote_control "+code);
if(progView == null || ! progView.isShown() || code > progView.pages.size()) return; if(progView == null || ! progView.isShown() || code > progView.pages.size()) return;
var page = progView.pages.get(code-1);
var ms = System.currentTimeMillis(); var ms = System.currentTimeMillis();
if(! avas.isEmpty()) { if(! avas.isEmpty()) {
avas.get(curAva).hide(); avas.get(curAva).hide();
if(avas.size()==1 && avas.get(0)==page) for(var call : progView.calls) call.doFrame(ms); if(code > 0 && avas.get(curAva)==progView.pages.get(code-1)) for(var call : progView.calls) call.doFrame(ms);
} }
ms = (ms+999)/1000*1000; ms = (ms+999)/1000*1000;
if(code > 0) { if(code > 0) {
avas.clear(); avas.clear();
var page = progView.pages.get(code-1);
avas.add(page); avas.add(page);
curAva = 0; curAva = 0;
curTimes = 1; curTimes = 1;
waitTo = 0; //点播 waitTo = 0; //点播
page.setMillis(ms); page.setMillis(ms, ms);
if(state != 6) { if(state != 6) {
setContentView(progView); setContentView(progView);
state = 6; state = 6;
} }
} else { } else {
waitTo = Long.MAX_VALUE; waitTo = Long.MAX_VALUE;
syncProg(ms); syncProg(ms, 0);
} }
} catch (Throwable e) { } catch (Throwable e) {
Util.makeText(MainActivity.this, Util.toStr(e)).show(); Util.makeText(MainActivity.this, Util.toStr(e)).show();
@ -367,9 +373,39 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
reces.add(rece); reces.add(rece);
new Thread(this).start(); new Thread(this).start();
// new Thread(()->{
// while(true) {
// try {
// Thread.sleep(10000);
// if(serviCard!=null && serviCard.asBinder().isBinderAlive()) {
// var www = serviCard.getScreenWidth();
// var hhh = serviCard.getScreenHeight();
// if(www!=Util.screenWidth || hhh!=Util.screenHeight) {
// var ins = MainActivity.ins;
// if(ins!=null) ins.runOnUiThread(() -> {
// Util.screenWidth = www;
// Util.screenHeight = hhh;
// ins.backView.invalidate();
// });
// }
// } else {
// Util.println(" bindService");
// var ins = MainActivity.ins;
// if(ins!=null) ins.runOnUiThread(() -> ins.bindService(ins.intenCard, ins.connCard, Context.BIND_AUTO_CREATE));
// }
// } catch (Throwable e) {
// var ins = MainActivity.ins;
// if(ins!=null) ins.runOnUiThread(() -> Util.makeText(ins, Util.toStr(e)).show());
// Util.printStackTrace(e);
// }
// }
// }).start();
} }
public void stopProg() { public void stopProg() {
avas.clear();
curAva = 0;
curTimes = 1;
if(insView!=null) { if(insView!=null) {
insView.release(); insView.release();
insView = null; insView = null;
@ -434,7 +470,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
if(insView!=null || progView!=null) { if(insView!=null || progView!=null) {
state = 5; state = 5;
Util.println("Init Sync"); Util.println("Init Sync");
syncProg((System.currentTimeMillis()+999)/1000*1000); syncProg((System.currentTimeMillis()+999)/1000*1000, 0);
if(canAdd) { if(canAdd) {
choreographer.postFrameCallback(this); choreographer.postFrameCallback(this);
canAdd = false; canAdd = false;
@ -479,7 +515,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
state = 5; state = 5;
System.gc(); System.gc();
Util.println("Init Sync"); Util.println("Init Sync");
syncProg((System.currentTimeMillis()+999)/1000*1000); syncProg((System.currentTimeMillis()+999)/1000*1000, 0);
if(canAdd) { if(canAdd) {
choreographer.postFrameCallback(this); choreographer.postFrameCallback(this);
canAdd = false; canAdd = false;
@ -513,7 +549,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
if(milli >= waitTo) { if(milli >= waitTo) {
waitTo = Long.MAX_VALUE; waitTo = Long.MAX_VALUE;
Util.println("wait sync"); Util.println("wait sync");
syncProg(milli); syncProg(milli, 0);
if(insView!=null) for(var call : insView.calls) call.doFrame(milli); if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
if(progView!=null) for(var call : progView.calls) call.doFrame(milli); if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
} }
@ -526,7 +562,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
if(isInsert) { if(isInsert) {
if(--lastPage.repeatTimes<=0 && ++curAva >= avas.size()) { if(--lastPage.repeatTimes<=0 && ++curAva >= avas.size()) {
var isDiff = milli-lastPage.endMilli>=1000; var isDiff = milli-lastPage.endMilli>=1000;
syncProg(isDiff ? milli : lastPage.endMilli); syncProg(isDiff ? milli : lastPage.endMilli, milli);
if(insView!=null) for(var call : insView.calls) call.doFrame(milli); if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
if(progView!=null) for(var call : progView.calls) call.doFrame(milli); if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
return; return;
@ -538,7 +574,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
curTimes = 1; curTimes = 1;
if(++curAva >= avas.size()) { if(++curAva >= avas.size()) {
var isDiff = milli-lastPage.endMilli>=1000; var isDiff = milli-lastPage.endMilli>=1000;
syncProg(isDiff ? milli : lastPage.endMilli); syncProg(isDiff ? milli : lastPage.endMilli, milli);
if(insView!=null) for(var call : insView.calls) call.doFrame(milli); if(insView!=null) for(var call : insView.calls) call.doFrame(milli);
if(progView!=null) for(var call : progView.calls) call.doFrame(milli); if(progView!=null) for(var call : progView.calls) call.doFrame(milli);
return; return;
@ -546,14 +582,15 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
} }
} }
} }
avas.get(curAva).setMillis(lastPage.endMilli); avas.get(curAva).setMillis(lastPage.endMilli, milli);
Util.println("curAva: "+curAva+" endMs: "+avas.get(curAva).endMilli); Util.println("curAva: "+curAva+" endMs: "+avas.get(curAva).endMilli);
} }
if(isInsert) for(var call : insView.calls) call.doFrame(milli); if(isInsert) for(var call : insView.calls) call.doFrame(milli);
else for(var call : progView.calls) call.doFrame(milli); else for(var call : progView.calls) call.doFrame(milli);
} }
void syncProg(long milli) { void syncProg(long milli, long cur) {
if(cur==0) cur = milli;
Util.println("\nSyncProg"); Util.println("\nSyncProg");
avas.clear(); avas.clear();
curAva = 0; curAva = 0;
@ -589,7 +626,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
if(avas.isEmpty()) for(var page : insView.pages) if(page.sches==null) avas.add(page); if(avas.isEmpty()) for(var page : insView.pages) if(page.sches==null) avas.add(page);
if(! avas.isEmpty()) { if(! avas.isEmpty()) {
isInsert = true; isInsert = true;
avas.get(curAva).setMillis(milli); avas.get(curAva).setMillis(milli, cur);
if(! insView.isShown()) setContentView(insView); if(! insView.isShown()) setContentView(insView);
state = 6; state = 6;
Util.println("avas "+avas.size()+" Insert"); Util.println("avas "+avas.size()+" Insert");
@ -617,7 +654,7 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
syncMs = milli; syncMs = milli;
Util.println("Sync. dur: "+dur+" milli: "+milli+" start: "+start+" diff: "+(milli - start)); Util.println("Sync. dur: "+dur+" milli: "+milli+" start: "+start+" diff: "+(milli - start));
} }
avas.get(curAva).setMillis(start); avas.get(curAva).setMillis(start, milli);
if(! progView.isShown()) setContentView(progView); if(! progView.isShown()) setContentView(progView);
state = 6; state = 6;
Util.println("Avas "+avas.size()); Util.println("Avas "+avas.size());
@ -642,7 +679,8 @@ public class MainActivity extends Activity implements Choreographer.FrameCallbac
new SocketThread(MainActivity.ins, socket).start(); new SocketThread(MainActivity.ins, socket).start();
Util.println("\nAccepted"); Util.println("\nAccepted");
} catch (Throwable e) { } catch (Throwable e) {
if(MainActivity.ins!=null) MainActivity.ins.runOnUiThread(() -> Util.makeText(MainActivity.ins, Util.toStr(e)).show()); var ins = MainActivity.ins;
if(ins!=null) ins.runOnUiThread(() -> Util.makeText(ins, Util.toStr(e)).show());
Util.printStackTrace(e); Util.printStackTrace(e);
} }
} }

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri; import android.net.Uri;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
@ -204,6 +205,7 @@ public class Prog extends AbsLayout {
var imgView = new ImageView(context); var imgView = new ImageView(context);
var file = Util.programDir+"/"+id; var file = Util.programDir+"/"+id;
new Thread(()->{ new Thread(()->{
try {
var ttt = System.currentTimeMillis(); var ttt = System.currentTimeMillis();
var img = BitmapFactory.decodeFile(file); var img = BitmapFactory.decodeFile(file);
// if(img.getByteCount()>1500*1500*4) { // if(img.getByteCount()>1500*1500*4) {
@ -215,6 +217,15 @@ public class Prog extends AbsLayout {
Util.println(" img "+img.getWidth()+"x"+img.getHeight()+" "+ttt); Util.println(" img "+img.getWidth()+"x"+img.getHeight()+" "+ttt);
Bitmap finalImg = img; Bitmap finalImg = img;
MainActivity.ins.runOnUiThread(() -> imgView.setImageBitmap(finalImg)); MainActivity.ins.runOnUiThread(() -> imgView.setImageBitmap(finalImg));
} catch (Throwable e) {
var stackTrace = Util.toStackTrace(e);
Util.println(stackTrace);
var img = Bitmap.createBitmap(600, 400, Bitmap.Config.ARGB_8888);
var paint = new Paint();
paint.setColor(Color.RED);
new Canvas(img).drawText(stackTrace, 0, 0, paint);
MainActivity.ins.runOnUiThread(() -> imgView.setImageBitmap(img));
}
}).start(); }).start();
imgView.setScaleType(ImageView.ScaleType.FIT_XY); imgView.setScaleType(ImageView.ScaleType.FIT_XY);
src.view = imgView; src.view = imgView;
@ -242,6 +253,20 @@ public class Prog extends AbsLayout {
} else if(src.type.equals("Audio")) { } else if(src.type.equals("Audio")) {
if(id==null) continue; if(id==null) continue;
src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, dur, false, false); src.view = new SrcVideo(context, Util.programDir + "/" +id, source.intg("vol", 100) / 100.0f, dur, false, false);
} else if(src.type.equals("Scroll")) {
JSList<String> imgs = source.jslist("imgs");
if(imgs.isEmpty()) continue;
var images = new ArrayList<Bitmap>();
for(var img : imgs) images.add(BitmapFactory.decodeFile(Util.programDir+"/"+img));
var directStr = source.str("direct");
src.view = new SrcScroll(this, images, directStr==null ? 0 : directStr.charAt(0), source.dbl("speed"));
src.text = source.str("tts");
if(src.text!=null) {
src.tts = new TextToSpeech(context, (int status)->{
Util.println("status: "+status+" "+(status==TextToSpeech.SUCCESS));
}, "com.iflytek.speechcloud");
src.tts.setSpeechRate((float) source.dbl("speechRate"));
}
} else if(src.type.startsWith("MultiPng") || src.type.equals("SplitText")) { } else if(src.type.startsWith("MultiPng") || src.type.equals("SplitText")) {
JSList<JSMap> imgs = source.jslist("arrayPics"); JSList<JSMap> imgs = source.jslist("arrayPics");
if(imgs.isEmpty()) continue; if(imgs.isEmpty()) continue;
@ -250,7 +275,20 @@ public class Prog extends AbsLayout {
var speechRate = (float) source.dbl("voiceRate"); var speechRate = (float) source.dbl("voiceRate");
if(mode!=null ? mode.endsWith("roll") : (imgs.size()==1 && imgs.get(0).intg("picDuration")==0)) { if(mode!=null ? mode.endsWith("roll") : (imgs.size()==1 && imgs.get(0).intg("picDuration")==0)) {
var img = imgs.get(0); var img = imgs.get(0);
src.view = new SrcScroll(this, img, null); var images = new ArrayList<Bitmap>();
images.add(BitmapFactory.decodeFile(Util.programDir+"/"+img.stnn("id")));
var speed = img.dbl("scrollSpeed");
if(speed==0) {
var scrollDur = img.dbl("effectSpeed");
if(scrollDur!=0) speed = 1000 / scrollDur;
}
char direct = 0;
var directStr = img.str("effect");
if(directStr!=null && ! directStr.equals("no")) {
int idx = directStr.lastIndexOf(' ');
if(idx > -1) direct = directStr.charAt(idx+1);
}
src.view = new SrcScroll(this, images, direct, speed);
if(hasTTS) { if(hasTTS) {
src.text = img.str("text"); src.text = img.str("text");
if(src.text!=null) { if(src.text!=null) {
@ -329,9 +367,11 @@ public class Prog extends AbsLayout {
prefix += "height:"+geo.height+"; font-size:"+fontSize+"px;\">"; prefix += "height:"+geo.height+"; font-size:"+fontSize+"px;\">";
var suffix = "</body><script>window.onload = function() {\n" + var suffix = "</body><script>window.onload = function() {\n" +
"window.java.setWidth(document.body.scrollWidth);};</script>"; "window.java.setWidth(document.body.scrollWidth);};</script>";
source.put("effect", "to left"); var speed = source.dbl("speed");
source.put("effectSpeed", source.intg("speed")); if(speed!=0) speed = 1000.0 / speed;
var view = new SrcScroll(this, source, Bitmap.createBitmap(geo.width, geo.height, Bitmap.Config.ARGB_8888)); var imgs = new ArrayList<Bitmap>();
imgs.add(Bitmap.createBitmap(geo.width, geo.height, Bitmap.Config.ARGB_8888));
var view = new SrcScroll(this, imgs, 'l', speed);
src.view = view; src.view = view;
webView.addJavascriptInterface(new Object() { webView.addJavascriptInterface(new Object() {
@JavascriptInterface @JavascriptInterface
@ -351,8 +391,8 @@ public class Prog extends AbsLayout {
webView.draw(canvas); webView.draw(canvas);
webView.setVisibility(GONE); webView.setVisibility(GONE);
view.freshCnt = view.cur = 0; view.freshCnt = view.cur = 0;
if(view.effect=='l') view.end = -(view.imgs.get(0).getWidth()-view.step); if(view.direct=='l') view.end = -(view.imgs.get(0).getWidth()-view.step);
else if(view.effect=='r') view.end = view.imgs.get(0).getWidth()-view.step; else if(view.direct=='r') view.end = view.imgs.get(0).getWidth()-view.step;
view.invalidate(); view.invalidate();
} }
}; };
@ -635,14 +675,17 @@ public class Prog extends AbsLayout {
for(var layer : layers) for(var src : layer.srcs) src.hide(); for(var layer : layers) for(var src : layer.srcs) src.hide();
} }
void setMillis(long milli) { void setMillis(long start, long cur) {
endMilli = milli + sDur; endMilli = start + sDur;
for(var layer : layers) { for(var layer : layers) {
if(layer.isLoop) layer.endMilli = milli + layer.dur; if(layer.isLoop) layer.endMilli = start + layer.dur;
for(var src : layer.srcs) { for(var src : layer.srcs) {
src.endMilli = milli + src.endTime; src.endMilli = start + src.endTime;
src.startMilli = milli + src.startTime; src.startMilli = start + src.startTime;
if(src.startTime == 0) src.show(); if(src.startTime == 0) {
if(src.view instanceof SrcVideo) ((SrcVideo)src.view).seekTo = cur - src.startMilli;
src.show();
}
} }
} }
} }
@ -652,7 +695,10 @@ public class Prog extends AbsLayout {
if(src.view.getVisibility()==VISIBLE) { if(src.view.getVisibility()==VISIBLE) {
if(milli >= src.endMilli) src.hide(); if(milli >= src.endMilli) src.hide();
else src.doEff(); else src.doEff();
} else if(milli < src.endMilli && milli >= src.startMilli) src.show(); } else if(milli < src.endMilli && milli >= src.startMilli) {
if(src.view instanceof SrcVideo) ((SrcVideo)src.view).seekTo = milli - src.startMilli;
src.show();
}
} }
if(milli >= layer.endMilli) { if(milli >= layer.endMilli) {
layer.endMilli += layer.dur; layer.endMilli += layer.dur;

View File

@ -47,22 +47,24 @@ public class Server extends Service {
@Override @Override
public String getVersion() throws RemoteException { public String getVersion() throws RemoteException {
Util.println("Server getVersion. <-"+null);
return null; return null;
} }
@Override @Override
public void setScreenWidth(int w) throws RemoteException { public void setScreenWidth(int width) throws RemoteException {
Util.println("Server setScreenWidth. ->"+width);
} }
@Override @Override
public void setScreenHeight(int h) throws RemoteException { public void setScreenHeight(int height) throws RemoteException {
Util.println("Server setScreenHeight. ->"+height);
} }
@Override @Override
public void taskScreenshot(String cmdId) throws RemoteException { public void taskScreenshot(String cmdId) throws RemoteException {
Util.println("Server taskScreenshot. ->"+cmdId);
} }
@Override @Override

View File

@ -93,15 +93,15 @@ public class SocketThread extends Thread {
new File(Util.programDir + "/" + name).delete(); new File(Util.programDir + "/" + name).delete();
} }
} }
} else if("SetBackImg".equals(_type) || "imgFileStart".equals(_type)) { } else if("setBackImg".equals(_type) || "imgFileStart".equals(_type)) {
var size = obj.intg("size");
var fout = new FileOutputStream(Util.backImgFile); var fout = new FileOutputStream(Util.backImgFile);
IOs.write(fout, in, size); IOs.write(fout, in, obj.intg("size"));
fout.flush(); fout.flush();
fout.getFD().sync(); fout.getFD().sync();
fout.close(); fout.close();
var img = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled);
if(main!=null) main.runOnUiThread(() -> { if(main!=null) main.runOnUiThread(() -> {
main.backView.cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled); main.backView.cosImg = img;
main.backView.invalidate(); main.backView.invalidate();
}); });
new JSMap("success", true).write(out); new JSMap("success", true).write(out);

View File

@ -2,7 +2,6 @@ package com.xixun.xixunplayer;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
import android.view.Choreographer; import android.view.Choreographer;
@ -12,53 +11,53 @@ import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import gnph.util.JSMap;
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
public class SrcScroll extends View implements Choreographer.FrameCallback { public class SrcScroll extends View implements Choreographer.FrameCallback {
ArrayList<Bitmap> imgs = new ArrayList<>(); ArrayList<Bitmap> imgs;
Rect rect = new Rect(); Rect rect = new Rect();
int interval, cur, end, step; int interval, cur, end, step;
char effect; char direct;
public SrcScroll(Prog prog, JSMap json, Bitmap img) { public SrcScroll(Prog prog, ArrayList<Bitmap> imgs, char direct, double speed) {
super(prog.getContext()); super(prog.getContext());
if(img==null) img = BitmapFactory.decodeFile(Util.programDir+"/"+json.stnn("id")); this.imgs = imgs;
if(img.getWidth() > 8192) { this.direct = direct;
var rem = img.getWidth(); var img0 = imgs.get(0);
Util.println(" SrcScroll img cnt "+imgs.size()+", "+img0.getWidth()+"x"+img0.getHeight()+" direct "+direct+" speed "+speed);
if(img0.getWidth() > 4096) {
imgs.clear();
var rem = img0.getWidth();
do { do {
imgs.add(Bitmap.createBitmap(img, img.getWidth()-rem, 0, Math.min(8192, rem), img.getHeight())); imgs.add(Bitmap.createBitmap(img0, img0.getWidth()-rem, 0, Math.min(4096, rem), img0.getHeight()));
rem -= 8192; rem -= 4096;
} while (rem>0); } while (rem>0);
} else if(img.getHeight() > 8192) { } else if(img0.getHeight() > 4096) {
var rem = img.getHeight(); imgs.clear();
var rem = img0.getHeight();
do { do {
imgs.add(Bitmap.createBitmap(img, 0, img.getHeight()-rem, img.getWidth(), Math.min(8192, rem))); imgs.add(Bitmap.createBitmap(img0, 0, img0.getHeight()-rem, img0.getWidth(), Math.min(4096, rem)));
rem -= 8192; rem -= 4096;
} while (rem>0); } while (rem>0);
} else imgs.add(img);
var effStr = json.str("effect");
if(effStr==null || effStr.equals("no")) return;
var scrollSpeed = json.dbl("scrollSpeed");
if(scrollSpeed==0) {
var scrollDur = json.dbl("effectSpeed");
if(scrollDur==0) return;
scrollSpeed = 1000 / scrollDur;
} }
if(speed==0) return;
int width = 0, height = 0;
for(var img : imgs) {
width += img.getWidth();
height += img.getHeight();
}
if(direct=='l') end = -(width-step);
else if(direct=='r') end = width-step;
else if(direct=='t') end = -(height-step);
else if(direct=='b') end = height-step;
else direct = 0;
if(direct==0) return;
interval = step = 1; interval = step = 1;
if(scrollSpeed > 60) step = (int) Math.round(scrollSpeed/60); if(speed > 60) step = (int) Math.round(speed/60);
else if(scrollSpeed < 60) interval = (int) Math.round(60/scrollSpeed); else if(speed < 60) interval = (int) Math.round(60/speed);
int idx = effStr.lastIndexOf(' '); prog.calls.add(this);
if(idx > -1) {
effect = effStr.charAt(idx+1);
if(effect=='l') end = -(img.getWidth()-step);
else if(effect=='r') end = img.getWidth()-step;
else if(effect=='t') end = -(img.getHeight()-step);
else if(effect=='b') end = img.getHeight()-step;
else effect = 0;
}
if(effect!=0) prog.calls.add(this);
} }
@Override @Override
protected void onDraw(@NonNull Canvas canvas) { protected void onDraw(@NonNull Canvas canvas) {
@ -78,14 +77,14 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
rect.right = getWidth(); rect.right = getWidth();
rect.bottom = getHeight(); rect.bottom = getHeight();
} }
if(effect=='l') { if(direct=='l') {
int ii = 0, x = cur; int ii = 0, x = cur;
do { do {
if(x > rect.left-imgs.get(ii).getWidth() && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null); if(x > rect.left-imgs.get(ii).getWidth() && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null);
x += imgs.get(ii).getWidth(); x += imgs.get(ii).getWidth();
if(++ii >= imgs.size()) ii = 0; if(++ii >= imgs.size()) ii = 0;
} while(x < rect.right); } while(x < rect.right);
} else if(effect=='r') { } else if(direct=='r') {
int ii = imgs.size()-1, x = cur + getWidth(); int ii = imgs.size()-1, x = cur + getWidth();
boolean con1; boolean con1;
do { do {
@ -94,14 +93,14 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
if(con1 && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null); if(con1 && x < rect.right) canvas.drawBitmap(imgs.get(ii), x, 0, null);
if(--ii < 0) ii = imgs.size()-1; if(--ii < 0) ii = imgs.size()-1;
} while(con1); } while(con1);
} else if(effect=='t') { } else if(direct=='t') {
int ii = 0, y = cur; int ii = 0, y = cur;
do { do {
if(y > rect.top-imgs.get(ii).getHeight() && y < rect.bottom) canvas.drawBitmap(imgs.get(ii), 0, y, null); if(y > rect.top-imgs.get(ii).getHeight() && y < rect.bottom) canvas.drawBitmap(imgs.get(ii), 0, y, null);
y += imgs.get(ii).getHeight(); y += imgs.get(ii).getHeight();
if(++ii >= imgs.size()) ii = 0; if(++ii >= imgs.size()) ii = 0;
} while(y < rect.bottom); } while(y < rect.bottom);
} else if(effect=='b') { } else if(direct=='b') {
int ii = imgs.size()-1, y = cur + getHeight(); int ii = imgs.size()-1, y = cur + getHeight();
boolean con1; boolean con1;
do { do {
@ -124,10 +123,10 @@ public class SrcScroll extends View implements Choreographer.FrameCallback {
if(freshCnt < interval) freshCnt++; if(freshCnt < interval) freshCnt++;
else { else {
freshCnt = 1; freshCnt = 1;
if(effect=='t' || effect=='l') { if(direct=='t' || direct=='l') {
if(cur <= end) cur -= end; if(cur <= end) cur -= end;
else cur -= step; else cur -= step;
} else if(effect=='b' || effect=='r') { } else if(direct=='b' || direct=='r') {
if(cur >= end) cur -= end; if(cur >= end) cur -= end;
else cur += step; else cur += step;
} }

View File

@ -25,6 +25,7 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
IjkMediaPlayer ijkPlayer; IjkMediaPlayer ijkPlayer;
ExoPlayer exoPlayer; ExoPlayer exoPlayer;
long bitRate; long bitRate;
long seekTo;
boolean isLive; boolean isLive;
public SrcVideo(Context context, String path, float vol, int dur, boolean useHW, boolean isLive) { public SrcVideo(Context context, String path, float vol, int dur, boolean useHW, boolean isLive) {
@ -48,13 +49,11 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
} }
void initIjk(boolean useHW) { void initIjk(boolean useHW) {
ijkPlayer = new IjkMediaPlayer(); ijkPlayer = new IjkMediaPlayer();
if(useHW) {
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-avc", 1);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", 1);
}
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48); ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 0);
try { try {
setSurfaceTextureListener(this); setSurfaceTextureListener(this);
ijkPlayer.setDataSource(path); ijkPlayer.setDataSource(path);
@ -100,10 +99,11 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
void start() { void start() {
if(ijkPlayer!=null) { if(ijkPlayer!=null) {
ijkPlayer.seekTo(0); ijkPlayer.seekTo(seekTo);
ijkPlayer.start(); ijkPlayer.start();
} else if(exoPlayer!=null) { } else if(exoPlayer!=null) {
if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare(); if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare();
exoPlayer.seekTo(seekTo);
exoPlayer.play(); exoPlayer.play();
} }
} }
@ -146,6 +146,9 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
start(); start();
if(isLive) ijkPlayer.setVolume(vol, vol); if(isLive) ijkPlayer.setVolume(vol, vol);
} else if(isLive) ijkPlayer.setVolume(0, 0); } else if(isLive) ijkPlayer.setVolume(0, 0);
else pause(); else {
seekTo = 0;
pause();
}
} }
} }

View File

@ -23,7 +23,7 @@ import gnph.util.IOs;
public class Util { public class Util {
public static String serverURL; public static String serverURL;
public static int screenWidth, screenHeight; public static int screenWidth = 1920, screenHeight = 1080;
public static boolean isScreenOn; public static boolean isScreenOn;
public static final BitmapFactory.Options noScaled = new BitmapFactory.Options(); public static final BitmapFactory.Options noScaled = new BitmapFactory.Options();