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">
<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="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />

View File

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

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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.READ_EXTERNAL_STORAGE" />

View File

@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Environment;
import android.view.View;
public class BackView extends View {
@ -14,17 +13,18 @@ public class BackView extends View {
Bitmap cosImg;
Rect rect = new Rect();
public BackView(Context context, int width, int height) {
public BackView(Context context) {
super(context);
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back, Util.noScaled);
cosImg = BitmapFactory.decodeFile(Util.backImgFile, Util.noScaled);
rect.right = width;
rect.bottom = height;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
rect.right = Util.screenWidth;
rect.bottom = Util.screenHeight;
canvas.clipRect(rect);
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);
}

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

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.CountDownTimer;
import android.speech.tts.TextToSpeech;
@ -204,17 +205,27 @@ public class Prog extends AbsLayout {
var imgView = new ImageView(context);
var file = Util.programDir+"/"+id;
new Thread(()->{
var ttt = System.currentTimeMillis();
var img = BitmapFactory.decodeFile(file);
try {
var ttt = System.currentTimeMillis();
var img = BitmapFactory.decodeFile(file);
// if(img.getByteCount()>1500*1500*4) {
// var matrix = new Matrix();
// matrix.setScale(0.5f, 0.5f);
// img = Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), matrix, true);
// }
ttt = System.currentTimeMillis() - ttt;
Util.println(" img "+img.getWidth()+"x"+img.getHeight()+" "+ttt);
Bitmap finalImg = img;
MainActivity.ins.runOnUiThread(() -> imgView.setImageBitmap(finalImg));
ttt = System.currentTimeMillis() - ttt;
Util.println(" img "+img.getWidth()+"x"+img.getHeight()+" "+ttt);
Bitmap finalImg = img;
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();
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
src.view = imgView;
@ -242,6 +253,20 @@ public class Prog extends AbsLayout {
} else if(src.type.equals("Audio")) {
if(id==null) continue;
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")) {
JSList<JSMap> imgs = source.jslist("arrayPics");
if(imgs.isEmpty()) continue;
@ -250,7 +275,20 @@ 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 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) {
src.text = img.str("text");
if(src.text!=null) {
@ -329,9 +367,11 @@ public class Prog extends AbsLayout {
prefix += "height:"+geo.height+"; font-size:"+fontSize+"px;\">";
var suffix = "</body><script>window.onload = function() {\n" +
"window.java.setWidth(document.body.scrollWidth);};</script>";
source.put("effect", "to left");
source.put("effectSpeed", source.intg("speed"));
var view = new SrcScroll(this, source, Bitmap.createBitmap(geo.width, geo.height, Bitmap.Config.ARGB_8888));
var speed = source.dbl("speed");
if(speed!=0) speed = 1000.0 / speed;
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;
webView.addJavascriptInterface(new Object() {
@JavascriptInterface
@ -351,8 +391,8 @@ public class Prog extends AbsLayout {
webView.draw(canvas);
webView.setVisibility(GONE);
view.freshCnt = view.cur = 0;
if(view.effect=='l') view.end = -(view.imgs.get(0).getWidth()-view.step);
else if(view.effect=='r') 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.direct=='r') view.end = view.imgs.get(0).getWidth()-view.step;
view.invalidate();
}
};
@ -635,14 +675,17 @@ public class Prog extends AbsLayout {
for(var layer : layers) for(var src : layer.srcs) src.hide();
}
void setMillis(long milli) {
endMilli = milli + sDur;
void setMillis(long start, long cur) {
endMilli = start + sDur;
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) {
src.endMilli = milli + src.endTime;
src.startMilli = milli + src.startTime;
if(src.startTime == 0) src.show();
src.endMilli = start + src.endTime;
src.startMilli = start + src.startTime;
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(milli >= src.endMilli) src.hide();
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) {
layer.endMilli += layer.dur;

View File

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

View File

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

View File

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

View File

@ -25,6 +25,7 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
IjkMediaPlayer ijkPlayer;
ExoPlayer exoPlayer;
long bitRate;
long seekTo;
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) {
ijkPlayer = new IjkMediaPlayer();
if(useHW) {
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-avc", 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_FORMAT, "analyzeduration", 1);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 0);
try {
setSurfaceTextureListener(this);
ijkPlayer.setDataSource(path);
@ -100,10 +99,11 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
void start() {
if(ijkPlayer!=null) {
ijkPlayer.seekTo(0);
ijkPlayer.seekTo(seekTo);
ijkPlayer.start();
} else if(exoPlayer!=null) {
if(exoPlayer.getPlaybackState()==ExoPlayer.STATE_IDLE) exoPlayer.prepare();
exoPlayer.seekTo(seekTo);
exoPlayer.play();
}
}
@ -146,6 +146,9 @@ public class SrcVideo extends TextureView implements TextureView.SurfaceTextureL
start();
if(isLive) ijkPlayer.setVolume(vol, vol);
} 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 static String serverURL;
public static int screenWidth, screenHeight;
public static int screenWidth = 1920, screenHeight = 1080;
public static boolean isScreenOn;
public static final BitmapFactory.Options noScaled = new BitmapFactory.Options();