我已经按照全景演示示例连接到无人机。我正在使用正确的型号和DJICamera获得DJIAircraft,但视频永远不会启动(没有图像& 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)")
}
}
答案 0 :(得分:0)
我知道它已经很晚但我们在App中遇到了类似的问题,问题是当DJI无人机连接时,我们在连接时没有拿到相机的实例。连接后添加5-10秒的延迟。我已经做了类似的事情,它现在适用于每个无人机。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(7 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
let camera = ConnectedDroneManager.sharedDroneInstance.fetchCamera()
camera?.delegate = self
camera?.playbackManager?.delegate = self
})
希望这会对你有所帮助。
答案 1 :(得分:0)
您应该在应用连接到DJI产品后启动视频流。将VideoPreviewer.instance().start()
放入sdkManagerProductDidChange
委托方法可以解决问题。
func sdkManagerDidRegisterAppWithError(_ error: Error?) {
guard error == nil else {
makeToast("Error registering SDK Manager \(error)")
return
}
DJISDKManager.startConnectionToProduct()
VideoPreviewer.instance().start()
makeToast("Registered app with DJISDKManager")
}
答案 2 :(得分:-1)
DJI的iOS PanoDemo是用Objective-C编写的,我在Phantom 4 Pro上试过,演示应用程序可以成功显示实时视频。好像你正在使用Swift编写自己的DJI SDK应用程序。
在您上面显示的代码中,我认为您尚未成功注册该应用。在registerApp()
乐趣中,您通过&#34; ******************&#34;在DJISDKManager.registerApp()方法中,这是不正确的,你应该在DJI开发者网站用户中心使用你的Xcode的包ID创建一个App密钥:https://developer.dji.com/user/apps/,然后将其粘贴到{{1}方法。
更多信息,您可以按照Github上的DJI Swift示例代码:https://github.com/dji-sdk/Mobile-SDK-iOS/tree/master/Sample%20Code/SwiftSampleCode了解如何制作自己的DJI SDK应用。希望这有帮助!