我遵循全景演示示例并连接到无人机。我得到了一个具有正确型号的 DJIAircraft 和一个 DJICamera,但视频永远不会开始(没有图像和 didReceiveVideoData 永远不会被调用)。如果我切换到 DJI GO 4 应用程序,我可以看到实时视频源。有任何想法吗?
//
// CaptureViewController.swift
//
// MARK: - Source https://developer.dji.com/mobile-sdk/documentation/ios-tutorials/PanoDemo.html
import UIKit
import VideoPreviewer
import ToastSwiftFramework
class CaptureViewController: UIViewController, DJISDKManagerDelegate, DJICameraDelegate, DJIPlaybackDelegate, DJIMissionManagerDelegate, DJIFlightControllerDelegate {
@IBOutlet var fpvPreviewView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
tabBarItem.title = "CAPTURE".localized
VideoPreviewer.instance().setView(fpvPreviewView)
self.registerApp()
}
func registeredAppWithError(error: Error?) {
guard error == nil else {
makeToast("Error registering app \(error)")
return
}
VideoPreviewer.instance().start()
}
//MARK: - DJI Delegate
func registerApp() {
DJISDKManager.registerApp("******************", with: self)
}
func sdkManagerDidRegisterAppWithError(_ error: Error?) {
guard error == nil else {
makeToast("Error registering SDK Manager \(error)")
return
}
DJISDKManager.startConnectionToProduct()
makeToast("Registered app with DJISDKManager")
}
func camera(product: DJIBaseProduct?) -> DJICamera? {
guard let aircraft = DJISDKManager.product() as? DJIAircraft else { return nil }
return aircraft.camera
}
func sdkManagerProductDidChange(from oldProduct: DJIBaseProduct?, to newProduct: DJIBaseProduct?) {
makeToast("Found \(newProduct?.model ?? "")")
guard let camera = camera(product: newProduct) else {
makeToast("No camera!")
return
}
makeToast("Camera \(camera.displayName)")
camera.delegate = self
camera.playbackManager?.delegate = self
}
var receivedVideo = false
func camera(_ camera: DJICamera, didReceiveVideoData videoBuffer: UnsafeMutablePointer<UInt8>, length size: Int) {
makeToast("Receiving video!")
VideoPreviewer.instance().push(videoBuffer, length: Int32(size))
}
func playbackManager(_ playbackManager: DJIPlaybackManager, didUpdate playbackState: DJICameraPlaybackState) {
makeToast("PlaybackState: \(playbackState.playbackMode)")
}
}