-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from Ahmadre/issue_35
Issue 35
- Loading branch information
Showing
8 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'dart:html' as html; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:image_picker_web/image_picker_web.dart'; | ||
import 'package:video_player/video_player.dart'; | ||
|
||
class BigVideoUploadView extends StatefulWidget { | ||
const BigVideoUploadView({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<BigVideoUploadView> createState() => _BigVideoUploadViewState(); | ||
} | ||
|
||
class _BigVideoUploadViewState extends State<BigVideoUploadView> { | ||
VideoPlayerController? _controller; | ||
|
||
Future<void> _createVideo(Uint8List bytes) async { | ||
final blob = html.Blob([bytes]); | ||
final url = html.Url.createObjectUrlFromBlob(blob); | ||
_controller = VideoPlayerController.network(url); | ||
await _controller?.initialize(); | ||
setState(() {}); | ||
} | ||
|
||
Future<Uint8List> _loadImage(html.File file) async { | ||
final reader = html.FileReader(); | ||
reader.readAsArrayBuffer(file); | ||
await reader.onLoad.first; | ||
reader.onLoadEnd; | ||
return reader.result as Uint8List; | ||
} | ||
|
||
Future<void> _pickAndLoadVideo() async { | ||
final file = await ImagePickerWeb.getVideoAsFile(); | ||
if (file != null) { | ||
final bytes = await _loadImage(file); | ||
await _createVideo(bytes); | ||
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_controller?.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final controller = _controller; | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Big Video Upload')), | ||
floatingActionButton: controller != null | ||
? FloatingActionButton( | ||
onPressed: () { | ||
setState(() { | ||
controller.value.isPlaying | ||
? controller.pause() | ||
: controller.play(); | ||
}); | ||
}, | ||
child: Icon( | ||
controller.value.isPlaying ? Icons.pause : Icons.play_arrow, | ||
), | ||
) | ||
: null, | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
if (controller != null && controller.value.isInitialized) | ||
AspectRatio( | ||
aspectRatio: controller.value.aspectRatio, | ||
child: VideoPlayer(controller), | ||
), | ||
ElevatedButton( | ||
onPressed: _pickAndLoadVideo, | ||
child: Text('Load Video with FileReader'), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters