dji-sdk / Mobile-SDK-iOS

DJI Mobile SDK for iOS: http://developer.dji.com/mobile-sdk/
Other
579 stars 253 forks source link

Camera is busy or the command is not supported in the camera's current state(code:-3002) #464

Open ramdhasm opened 3 years ago

ramdhasm commented 3 years ago

When i try to get the last captured image, i'm getting this error: Camera is busy or the command is not supported in the camera's current state(code:-3002). Always newMedia.fetchData callback throws this error.

func camera(_ camera: DJICamera, didGenerateNewMediaFile newMedia: DJIMediaFile) {
    print("Generate new media file: \(newMedia.fileName), duration: \(newMedia.durationInSeconds)")

    newMedia.fetchThumbnail { (error) in
        let image = newMedia.thumbnail
    }

    getImages(with: newMedia)

    newMedia.fetchData(withOffset: 0, update: DispatchQueue.main, update: {(_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in
        let manager = camera.mediaManager!

        if error != nil {
            print("State: \(manager.sdCardFileListState.rawValue)")
            print("Error downloading photo: \(error!)")
        }
        else {
            if let data = data, let downloadedImage = UIImage(data: data) {
                print("Image was downloaded!")
                print(downloadedImage)
            }
        }
    })
}
dji-dev commented 3 years ago

Agent comment from Luce Luo in Zendesk ticket #48323:

Dear Customer,

Thank you for contacting DJI. It should be the DOWNLOAD mode first, please check it setMode:withCompletion.

Thanks,

Luce Luo DJI Developer Support

°°°

caiodataopshouse commented 1 year ago

Hello. I'm having the same problem. But I'm using Mini 2 and apparently setMode is not supported.. I tried to add camera.enterPlayback(), but no success.

func camera(_ camera: DJICamera, didGenerateNewMediaFile newMedia: DJIMediaFile) {
      camera.enterPlayback()
        newMedia.fetchData(withOffset: 0, update: DispatchQueue.main, update: { [self](_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in

                                if error != nil {
                                    testlabel.text = "\(error!.localizedDescription)"
                                    print("State:")
                                    print("Error downloading photo: \(error!)")
                                }
                                else {
                                    // unwrap downloaded data and create image
                                    guard let data = data else {return}
                                    let downloadedImage = UIImage(data: data)
                                    pictureview.image = downloadedImage

                                }

            guard isComplete else {return}
            camera.exitPlayback()
})