Isvisoft / flutter_screen_recording

A new Flutter plugin for record the screen.
MIT License
142 stars 138 forks source link

Recording Screen & audio is not working properly on IOS #78

Closed danglu999 closed 6 months ago

danglu999 commented 1 year ago

Hi, Thanks for your great work. Recording screen can work well, while I choose record screen & audio, only 1 second is recorded whenever I tap Stop Record.

Flutter version: 3.3.8

jayu146 commented 1 year ago

Hello @danglu999 I found one solution and I implemented this solution in my project it is working fine. You need to change swift code in SwiftFlutterScreenRecordingPlugin this file. And it is package file.

switch rpSampleBufferType {
            case .video:

                print("writing sample....")

                if self.assetWriter?.status == AVAssetWriter.Status.unknown {

                    print("Started writing")
                    self.assetWriter?.startWriting()
                    self.assetWriter?.startSession(atSourceTime: CMSampleBufferGetPresentationTimeStamp(cmSampleBuffer))
                }

                if self.assetWriter.status == AVAssetWriter.Status.failed {
                    print("StartCapture Error Occurred, Status = \(self.assetWriter.status.rawValue), \(self.assetWriter.error!.localizedDescription) \(self.assetWriter.error.debugDescription)")
                     return
                }

                if self.assetWriter.status == AVAssetWriter.Status.writing {
                    if self.videoInput.isReadyForMoreMediaData {
                        print("Writing a sample")
                        if self.videoInput.append(cmSampleBuffer) == false {
                             print("problem writing video")
                        }
                     }
                 }

            case .audioMic:
                if self.audioMicInput.isReadyForMoreMediaData {
                    print("audioMic data added")
                    self.audioMicInput.append(cmSampleBuffer)
                }

            default:
                print("not a video sample")
            }

please add one case in above switch case case .audioMic: and also you need to add this switch condition in DispatchQueue.main.async

After that I able to record audio and video in iPhone real device. For your reference follow below link for solution : https://stackoverflow.com/questions/59613660/rpscreenrecorder-shared-startcapture-wont-write-keeps-failing

nikky78 commented 11 months ago

Is there any updates please ? It still doesn't work on ios

ttariq7 commented 8 months ago

Any updates on this? or @jayu146 are you able to help me implement your solution? Do I need to make a fork of this project and then make the changes. I was a bit confused what to do with "also you need to add this switch condition in DispatchQueue.main.async"

vsaase commented 7 months ago

@nikky78 @ttariq7 Screen and audio capture works for me, I implemented the suggested changes in my fork Thanks @jayu146