mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
99 lines
3.0 KiB
Dart
99 lines
3.0 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_api/api.dart';
|
|
import 'package:tablet_app/constants.dart';
|
|
import 'package:youtube_player_iframe/youtube_player_iframe.dart' as iframe;
|
|
//import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
|
|
|
class VideoViewerYoutube extends StatefulWidget {
|
|
final String videoUrl;
|
|
final bool isAuto;
|
|
final bool webView;
|
|
VideoViewerYoutube({required this.videoUrl, required this.isAuto, this.webView = false});
|
|
|
|
@override
|
|
_VideoViewerYoutube createState() => _VideoViewerYoutube();
|
|
}
|
|
|
|
class _VideoViewerYoutube extends State<VideoViewerYoutube> {
|
|
iframe.YoutubePlayer? _videoViewWeb;
|
|
//YoutubePlayer? _videoView;
|
|
|
|
@override
|
|
void initState() {
|
|
String? videoId;
|
|
if (widget.videoUrl.length > 0 ) {
|
|
//videoId = YoutubePlayer.convertUrlToId(widget.videoUrl);
|
|
|
|
if (widget.webView) {
|
|
final _controllerWeb = iframe.YoutubePlayerController(
|
|
params: iframe.YoutubePlayerParams(
|
|
mute: false,
|
|
showControls: false,
|
|
showFullscreenButton: false,
|
|
loop: false,
|
|
showVideoAnnotations: false,
|
|
strictRelatedVideos: false,
|
|
enableKeyboard: false,
|
|
enableCaption: false,
|
|
pointerEvents: iframe.PointerEvents.auto
|
|
),
|
|
);
|
|
|
|
_controllerWeb.loadVideo(widget.videoUrl);
|
|
if(!widget.isAuto) {
|
|
_controllerWeb.stopVideo();
|
|
}
|
|
|
|
_videoViewWeb = iframe.YoutubePlayer(
|
|
controller: _controllerWeb,
|
|
//showVideoProgressIndicator: false,
|
|
/*progressIndicatorColor: Colors.amber,
|
|
progressColors: ProgressBarColors(
|
|
playedColor: Colors.amber,
|
|
handleColor: Colors.amberAccent,
|
|
),*/
|
|
);
|
|
} else /*{
|
|
// Cause memory issue on tablet
|
|
videoId = YoutubePlayer.convertUrlToId(widget.videoUrl);
|
|
YoutubePlayerController _controller = YoutubePlayerController(
|
|
initialVideoId: videoId!,
|
|
flags: YoutubePlayerFlags(
|
|
autoPlay: widget.isAuto,
|
|
controlsVisibleAtStart: false,
|
|
loop: true,
|
|
hideControls: false,
|
|
hideThumbnail: false,
|
|
),
|
|
);
|
|
|
|
|
|
_videoView = YoutubePlayer(
|
|
controller: _controller,
|
|
//showVideoProgressIndicator: false,
|
|
progressIndicatorColor: Colors.amber,
|
|
progressColors: ProgressBarColors(
|
|
playedColor: Colors.amber,
|
|
handleColor: Colors.amberAccent,
|
|
),
|
|
);
|
|
}*/
|
|
super.initState();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
//_videoView = null;
|
|
_videoViewWeb = null;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => widget.videoUrl.length > 0 ?
|
|
_videoViewWeb!: //(widget.webView ? _videoViewWeb! : _videoView!)
|
|
Center(child: Text("La vidéo ne peut pas être affichée, l'url est incorrecte", style: new TextStyle(fontSize: kNoneInfoOrIncorrect)));
|
|
} |