rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

Gray Screen, no contents in assetRepresentingSegments() #329

Open joshoconnor89 opened 8 years ago

joshoconnor89 commented 8 years ago

I have two screens, a "Capture Screen", and a "Preview Capture Screen". In the Capture Screen, I am using the SCRecorder record method to record my video, and when I am done the recorder is paused using the SCRecorder paused method. When a "Next" button is pressed on this Capture Screen, it passes the recorder.session object (after the video is paused using paused w/ completion handler) to the Preview Capture Screen. This recorder.session object is then used to populate the video in the Preview Capture Screen. All works great, but one issue.

When the user presses "Next" button extremely quickly (less than a second) after the video is done recording, it fails to pass any content with the recorder.session object. In addition, the SCVideoPlayerView will be entirely Gray with no video or audio output.

Under the gray screen scenario, I've printed it out in the console ("po recordSession.assetRepresentingSegments()") and retrieved: "<AVMutableComposition: 0x12da19310 tracks = ( )>" Why is nothing being passed, and why is this an AVMutableComposition instead of an AVURLAsset?

When I wait more than a second after recording to press the next button, it will successfully pass a valid object, when I print out the same recordSession.assetRepresentingSegments(): <AVURLAsset: 0X12d87a870, URL = file:///private/var/mobile......SCVideo.0.mp4>

Has anyone else experienced a gray screen issue, or no contents in assetRepresentingSegments?
SCREENSHOTS:

//Invalid, causing gray screen screenshot2

//Valid, no gray screen screenshot3

//recordSession.assetsRepresentingSegments either has or does not have proper contents for video screenshot1

richardjkeys commented 8 years ago

We had a similar issue with less powerful devices - 5S and iPod Touches.

I disabled the next button and didn't enable it until the Pause completion handler - touch wood this has sorted the issue.

joshoconnor89 commented 8 years ago

Yeah, that worked. Seems as if SCRecorder needs time to process the video after it is paused, hence the completion handler. Thank you!

benjaminhorner commented 8 years ago

I recommend using the delegate method didCompleteSegment instead of the pause callback. This method is called AFTER each segment is saved to memory. Therefore, you know the segments are all treated before showing your button:

func recorder(recorder: SCRecorder, didCompleteSegment segment: SCRecordSessionSegment?, inSession session: SCRecordSession, error: NSError?) {

// Check that the segment is not nil
// This can occur if there was an error writing the file
// Or if the segment was too short
        if segment != nil { 
             // TODO: Enable your play button here
        }

    }

Note that this delegate is the perfect place to deal with anything segment related, like making sure it is longer than the minimum length you may have set etc…