fetchVideoAsUint8List function

Future<Uint8List> fetchVideoAsUint8List(
  1. String videoUrl
)

Fetches an video from a network URL as a Uint8List.

This function allows you to fetch an video from a network URL and convert it into a Uint8List for further use.

Parameters:

  • videoUrl: A String representing the network URL of the video to be fetched.

Returns: A Future that resolves to a Uint8List containing the video data.

Example Usage:

final Uint8List videoBytes = await fetchImageAsUint8List('https://example.com/video.mp4');

Implementation

Future<Uint8List> fetchVideoAsUint8List(String videoUrl) async {
  final response = await http.get(Uri.parse(videoUrl));

  if (response.statusCode == 200) {
    // Convert the response body to a Uint8List
    final Uint8List uint8List = Uint8List.fromList(response.bodyBytes);
    return uint8List;
  } else {
    throw Exception('Failed to load video: $videoUrl');
  }
}