界面调整

yt_mpremote
liuguijing 5 days ago
parent f1c946172b
commit b646c5436b

@ -364,7 +364,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
@Override
public void run() {
if (photoOrVideo) {
showPhoto(file.getAbsolutePath(),dirPath);
showPhoto(file.getAbsolutePath(), dirPath);
} else {
showVideo(file.getAbsolutePath());
}
@ -459,7 +459,6 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
// photoDialog = AlertDialogUtils.show(this, "照片或视频获取中");
showStreaming(channel, channel - 1, "rtmp://" + mDeviceIp + "/live/0", localIp);
// showStreaming(channel, channel - 1, "rtsp://61.169.135.146:1554/live/11", localIp);
return 0;
@ -530,7 +529,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
*/
}
private void showPhoto(final String filePath,String path) {
private void showPhoto(final String filePath, String path) {
Intent intent = new Intent(this, ImageActivity.class);
intent.putExtra("path", filePath);
intent.putExtra("cmdid", TextUtils.isEmpty(mAppConfig.cmdid) ? "" : mAppConfig.cmdid);
@ -552,6 +551,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
int usb = 0;
int netCamera = 0;
int vendor = 0;
int selfTestingTime = 0;
Integer chVal = Integer.valueOf(channel);
if (mChannelCfgs.containsKey(chVal)) {
JSONObject jsonChannel = mChannelCfgs.get(chVal);
@ -560,7 +560,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
int orientation = jsonChannel.optInt("orientation", 0);
if (orientation > 0) {
rotation = (orientation - 1) * 90;
} else if (orientation == 0){
} else if (orientation == 0) {
rotation = 90;
}
int cameraType = jsonChannel.optInt("cameraType", 0);
@ -568,6 +568,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
netCamera = (cameraType == 2 || cameraType == 4) ? 1 : 0;
vendor = jsonChannel.optInt("vendor", 0);
selfTestingTime = jsonChannel.optInt("selfTestingTime", 0);
}
}
@ -582,7 +583,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
intent.putExtra("vendor", vendor);
intent.putExtra("usb", usb);
intent.putExtra("cmdid", TextUtils.isEmpty(mAppConfig.cmdid) ? "" : mAppConfig.cmdid);
// intent.putExtra("info", info);
intent.putExtra("selfTestingTime", selfTestingTime);
startActivity(intent);
}
@ -709,11 +710,7 @@ public class DeviceActivity extends AppCompatActivity implements View.OnClickLis
finish();
break;
case R.id.refresh:
// loadDeviceInfo(false)
// ;
Intent intent = new Intent(this, StreamActivity.class);
// intent.putExtra("info", info);
startActivity(intent);
loadDeviceInfo(false);
break;
}
}

