Provendor
Provendor

Reputation: 85

Flutter Web- playing uint8list n videoplayer

I am trying to play a local video file on flutter web but am getting stuck after choosing the video. According to this github post, it is possible to play a local video file by converting the uint8list of the video to a blob and then using videoController.network to play the blob: github. The problem is that I am not sure how to convert to a blob properly. How do I convert a uint8list to a blob and then play that blob in the flutter video player?

Upvotes: 4

Views: 4794

Answers (2)

Mohi Dev
Mohi Dev

Reputation: 3386

If you want to play Uint8List in flutter web, please use this code

final blob = html.Blob([savedData], 'audio/webm');
final url = html.Url.createObjectUrlFromBlob(blob);

await player
     .setAudioSource(AudioSource.uri(Uri.parse(url), tag: 'audio'));

Upvotes: 0

Spatz
Spatz

Reputation: 20118

Url.createObjectUrlFromBlob(blob) from dart:html library does the trick:

import 'dart:html' as html;

// ...
    final blob = html.Blob([bytes]);
    final url = html.Url.createObjectUrlFromBlob(blob);
    _controller = VideoPlayerController.network(url);

Upvotes: 11

Related Questions