90 lines
2.7 KiB
Dart
90 lines
2.7 KiB
Dart
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:youtube_player_iframe/youtube_player_iframe.dart' as iframe;
|
|
import 'package:youtube_player_iframe/youtube_player_iframe.dart';
|
|
|
|
class VideoViewerYoutube extends StatefulWidget {
|
|
final String videoUrl;
|
|
VideoViewerYoutube({required this.videoUrl});
|
|
|
|
@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 (kIsWeb) {
|
|
final _controllerWeb = iframe.YoutubePlayerController(
|
|
params: iframe.YoutubePlayerParams(
|
|
mute: false,
|
|
showControls: true,
|
|
showFullscreenButton: false,
|
|
loop: true,
|
|
showVideoAnnotations: false,
|
|
strictRelatedVideos: false,
|
|
enableKeyboard: false,
|
|
enableCaption: false,
|
|
pointerEvents: iframe.PointerEvents.auto
|
|
),
|
|
);
|
|
|
|
_controllerWeb.loadVideo(widget.videoUrl);
|
|
|
|
_videoViewWeb = iframe.YoutubePlayer(
|
|
controller: _controllerWeb,
|
|
//showVideoProgressIndicator: false,
|
|
/*progressIndicatorColor: Colors.amber,
|
|
progressColors: ProgressBarColors(
|
|
playedColor: Colors.amber,
|
|
handleColor: Colors.amberAccent,
|
|
),*/
|
|
);
|
|
//} else {
|
|
/*videoId = YoutubePlayer.convertUrlToId(widget.videoUrl);
|
|
YoutubePlayerController _controller = YoutubePlayerController(
|
|
initialVideoId: videoId!,
|
|
flags: YoutubePlayerFlags(
|
|
autoPlay: true,
|
|
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 ?
|
|
(kIsWeb ? _videoViewWeb! : _videoView!):
|
|
Center(child: Text("La vidéo ne peut pas être affichée, l'url est incorrecte", style: new TextStyle(fontSize: 12)));
|
|
} |