@ -13,11 +13,14 @@ import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.xypower.mpremote.databinding.ActivityStreamBinding;
import com.xypower.mpremote.utils.AdbUtils;
import com.xypower.mpremote.utils.AlertDialogUtils;
import com.xypower.mpremote.utils.CountdownAlertDialog;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
@ -36,7 +39,7 @@ import androidx.core.content.ContextCompat;
import dadb.AdbShellResponse;
import dadb.Dadb;
public class StreamActivity extends AppCompatActivity implements IVLCVout.Callback, TextureView.SurfaceTextureListener {
public class StreamActivity extends AppCompatActivity implements IVLCVout.Callback, TextureView.SurfaceTextureListener, View.OnClickListener {
private static final String TAG = "VLCPlayer";
private static final int PERMISSION_REQUEST_CODE = 1001;
private static String pushUrl = "";
@ -58,8 +61,11 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
private int rotation;
private int netCamera;
private int vendor;
private int selfTestingTime;
private int channel;
private AlertDialog alertDialog;
private LinearLayout back;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -71,9 +77,7 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
initHandler();
initEvent();
// 检查并请求权限
if (checkPermissions()) {
// initializePlayer();
} else {
if (!checkPermissions()) {
requestPermissions();
}
}
@ -86,6 +90,9 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
case 1:
AlertDialogUtils.dismiss(alertDialog);
break;
case 2:
CountdownAlertDialog.dismiss();
break;
}
}
};
@ -94,11 +101,10 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
private void initView() {
textureView = binding.textureView;
textureView.setSurfaceTextureListener(this);
back = binding.toolbar.back;
back.setOnClickListener(this);
}
private void initIntent() {
Intent intent = getIntent();
mDeviceIp = intent.getStringExtra("deviceIp");
@ -107,30 +113,36 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
rotation = intent.getIntExtra("rotation", -1);
netCamera = intent.getIntExtra("netCamera", 0);
vendor = intent.getIntExtra("vendor", 0);
selfTestingTime = intent.getIntExtra("selfTestingTime", 0);
}
private void initEvent() {
if (netCamera == 0) {
alertDialog = AlertDialogUtils.show(this, "视频加载中");
pushUrl = "rtmp://127.0.0.1/live/" + channel;
} else {
if (selfTestingTime > 0) {
CountdownAlertDialog.show(this, selfTestingTime, new CountdownAlertDialog.OnCountdownFinishedListener() {
@Override
public void onCountdownFinished() {
}
});
}
pushUrl = "rtsp://127.0.0.1:8554/live/" + channel;
}
if (TextUtils.isEmpty(pushUrl)) {
handler.post(() -> Toast.makeText(StreamActivity.this, "未找到推流路径", Toast.LENGTH_LONG).show());
} else {
String cmd = "am start -n com.xypower.mplive/com.xypower.mplive.MainActivity" + " --ei cameraId " + Integer.toString(cameraId) +" --ei channel " + Integer.toString(channel)+ " --ei rotation " + Integer.toString(rotation) + " --ei netCamera " + Integer.toString(netCamera) + " --ei vendor " + Integer.toString(vendor) + " --ei autoStart 1" + " --es url \"" + pushUrl + "\"";
String cmd = "am start -n com.xypower.mplive/com.xypower.mplive.MainActivity" + " --ei cameraId " + Integer.toString(cameraId) + " --ei channel " + Integer.toString(channel) + " --ei rotation " + Integer.toString(rotation) + " --ei netCamera " + Integer.toString(netCamera) + " --ei vendor " + Integer.toString(vendor) + " --ei autoStart 1" + " --es url \"" + pushUrl + "\"";
Runnable runnable = new Runnable() {
@Override
public void run() {
initializePlayer();
}
};
alertDialog = AlertDialogUtils.show(this, "视频加载中");
startStreaming(cmd, runnable);
// runOnUiThread(runnable);
// new Thread(runnable).start();
}
}
@ -166,9 +178,16 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
}
if (adbShellResponse != null) {
if (adbShellResponse.getExitCode() == 0) {
try {
Thread.sleep(150000);
} catch (Exception ex) {
if (netCamera == 0) {
try {
Thread.sleep(150);
} catch (Exception ex) {
}
} else {
try {
Thread.sleep(40000);
} catch (Exception ex) {
}
}
runOnUiThread(runnable);
}
@ -230,7 +249,6 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// initializePlayer();
} else {
Toast.makeText(this, "需要存储权限才能播放视频", Toast.LENGTH_SHORT).show();
finish();
@ -340,6 +358,14 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.back:
finish();
break;
}
}
private String getErrorString(int state) {
switch (state) {
case Media.State.Error:
@ -436,6 +462,7 @@ public class StreamActivity extends AppCompatActivity implements IVLCVout.Callba
@Override
protected void onDestroy() {
super.onDestroy();
CountdownAlertDialog.dismiss();
AlertDialogUtils.dismiss(alertDialog);
releasePlayer();
stopStreaming();

@ -23,6 +23,7 @@ public class AlertDialogUtils {
return loadingDialog;
}
public static void dismiss(AlertDialog loadingDialog) {
if (loadingDialog != null) {
loadingDialog.dismiss();

@ -0,0 +1,93 @@
package com.xypower.mpremote.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.os.CountDownTimer;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.xypower.mpremote.R;
public class CountdownAlertDialog {
private static AlertDialog dialog;
private static CountDownTimer countDownTimer;
private static OnCountdownFinishedListener listener;
// 显示对话框(静态方法)
public static void show(Context context,
int countdownSeconds, OnCountdownFinishedListener listener) {
// 先关闭已存在的对话框
dismiss();
// 创建 AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
TextView viewById = dialogView.findViewById(R.id.tvLoading);
viewById.setText("视频加载倒计时: " + countdownSeconds + " 秒");
builder.setView(dialogView);
builder.setCancelable(true); // 是否允许用户取消
dialog = builder.create();
dialog.show();
CountdownAlertDialog.listener = listener;
// 创建并显示对话框
if (countdownSeconds > 0) {
// 创建倒计时器
countDownTimer = new CountDownTimer(countdownSeconds * 1000, 1000) {
public void onTick(long millisUntilFinished) {
int secondsLeft = (int) (millisUntilFinished / 1000);
viewById.setText("视频加载倒计时: " + secondsLeft + " 秒");
}
public void onFinish() {
dismiss();
if (CountdownAlertDialog.listener != null) {
CountdownAlertDialog.listener.onCountdownFinished();
}
}
}.start();
}
// 设置对话框监听
dialog.setOnCancelListener(dialogInterface -> {
if (CountdownAlertDialog.listener != null) {
CountdownAlertDialog.listener.onCountdownCancelled();
}
dismiss();
});
dialog.setOnDismissListener(dialogInterface -> dismiss());
dialog.show();
}
// 关闭对话框(静态方法)
public static void dismiss() {
if (countDownTimer != null) {
countDownTimer.cancel();
countDownTimer = null;
}
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
dialog = null;
}
listener = null;
}
// 检查对话框是否显示中(静态方法)
public static boolean isShowing() {
return dialog != null && dialog.isShowing();
}
// 回调接口
public interface OnCountdownFinishedListener {
void onCountdownFinished();
default void onCountdownCancelled() {
}
}
}

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -7,67 +7,71 @@
android:fitsSystemWindows="true"
tools:context=".DeviceActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/deviceInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:lineSpacingMultiplier="1.25"
android:singleLine="false"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<Button
android:id="@+id/yt_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="云台控制"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deviceInfo" />
<TextView
android:id="@+id/deviceInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:lineSpacingMultiplier="1.25"
android:singleLine="false"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<TextView
android:id="@+id/phototext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="拍照"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deviceInfo" />
<Button
android:id="@+id/yt_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="云台控制"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deviceInfo" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewPhoto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@+id/phototext" />
<TextView
android:id="@+id/phototext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="拍照"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deviceInfo" />
<TextView
android:id="@+id/videotext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="视频预览"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerViewPhoto" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewPhoto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@+id/phototext" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewVideo"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@+id/videotext" />
<TextView
android:id="@+id/videotext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="视频预览"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerViewPhoto" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@+id/videotext" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

@ -19,12 +19,24 @@
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@+id/toolbar" />-->
<TextureView
android:id="@+id/textureView"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextureView
android:id="@+id/textureView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</FrameLayout>
<!-- <TextureView-->
<!-- android:id="@+id/textureView"-->
<!-- android:layout_gravity="center"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- />-->
<!-- <androidx.media3.ui.PlayerView-->
<!-- android:id="@+id/playerView"-->
<!-- android:layout_width="match_parent"-->

Loading…
Cancel
Save