MSDK V5使用FPVWidget,始终不显示画面,配置程序是否如下
CompletedprimaryFpvWidget = findViewById<FPVWidget>(R.id.widget_primary_fpv)
val primaryChannel =
MediaDataCenter.getInstance().videoStreamManager.getAvailableVideoChannel(
VideoChannelType.PRIMARY_STREAM_CHANNEL
)
if (primaryChannel != null) {
primaryChannelStateListener =
VideoChannelStateChangeListener { from: VideoChannelState?, to: VideoChannelState ->
val primaryStreamSource =
primaryChannel.streamSource
if (VideoChannelState.ON == to && primaryStreamSource != null) {
runOnUiThread {
primaryFpvWidget?.updateVideoSource(
primaryStreamSource,
VideoChannelType.PRIMARY_STREAM_CHANNEL
)
}
}
}
primaryChannel.addVideoChannelStateChangeListener(primaryChannelStateListener)
}
MediaDataCenter.getInstance().videoStreamManager.addStreamSourcesListener { sources: List<StreamSource?>? ->
runOnUiThread { updateFPVWidgetSource(sources as List<StreamSource>?) }
}
primaryFpvWidget?.setOnFPVStreamSourceListener(object : FPVStreamSourceListener {
override fun onStreamSourceUpdated(
devicePosition: PhysicalDevicePosition,
lensType: CameraLensType
) {
LogUtils.i(TAG, devicePosition, lensType)
cameraSourceProcessor.onNext(CameraSource(devicePosition, lensType))
}
})
-
在按照教程导入UXSDK模块之后,可以参考下面的MainActivity.java文件去显示画面: package com.dji.myapplication import android.opengl.Visibility import android.os.Bundle import android.util.Log import android.view.View import android.view.View.INVISIBLE import android.view.View.VISIBLE import androidx.appcompat.app.AppCompatActivity import dji.v5.common.error.IDJIError import dji.v5.common.register.DJISDKInitEvent import dji.v5.common.video.stream.StreamSource import dji.v5.manager.SDKManager import dji.v5.manager.datacenter.video.VideoStreamManager import dji.v5.manager.interfaces.SDKManagerCallback import dji.v5.ux.core.widget.fpv.* class MainActivity : AppCompatActivity() { private val TAG = "myApp" protected var primaryFpvWidget: FPVWidget? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) registerApp() primaryFpvWidget = findViewById(R.id.widget_primary_fpv) **primaryFpvWidget?.visibility = INVISIBLE** } private fun registerApp() { SDKManager.getInstance().init(this, object : SDKManagerCallback { override fun onRegisterSuccess() { Log.i(TAG, "myApp onRegisterSuccess") } override fun onRegisterFailure(error: IDJIError) { Log.i(TAG, "myApp onRegisterFailure") } override fun onProductDisconnect(productId: Int) { Log.i(TAG, "myApp onProductDisconnect") } override fun onProductConnect(productId: Int) { Log.i(TAG, "myApp onProductConnect") VideoStreamManager.getInstance().addStreamSourcesListener() { it?.let { if(it.size > 0) **primaryFpvWidget?.visibility = VISIBLE** } } } override fun onProductChanged(productId: Int) { Log.i(TAG, "myApp onProductChanged") } override fun onInitProcess(event: DJISDKInitEvent, totalProcess: Int) { Log.i(TAG, "myApp onInitProcess") if (event == DJISDKInitEvent.INITIALIZE_COMPLETE) { Log.i(TAG, "myApp start registerApp") SDKManager.getInstance().registerApp() } } override fun onDatabaseDownloadProgress(current: Long, total: Long) { Log.i(TAG, "myApp onDatabaseDownloadProgress") } }) } } 我在项目里导入了UXSDK模块,然后在MainActivity里配置FPVWidget。需要关注的是加粗的部分。效果如下: ![](https://djisdksupport.zendesk.com/attachments/token/peQyTXseUBqeFPNajF7kPZy3v/?name=image.png)
Please sign in to leave a comment.
Comments
3 comments