使用SurfaceView播放相机界面,一段时间后卡住不动
已完成手机型号:Redmi Note 7,Android 10
MSDK版本:MSDKV5.3.0 或者 MSDK5.4.0
无人机机型: DJI Mini 3 Pro
问题:使用SurfaceView获取相机界面,刚开始正常,飞行了大约几分钟之后,会出现相机视图卡死不动(sample代码编译出来的版本也有同样问题),但是rtmp推流视频播放正常,代码如下:
public class FlightControlActivity extends AppCompatActivity implements SurfaceHolder.Callback {
private SurfaceView mSurfaceView;
private VideoDecoder videoDecoder = null;
private final Thread sendDataThread = new Thread(new SendDataThread());
private final Handler freshHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message message) {
if (message.what == 1) {
.....
}
return false;
}
});
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (this.videoDecoder == null) {
this.videoDecoder = new VideoDecoder(
this,
VideoChannelType.PRIMARY_STREAM_CHANNEL,
DecoderOutputMode.SURFACE_MODE,
this.mSurfaceView.getHolder(),
this.mSurfaceView.getWidth(),
this.mSurfaceView.getHeight(),
true);
FlightControlActivity.this.initListen();
} else if (this.videoDecoder.getDecoderStatus() == DecoderState.PAUSED) {
this.videoDecoder.onResume();
}
LogUitl.i(TAG, "surfaceChanged...");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (this.videoDecoder == null) {
this.videoDecoder = new VideoDecoder(
this,
VideoChannelType.PRIMARY_STREAM_CHANNEL,
DecoderOutputMode.SURFACE_MODE,
this.mSurfaceView.getHolder(),
this.mSurfaceView.getWidth(),
this.mSurfaceView.getHeight(),
true);
FlightControlActivity.this.initListen();
} else if (this.videoDecoder.getDecoderStatus() == DecoderState.PAUSED) {
this.videoDecoder.onResume();
}
LogUitl.i(TAG, "surfaceCreated...");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (this.videoDecoder != null) {
this.videoDecoder.onPause();
}
LogUitl.i(TAG, "surfaceDestroyed...");
}
public void onDetachedFromWindow() {
if (this.videoDecoder != null) {
this.videoDecoder.destroy();
this.videoDecoder = null;
}
super.onDetachedFromWindow();
LogUitl.i(TAG, "onDetachedFromWindow...");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flight);
this.mSurfaceView = (SurfaceView) findViewById(R.id.fpv_widget);
this.mSurfaceView.getHolder().addCallback(this);
this.sendDataThread.start();
}
private void initListen() {
this.videoDecoder.addDecoderStateChangeListener(new DecoderStateChangeListener() {
public void onUpdate(DecoderState from, DecoderState to) {
LogUitl.i(TAG, "DecoderState from:" + from + " to:" + to);
}
});
}
@Override
public void onDestroy() {
this.freshHandler.removeCallbacksAndMessages(null);
this.sendDataThread.interrupt();
super.onDestroy();
}
private class SendDataThread implements Runnable {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(4000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (!FlightControlActivity.this.isStopSendData) {
try {
Message message = .....;
FlightControlActivity.this.freshHandler.sendMessage(message);
} catch (Exception e) {
LogUitl.e(TAG, "timeRunnable except:" + e.toString());
}
}
}
}
}
}
xml布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:background="@drawable/fpv_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/fpv_widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
求助几个问题:
1、请帮忙看下代码是否有问题呢?界面卡死是什么原因呢?
2、我在论坛看到自定义视图必须设置宽度和高度必须是16的倍数,我的布局在上面,这个有什么影响吗?
3、是否有渠道把代码完整发给你们的开发者帮忙看下吗?定位了很久实在不知道哪里有问题。
-
卡死之后,代码中有出现异常报错信息么?如果有可以提供给我们。同时希望你可以录制一个视频让我们更加直观的观察问题。上传地址:https://pan-sec.djicorp.com/s/Jkc94b8Tz8njqd8 -
录了一个视频,主要就是运行一段时间之后,晃动飞机,app界面的视频就卡住不动了。
请先登录再写评论。
评论
5 条评论