You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			139 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Dart
		
	
		
		
			
		
	
	
			139 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Dart
		
	
| 
											3 years ago
										 | import 'dart:convert'; | ||
|  | import 'dart:io' as Io; | ||
|  | import 'dart:io'; | ||
|  | import 'dart:typed_data'; | ||
|  | 
 | ||
|  | import 'package:flutter/material.dart'; | ||
|  | import 'package:mohem_flutter_app/classes/colors.dart'; | ||
|  | import 'package:path_provider/path_provider.dart'; | ||
|  | import 'package:video_player/video_player.dart'; | ||
|  | 
 | ||
|  | class ITGAdsScreen extends StatefulWidget { | ||
|  |   final String encodedBytes; | ||
|  |   final String fileExtension; | ||
|  | 
 | ||
|  |   const ITGAdsScreen({required this.encodedBytes, required this.fileExtension}); | ||
|  | 
 | ||
|  |   @override | ||
|  |   _ITGAdsScreenState createState() => _ITGAdsScreenState(); | ||
|  | } | ||
|  | 
 | ||
|  | class _ITGAdsScreenState extends State<ITGAdsScreen> { | ||
|  |   late Future<VideoPlayerController> _futureController; | ||
|  |   late VideoPlayerController _controller; | ||
|  |   bool skip = false; | ||
|  | 
 | ||
|  |   Future<VideoPlayerController> createVideoPlayer() async { | ||
|  |     try { | ||
|  |       Uint8List decodedBytes = base64Decode(widget.encodedBytes.split("base64,").last); | ||
|  |       Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
 | ||
|  |       File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4"); | ||
|  |       file.writeAsBytesSync(decodedBytes); | ||
|  |       VideoPlayerController controller = VideoPlayerController.file(file); | ||
|  |       await controller.initialize(); | ||
|  |       await controller.play(); | ||
|  |       await controller.setVolume(1.0); | ||
|  |       await controller.setLooping(false); | ||
|  |       return controller; | ||
|  |     } catch (e) { | ||
|  |       return new VideoPlayerController.asset("dataSource"); | ||
|  |     } | ||
|  |   } | ||
|  | 
 | ||
|  |   void checkType(){ | ||
|  | 
 | ||
|  |    // getFileTypeDescription(value);
 | ||
|  | 
 | ||
|  | 
 | ||
|  |   } | ||
|  | 
 | ||
|  |   String getFileTypeDescription(String value) { | ||
|  |     switch (value) { | ||
|  |       case ".pdf": | ||
|  |         return "application/pdf"; | ||
|  |       case ".png": | ||
|  |         return "image/png"; | ||
|  |       case ".txt": | ||
|  |         return "text/plain"; | ||
|  |       case ".jpg": | ||
|  |         return "image/jpg"; | ||
|  |       case ".jpeg": | ||
|  |         return "image/jpeg"; | ||
|  |       case ".ppt": | ||
|  |         return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; | ||
|  |       case ".pptx": | ||
|  |         return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; | ||
|  |       case ".doc": | ||
|  |         return "application/vnd.openxmlformats-officedocument.wordprocessingm"; | ||
|  |       case ".docx": | ||
|  |         return "application/vnd.openxmlformats-officedocument.wordprocessingm"; | ||
|  |       case ".xls": | ||
|  |         return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; | ||
|  |       case ".xlsx": | ||
|  |         return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; | ||
|  |       case ".zip": | ||
|  |         return "application/octet-stream"; | ||
|  |       case ".rar": | ||
|  |         return "application/octet-stream"; | ||
|  |       default: | ||
|  |         return ""; | ||
|  |     } | ||
|  |   } | ||
|  | 
 | ||
|  |   @override | ||
|  |   void initState() { | ||
|  |     _futureController = createVideoPlayer(); | ||
|  |     initTimer(); | ||
|  |     super.initState(); | ||
|  |   } | ||
|  | 
 | ||
|  |   void initTimer() { | ||
|  |     Future.delayed(const Duration(milliseconds: 500), () { | ||
|  |       setState(() { | ||
|  |         skip = true; | ||
|  |       }); | ||
|  |     }); | ||
|  |   } | ||
|  | 
 | ||
|  |   @override | ||
|  |   void dispose() { | ||
|  |     _controller.dispose(); | ||
|  |     super.dispose(); | ||
|  |   } | ||
|  | 
 | ||
|  |   @override | ||
|  |   Widget build(BuildContext context) { | ||
|  |     double height = MediaQuery.of(context).size.height * .25; | ||
|  |     return Scaffold( | ||
|  |       body: Column( | ||
|  |         children: [ | ||
|  |           SizedBox( | ||
|  |             height: MediaQuery.of(context).size.height * .3, | ||
|  |             child: FutureBuilder( | ||
|  |               future: _futureController, | ||
|  |               builder: (BuildContext context, AsyncSnapshot<Object?> snapshot) { | ||
|  |                 if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { | ||
|  |                   _controller = snapshot.data as VideoPlayerController; | ||
|  |                   return AspectRatio( | ||
|  |                     aspectRatio: _controller.value.aspectRatio, | ||
|  |                     child: VideoPlayer(_controller), | ||
|  |                   ); | ||
|  |                 } else { | ||
|  |                   return const Center( | ||
|  |                     child: CircularProgressIndicator(), | ||
|  |                   ); | ||
|  |                 } | ||
|  |               }, | ||
|  |             ), | ||
|  |           ), | ||
|  |           if (skip) | ||
|  |             ElevatedButton( | ||
|  |               onPressed: () {}, | ||
|  |               child: const Text("Go To Dashboard"), | ||
|  |             ) | ||
|  |         ], | ||
|  |       ), | ||
|  |     ); | ||
|  |   } | ||
|  | } |