Skip to main content
Language

Deserialization of Video Segments

VideoEditor SDK for Flutter supports serialization and deserialization of the video composition segments, allowing your users to save and revise their work at any time.

Loading a serialization#

To restore a previously saved state, we first need to retrieve the previously saved video segments as well as the video size. For this example, we are using hardcoded placeholder values.

To open the editor with the selected segments and size, you need to use the Video.fromSegments initializer and pass it to the VESDK.openEditor method as the video parameter.

import 'package:catalog/models/code_example.dart';
import 'package:flutter/material.dart';
import 'package:video_editor_sdk/video_editor_sdk.dart';
class VideoSegmentsDeserializationExample extends CodeExample {
void invoke() async {
try {
// Add a video consisting out of video segments.
final video = Video.fromSegments(segments: [
VideoSegment("assets/Skater.mp4", startTime: 0.5, endTime: 2.5)
], size: const Size(450, 450));
// Open the video editor and handle the export as well as any occurring errors.
final result = await VESDK.openEditor(video);
if (result != null) {
// The user exported a new video successfully and the newly generated video is located at `result.video`
// and the serialization is located at `result.serialization`.
print(result.serialization);
} else {
// The user tapped on the cancel button within the editor.
return;
}
} catch (error) {
// There was an error generating the video.
print(error);
}
// highlight-events
}
}