package com.dji.FPVDemo;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import com.secneo.sdk.Helper;
public class MApplication extends Application {
private FPVDemoApplication fpvDemoApplication;
@Override
protected void attachBaseContext(Context paramContext) {
super.attachBaseContext(paramContext);
Helper.install(MApplication.this);//即指定一种应用程序的加载形式 实质是利用DexInstall进行加载SDK
if (fpvDemoApplication == null) {
fpvDemoApplication = new FPVDemoApplication();//为空则创建实例
fpvDemoApplication.setContext(this);
}
}
@Override
public void onCreate() {
super.onCreate();
fpvDemoApplication.onCreate();
}
}
package com.dji.FPVDemo;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;
import dji.common.error.DJIError;
import dji.common.error.DJISDKError;
import dji.sdk.base.BaseComponent;
import dji.sdk.base.BaseProduct;
import dji.sdk.camera.Camera;
import dji.sdk.products.Aircraft;
import dji.sdk.products.HandHeld;
import dji.sdk.sdkmanager.DJISDKManager;
public class FPVDemoApplication extends Application{
public static final String FLAG_CONNECTION_CHANGE = "fpv_tutorial_connection_change";
private DJISDKManager.SDKManagerCallback mDJISDKManagerCallback;//管理器回调接口
private static BaseProduct mProduct;//产品类
public Handler mHandler;//Handler
private Application instance;
/**
* 为当前类中Application变量进行赋值的方法
* @param application
*/
public void setContext(Application application) {
instance = application;
}
/**
* 获取类中Application变量的方法
* @return
*/
@Override
public Context getApplicationContext() {
return instance;
}
/**
* 无参的构造函数
*/
public FPVDemoApplication() {
}
/**
* 获取连接的产品对象
*/
public static synchronized BaseProduct getProductInstance() {
if (null == mProduct) {
mProduct = DJISDKManager.getInstance().getProduct();
}
return mProduct;
}
/**
* 获取连接的产品相机对象
* @return
*/
public static synchronized Camera getCameraInstance() {
if (getProductInstance() == null) return null;
Camera camera = null;
//判别是无人机还是手持的云台设备
if (getProductInstance() instanceof Aircraft){
camera = ((Aircraft) getProductInstance()).getCamera();
} else if (getProductInstance() instanceof HandHeld) {
camera = ((HandHeld) getProductInstance()).getCamera();
}
return camera;
}
@Override
public void onCreate() {
super.onCreate();
mHandler = new Handler(Looper.getMainLooper());//新建在主线程中执行的handler,方便更新UI
/**
*当启动SDK服务时,利用接口DJISDKManager.DJISDKManagerCallback
* 的实例侦听SDK注册结果和产品更改。
*/
mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {
//监听注册结果
@Override
public void onRegister(DJIError djiError) {
if(djiError == DJISDKError.REGISTRATION_SUCCESS) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Register Success", Toast.LENGTH_LONG).show();
}
});//回到主线程进行消息的提示
DJISDKManager.getInstance().startConnectionToProduct();
} else {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Register sdk fails, check network is available", Toast.LENGTH_LONG).show();
}
});
}
Log.e("TAG", djiError.toString());
}
/**
* 监听产品是否处于断开连接状态
*/
@Override
public void onProductDisconnect() {
Log.d("TAG", "onProductDisconnect");
notifyStatusChange();
}
/**
* 监听产品是否处于连接状态
*/
@Override
public void onProductConnect(BaseProduct baseProduct) {
Log.d("TAG", String.format("onProductConnect newProduct:%s", baseProduct));
notifyStatusChange();
}
/**
* 监听产品中各种组件(相机,万向节等等)的连接状态
* @param componentKey
* @param oldComponent
* @param newComponent
*/
@Override
public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
BaseComponent newComponent) {
if (newComponent != null) {
newComponent.setComponentListener(new BaseComponent.ComponentListener() {
@Override
public void onConnectivityChange(boolean isConnected) {
Log.d("TAG", "onComponentConnectivityChanged: " + isConnected);
notifyStatusChange();
}
});
}
Log.d("TAG",
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
componentKey,
oldComponent,
newComponent));
}
};
//针对Android6.0以上的系统在SDK注册时检测权限
int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {
//This is used to start SDK services and initiate SDK.
DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
Toast.makeText(getApplicationContext(), "registering, pls wait...", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
}
}
/**
* 通知状态更新的函数
*/
private void notifyStatusChange() {
mHandler.removeCallbacks(updateRunnable);//关闭之前的定时器
mHandler.postDelayed(updateRunnable, 500);//0.5启动一次
}
/**
* 状态跟新所需要用到的线程
*/
private Runnable updateRunnable = new Runnable() {
@Override
public void run() {
Intent intent = new Intent(FLAG_CONNECTION_CHANGE);
getApplicationContext().sendBroadcast(intent);
}
};
}
package com.dji.FPVDemo;
import android.Manifest;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import dji.common.error.DJIError;
import dji.common.error.DJISDKError;
import dji.log.DJILog;
import dji.sdk.base.BaseComponent;
import dji.sdk.base.BaseProduct;
import dji.sdk.products.Aircraft;
import dji.sdk.sdkmanager.DJISDKManager;
public class ConnectionActivity extends Activity implements View.OnClickListener {
private static final String TAG = ConnectionActivity.class.getName();
private TextView mTextConnectionStatus;//连接状态
private TextView mTextProduct;//产品型号
private TextView mVersionTv;//版本
private Button mBtnOpen;//开启(跳转)按钮
//申请权限声明
private static final String[] REQUIRED_PERMISSION_LIST = new String[]{
Manifest.permission.VIBRATE,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.WAKE_LOCK,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE,
};
private List missingPermission = new ArrayList<>();//权限容器
private AtomicBoolean isRegistrationInProgress = new AtomicBoolean(false);//设置原子布尔变量 并初始化为空
private static final int REQUEST_PERMISSION_CODE = 12345;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkAndRequestPermissions();//检测权限 放在加载布局之前
setContentView(R.layout.activity_connection);
initUI();//初始化UI
// Register the broadcast receiver for receiving the device connection's changes.
IntentFilter filter = new IntentFilter();//新建过滤器
filter.addAction(FPVDemoApplication.FLAG_CONNECTION_CHANGE);//接受状态改变信息
registerReceiver(mReceiver, filter);
}
/**
* Checks if there is any missing permissions, and
* requests runtime permission if needed.
*/
private void checkAndRequestPermissions() {
// Check for permissions
for (String eachPermission : REQUIRED_PERMISSION_LIST) {
if (ContextCompat.checkSelfPermission(this, eachPermission) != PackageManager.PERMISSION_GRANTED) {
missingPermission.add(eachPermission);//将成功授权的权限添加至权限容器
}
}
// Request for missing permissions
if (!missingPermission.isEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions(this,
missingPermission.toArray(new String[missingPermission.size()]),
REQUEST_PERMISSION_CODE);//申请6.0后需要动态申请的权限
}
}
/**
* 申请权限的结果
*/
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Check for granted permission and remove from missing list
if (requestCode == REQUEST_PERMISSION_CODE) {
for (int i = grantResults.length - 1; i >= 0; i--) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
missingPermission.remove(permissions[i]);//在权限容器中删除该权限
}
}
}
// 权限不够不进行注册
if (missingPermission.isEmpty()) {
startSDKRegistration();
} else {
showToast("Missing permissions!!!");
}
}
/**
* 开始进行SDK注册操作
*/
private void startSDKRegistration() {
if (isRegistrationInProgress.compareAndSet(false, true)) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
showToast( "registering, pls wait...");
//调用DJISDKManager的registerApp方法进行SDK注册
DJISDKManager.getInstance().registerApp(getApplicationContext(), new DJISDKManager.SDKManagerCallback() {
@Override
public void onRegister(DJIError djiError) {
if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
DJILog.e("App registration", DJISDKError.REGISTRATION_SUCCESS.getDescription());
DJISDKManager.getInstance().startConnectionToProduct();
showToast("Register Success");
} else {
showToast( "Register sdk fails, check network is available");
}
Log.v(TAG, djiError.getDescription());
}
@Override
public void onProductDisconnect() {
Log.d(TAG, "onProductDisconnect");
showToast("Product Disconnected");
}
@Override
public void onProductConnect(BaseProduct baseProduct) {
Log.d(TAG, String.format("onProductConnect newProduct:%s", baseProduct));
showToast("Product Connected");
}
@Override
public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
BaseComponent newComponent) {
if (newComponent != null) {
newComponent.setComponentListener(new BaseComponent.ComponentListener() {
@Override
public void onConnectivityChange(boolean isConnected) {
Log.d(TAG, "onComponentConnectivityChanged: " + isConnected);
}
});
}
Log.d(TAG,
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
componentKey,
oldComponent,
newComponent));
}
});
}
});
}
}
@Override
public void onResume() {
Log.e(TAG, "onResume");
super.onResume();
}
@Override
public void onPause() {
Log.e(TAG, "onPause");
super.onPause();
}
@Override
public void onStop() {
Log.e(TAG, "onStop");
super.onStop();
}
@Override
protected void onDestroy() {
Log.e(TAG, "onDestroy");
unregisterReceiver(mReceiver);
super.onDestroy();
}
private void initUI() {
mTextConnectionStatus = (TextView) findViewById(R.id.text_connection_status);//连接状态
mTextProduct = (TextView) findViewById(R.id.text_product_info);//产品信息
mBtnOpen = (Button) findViewById(R.id.btn_open);//进入下一个Activity
mBtnOpen.setOnClickListener(this);
mBtnOpen.setEnabled(false);//默认不可点击,当SDK注册成功才可进行点击
mVersionTv = (TextView) findViewById(R.id.textView2);//信息提示
mVersionTv.setText(getResources().getString(R.string.sdk_version, DJISDKManager.getInstance().getSDKVersion()));
}
/**
* 广播接收器,接受状态更改信息,以此更新UI界面
*/
protected BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
refreshSDKRelativeUI();
}
};
/**
* 刷新与SDK相关的界面
*/
private void refreshSDKRelativeUI() {
BaseProduct mProduct = FPVDemoApplication.getProductInstance();
//当产品不为空与产品的连接信息同时满足时
if (null != mProduct && mProduct.isConnected()) {
Log.v(TAG, "refreshSDK: True");
mBtnOpen.setEnabled(true);//使能界面跳转按钮
String str = mProduct instanceof Aircraft ? "DJIAircraft" : "DJIHandHeld";
mTextConnectionStatus.setText("Status: " + str + " connected");
//获取产品型号等信息
if (null != mProduct.getModel()) {
mTextProduct.setText("" + mProduct.getModel().getDisplayName());
} else {
mTextProduct.setText(R.string.product_information);
}
} else {//注册失败结果处理
Log.v(TAG, "refreshSDK: False");
mBtnOpen.setEnabled(false);
mTextProduct.setText(R.string.product_information);
mTextConnectionStatus.setText(R.string.connection_loose);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_open: {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);//跳转至下一个界面
break;
}
default:
break;
}
}
/**
*公用的弹出提示信息的方法
*/
private void showToast(final String toastMsg) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), toastMsg, Toast.LENGTH_LONG).show();
}
});
}
}
package com.dji.FPVDemo;
import android.app.Activity;
import android.graphics.SurfaceTexture;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.TextureView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.TextureView.SurfaceTextureListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import dji.common.camera.SettingsDefinitions;
import dji.common.camera.SystemState;
import dji.common.error.DJIError;
import dji.common.product.Model;
import dji.common.useraccount.UserAccountState;
import dji.common.util.CommonCallbacks;
import dji.sdk.base.BaseProduct;
import dji.sdk.camera.Camera;
import dji.sdk.camera.VideoFeeder;
import dji.sdk.codec.DJICodecManager;
import dji.sdk.useraccount.UserAccountManager;
public class MainActivity extends Activity implements SurfaceTextureListener,OnClickListener{
private static final String TAG = MainActivity.class.getName();
protected VideoFeeder.VideoDataCallback mReceivedVideoDataCallBack = null;//机载视频回传接口
// Codec for video live view
protected DJICodecManager mCodecManager = null;//视频解码器
protected TextureView mVideoSurface = null;//视频加载控件
//捕获,照相,录像等模式选择按钮
private Button mCaptureBtn, mShootPhotoModeBtn, mRecordVideoModeBtn;//负责拍摄的控制按钮
private ToggleButton mRecordBtn;//开始与停止录像切换按钮
private TextView recordingTime;//录像时间
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new Handler();
initUI();//初始化UI
// The callback for receiving the raw H264 video data for camera live view
mReceivedVideoDataCallBack = new VideoFeeder.VideoDataCallback() {
@Override
public void onReceive(byte[] videoBuffer, int size) {
if (mCodecManager != null) {
mCodecManager.sendDataToDecoder(videoBuffer, size);//传数据给视频解码器
}
}
};
Camera camera = FPVDemoApplication.getCameraInstance();//相机实例
if (camera != null) {
camera.setSystemStateCallback(new SystemState.Callback() {
@Override
public void onUpdate(SystemState cameraSystemState) {
if (null != cameraSystemState) {
int recordTime = cameraSystemState.getCurrentVideoRecordingTimeInSeconds();//获取播放时间
int minutes = (recordTime % 3600) / 60;//得到分钟数
int seconds = recordTime % 60;//得到秒数
final String timeString = String.format("%02d:%02d", minutes, seconds);//转换时间
final boolean isVideoRecording = cameraSystemState.isRecording();//播放标志位
//在ui线程更新界面
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
recordingTime.setText(timeString);//设置播放时间
/*
* Update recordingTime TextView visibility and mRecordBtn's check state
*/
if (isVideoRecording){
recordingTime.setVisibility(View.VISIBLE);
}else
{
recordingTime.setVisibility(View.INVISIBLE);
}
}
});
}
}
});
}
}
/**
* 产品更改的方法
*/
protected void onProductChange() {
initPreviewer();
loginAccount();
}
/**
* 登录账号管理
*/
private void loginAccount(){
UserAccountManager.getInstance().logIntoDJIUserAccount(this,
new CommonCallbacks.CompletionCallbackWith() {
@Override
public void onSuccess(final UserAccountState userAccountState) {
Log.e(TAG, "Login Success");
}
@Override
public void onFailure(DJIError error) {
showToast("Login Error:"
+ error.getDescription());
}
});
}
/**
* Activity进行显示的方法
*/
@Override
public void onResume() {
Log.e(TAG, "onResume");
super.onResume();
initPreviewer();
onProductChange();
if(mVideoSurface == null) {
Log.e(TAG, "mVideoSurface is null");
}
}
@Override
public void onPause() {
Log.e(TAG, "onPause");
uninitPreviewer();
super.onPause();
}
@Override
public void onStop() {
Log.e(TAG, "onStop");
super.onStop();
}
public void onReturn(View view){
Log.e(TAG, "onReturn");
this.finish();
}
@Override
protected void onDestroy() {
Log.e(TAG, "onDestroy");
uninitPreviewer();
super.onDestroy();
}
private void initUI() {
// init mVideoSurface
mVideoSurface = (TextureView)findViewById(R.id.video_previewer_surface);//视频显示界面
recordingTime = (TextView) findViewById(R.id.timer);
mCaptureBtn = (Button) findViewById(R.id.btn_capture);
mRecordBtn = (ToggleButton) findViewById(R.id.btn_record);
mShootPhotoModeBtn = (Button) findViewById(R.id.btn_shoot_photo_mode);
mRecordVideoModeBtn = (Button) findViewById(R.id.btn_record_video_mode);
//判断视频界面是否为空
if (null != mVideoSurface) {
mVideoSurface.setSurfaceTextureListener(this);
}
mCaptureBtn.setOnClickListener(this);
mRecordBtn.setOnClickListener(this);
mShootPhotoModeBtn.setOnClickListener(this);
mRecordVideoModeBtn.setOnClickListener(this);
recordingTime.setVisibility(View.INVISIBLE);
mRecordBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
startRecord();
} else {
stopRecord();
}
}
});
}
/**
* 初始化审查器
*/
private void initPreviewer() {
BaseProduct product = FPVDemoApplication.getProductInstance();//获取产品
if (product == null || !product.isConnected()) {
showToast(getString(R.string.disconnected));
} else {
if (null != mVideoSurface) {
mVideoSurface.setSurfaceTextureListener(this);//设置视频显示窗口的监听
}
//检测获取到的产品名称是否为未知的产品,若不是进行视频的最初回调
if (!product.getModel().equals(Model.UNKNOWN_AIRCRAFT)) {
VideoFeeder.getInstance().getPrimaryVideoFeed().setCallback(mReceivedVideoDataCallBack);
}
}
}
/**
* 非初始化审查器
*/
private void uninitPreviewer() {
Camera camera = FPVDemoApplication.getCameraInstance();//获取相机实例
if (camera != null){
//利用VideoFeeder中VideoFeed的接口的setCallback视频资源为空 从而不再加载视频数据
VideoFeeder.getInstance().getPrimaryVideoFeed().setCallback(null);
}
}
/**
* 初始化TextureView
* @param surface
* @param width
* @param height
*/
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.e(TAG, "onSurfaceTextureAvailable");
if (mCodecManager == null) {
mCodecManager = new DJICodecManager(this, surface, width, height);
}
}
/**
* 更改缓冲区大小时使用
* @param surface
* @param width
* @param height
*/
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
Log.e(TAG, "onSurfaceTextureSizeChanged");
}
/**
* 指定SurfaceTexture即将被销毁时调用
* @param surface
* @return
*/
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.e(TAG,"onSurfaceTextureDestroyed");
if (mCodecManager != null) {
mCodecManager.cleanSurface();
mCodecManager = null;
}
return false;
}
/**
* 指定SurfaceTexture的更新时调用
* @param surface
*/
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
public void showToast(final String msg) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
}
/**
* 按钮响应函数
* @param v
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_capture:{
captureAction();
break;
}
case R.id.btn_shoot_photo_mode:{
switchCameraMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO);
break;
}
case R.id.btn_record_video_mode:{
switchCameraMode(SettingsDefinitions.CameraMode.RECORD_VIDEO);//将模式参数进行传递
break;
}
default:
break;
}
}
/**
* 改变相机模式的函数
* @param cameraMode
*/
private void switchCameraMode(SettingsDefinitions.CameraMode cameraMode){
Camera camera = FPVDemoApplication.getCameraInstance();
if (camera != null) {
camera.setMode(cameraMode, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
if (error == null) {
showToast("Switch Camera Mode Succeeded");
} else {
showToast(error.getDescription());
}
}
});
}
}
// 利用相机进行拍照的函数
private void captureAction(){
final Camera camera = FPVDemoApplication.getCameraInstance();//获取相机对象
if (camera != null) {
SettingsDefinitions.ShootPhotoMode photoMode = SettingsDefinitions.ShootPhotoMode.SINGLE; // Set the camera capture mode as Single mode
camera.setShootPhotoMode(photoMode, new CommonCallbacks.CompletionCallback(){
@Override
public void onResult(DJIError djiError) {
if (null == djiError) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
camera.startShootPhoto(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
if (djiError == null) {
showToast("take photo: success");
} else {
showToast(djiError.getDescription());
}
}
});
}
}, 2000);
}
}
});
}
}
/**
* 开始录像的函数
*/
private void startRecord(){
final Camera camera = FPVDemoApplication.getCameraInstance();//获取相机对象
if (camera != null) {
camera.startRecordVideo(new CommonCallbacks.CompletionCallback(){
@Override
public void onResult(DJIError djiError)
{
if (djiError == null) {
showToast("Record video: success");
}else {
showToast(djiError.getDescription());
}
}
}); // Execute the startRecordVideo API
}
}
/**
* 停止摄影方法的函数
*/
private void stopRecord(){
Camera camera = FPVDemoApplication.getCameraInstance();
if (camera != null) {
camera.stopRecordVideo(new CommonCallbacks.CompletionCallback(){
@Override
public void onResult(DJIError djiError)
{
if(djiError == null) {
showToast("Stop recording: success");
}else {
showToast(djiError.getDescription());
}
}
}); // Execute the stopRecordVideo API
}
}
}
DJI源码下载地址:https://github.com/DJI-Mobile-SDK-Tutorials/Android-FPVDemo