Open callmejm opened 2 years ago
@callmejm Thank you for bringing this to our attention. Please create a example project with this code and submit the link here.
That way, myself or @maherjaafar can better assist you. Thanks in advance.
@callmejm this code should work for you.
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class VideoView extends StatefulWidget {
const VideoView({
Key? key,
}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _VideoViewState();
}
}
class _VideoViewState extends State<VideoView> {
late VideoPlayerController _videoPlayerController1;
ChewieController? _chewieController;
int? bufferDelay;
@override
void initState() {
super.initState();
initializePlayer();
}
@override
void dispose() {
_videoPlayerController1.dispose();
_chewieController?.dispose();
super.dispose();
}
List<String> srcs = [
"https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
];
Future<void> initializePlayer() async {
_videoPlayerController1 =
VideoPlayerController.network(srcs[currPlayIndex]);
await Future.wait([
_videoPlayerController1.initialize(),
]);
_createChewieController();
setState(() {});
}
void _createChewieController() {
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController1,
autoPlay: true,
looping: true,
progressIndicatorDelay:
bufferDelay != null ? Duration(milliseconds: bufferDelay!) : null,
additionalOptions: (context) {
return <OptionItem>[
OptionItem(
onTap: toggleVideo,
iconData: Icons.live_tv_sharp,
title: 'Toggle Video Src',
),
];
},
subtitleBuilder: (context, dynamic subtitle) => Container(
padding: const EdgeInsets.all(10.0),
child: subtitle is InlineSpan
? RichText(
text: subtitle,
)
: Text(
subtitle.toString(),
style: const TextStyle(color: Colors.black),
),
),
hideControlsTimer: const Duration(seconds: 1),
);
}
int currPlayIndex = 0;
Future<void> toggleVideo() async {
await _videoPlayerController1.pause();
currPlayIndex += 1;
if (currPlayIndex >= srcs.length) {
currPlayIndex = 0;
}
await initializePlayer();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: _chewieController != null &&
_chewieController!
.videoPlayerController.value.isInitialized
? Chewie(
controller: _chewieController!,
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
CircularProgressIndicator(),
SizedBox(height: 20),
Text('Loading'),
],
),
),
),
const SizedBox(height: 100)
],
),
),
);
}
}
The issue is with extendBodyBehindAppBar
property in the Scaffold
extendBodyBehindAppBar: true
is breaking the controls even if the Chewie widget isn't under the AppBar
I got the same issue. have you found a way to solve it?
I copy example and try to do some modify, however I notice that the player controls unable to click / seek
video_player: ^2.4.5
chewie: ^1.3.4
https://user-images.githubusercontent.com/6957533/177092594-8349ca0e-eb49-4cd4-b4ba-1d1db7fc76da.mp4