chewie
chewie copied to clipboard
unable to click controls
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
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:flutter_screenutil/flutter_screenutil.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 _videoPlayerController;
ChewieController? _chewieController;
int? bufferDelay;
@override
void initState() {
super.initState();
initializePlayer();
}
@override
void dispose() {
_videoPlayerController.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 {
_videoPlayerController = VideoPlayerController.network(srcs[currPlayIndex]);
await Future.wait([
_videoPlayerController.initialize(),
]);
_createChewieController();
setState(() {});
}
void _createChewieController() {
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
progressIndicatorDelay: Duration(seconds: 1),
additionalOptions: (context) {
return <OptionItem>[
OptionItem(
onTap: toggleVideo,
iconData: Icons.live_tv_sharp,
title: 'Toggle Video Src',
),
];
},
customControls: MaterialControls(
showPlayButton: true,
),
hideControlsTimer: const Duration(seconds: 3),
// materialProgressColors: ChewieProgressColors(
// playedColor: Colors.red,
// handleColor: Colors.blue,
// backgroundColor: Colors.grey,
// bufferedColor: Colors.lightGreen,
// ),
// placeholder: Container(
// color: Colors.grey,
// ),
// autoInitialize: true,
);
}
int currPlayIndex = 0;
Future<void> toggleVideo() async {
await _videoPlayerController.pause();
currPlayIndex += 1;
if (currPlayIndex >= srcs.length) {
currPlayIndex = 0;
}
await initializePlayer();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
colorScheme: const ColorScheme.light(secondary: Colors.red),
disabledColor: Colors.grey.shade400,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
splashRadius: 10.sp,
icon: Container(
height: kToolbarHeight,
width: kToolbarHeight,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(100)
),
child: Icon(Icons.arrow_back_rounded, color: Colors.white, size: 22.sp)
),
onPressed: (){
Navigator.pop(context);
},
),
),
extendBody: true,
extendBodyBehindAppBar: true,
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'),
],
),
),
),
SizedBox(height: 100.sp,)
],
),
),
);
}
}
@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
`extendBodyBehindAppBar: true`
`extendBodyBehindAppBar: false`
I got the same issue. have you found a way to solve it?