Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.20 KB | None | 0 0
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:video_player/video_player.dart';
  4. import './drawer.dart';
  5.  
  6. class VideoPlayerScreen extends StatefulWidget {
  7.   VideoPlayerScreen({Key key}) : super(key: key);
  8.  
  9.   @override
  10.   _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
  11. }
  12.  
  13. class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  14.   double _value = 0.0;
  15.   void _setvalue(double value) => setState(() => _value = value);
  16.  
  17.   VideoPlayerController _controller;
  18.   Future<void> _initializeVideoPlayerFuture;
  19.  
  20.   @override
  21.   void initState() {
  22.     // Create and store the VideoPlayerController. The VideoPlayerController
  23.     // offers several different constructors to play videos from assets, files,
  24.     // or the internet.
  25.     _controller = VideoPlayerController.network(
  26.       'https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8',
  27.     );
  28.  
  29.     // Initialize the controller and store the Future for later use.
  30.     _initializeVideoPlayerFuture = _controller.initialize();
  31.  
  32.     // Use the controller to loop the video.
  33.     _controller.setLooping(true);
  34.  
  35.     super.initState();
  36.   }
  37.  
  38.   @override
  39.   void dispose() {
  40.     // Ensure disposing of the VideoPlayerController to free up resources.
  41.     _controller.dispose();
  42.  
  43.     super.dispose();
  44.   }
  45.  
  46.   @override
  47.   Widget build(BuildContext context) {
  48.     return Scaffold(
  49.       drawer: DrawerList(),
  50.       // Use a FutureBuilder to display a loading spinner while waiting for the
  51.       // VideoPlayerController to finish initializing.
  52.       body: Container(
  53.         alignment: Alignment.center,
  54.         child: FutureBuilder(
  55.           future: _initializeVideoPlayerFuture,
  56.           builder: (context, snapshot) {
  57.             if (snapshot.connectionState == ConnectionState.done) {
  58.               // If the VideoPlayerController has finished initialization, use
  59.               // the data it provides to limit the aspect ratio of the video.
  60.               return AspectRatio(
  61.                 aspectRatio: _controller.value.aspectRatio,
  62.                 // Use the VideoPlayer widget to display the video.
  63.                 child: VideoPlayer(_controller),
  64.               );
  65.             } else {
  66.               // If the VideoPlayerController is still initializing, show a
  67.               // loading spinner.
  68.               return Center(child: CircularProgressIndicator());
  69.             }
  70.           },
  71.         ),
  72.       ),
  73.       bottomNavigationBar: BottomAppBar(
  74.         child: FloatingActionButton(
  75.           onPressed: () {
  76.             // Wrap the play or pause in a call to `setState`. This ensures the
  77.             // correct icon is shown.
  78.             setState(() {
  79.               // If the video is playing, pause it.
  80.               if (_controller.value.isPlaying) {
  81.                 _controller.pause();
  82.               } else {
  83.                 // If the video is paused, play it.
  84.                 _controller.play();
  85.               }
  86.             });
  87.           },
  88.           child: Icon(
  89.             _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
  90.           ),
  91.         ),
  92.       ),
  93.       // This trailing comma makes auto-formatting nicer for build methods.
  94.     );
  95.   }
  96. }
  97. //Volume range selector
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement