Open sparksworld opened 3 months ago
I got the same problem . How to resolve it
I got the same problem . How to resolve it
I can only move the [Chewie] Widget to a stable parent widget.
I got the same problem . How to resolve it
I can only move the [Chewie] Widget to a stable parent widget.
Did you resolve the issue after the move? I replaced it with the better_player module.
I got the same problem . How to resolve it
I can only move the [Chewie] Widget to a stable parent widget.
Did you resolve the issue after the move? I replaced it with the better_player module. I tried various ways to solve it, but it didn't work I have decided to handle the interactive interface myself
same problem
i had some test by offical example (ChewieDemo) , in the official example, ChewieDemo is loaded as the entree node: void main() { runApp( const ChewieDemo(), ); }
If the "home" property of MaterialAPP is set to ChewieDemo() in a new page , when playing a full-screen video, the video switch fails and the screen stays still ( This is a more general scene, because ChewieDemo cannot always be used as the entry widget )
but , use "builder" property with MaterialAPP , playing a full-screen video and switch another one is normal
MaterialApp( // home: Scaffold( // body: Stack( // children: [ // ChewieDemo(), // ], // ), // ), builder: (_,child){ return ChewieDemo(); }, )
So far, I don't know what the problem is and need to debug it further
I got the same problem . How to resolve it
I can only move the [Chewie] Widget to a stable parent widget.
Did you resolve the issue after the move? I replaced it with the better_player module. I tried various ways to solve it, but it didn't work I have decided to handle the interactive interface myself
当进入全屏后,假如外部包裹【Chiewe】的父组件【Dispose】,问题就会出现。我接到的产品需求是在【List】列表页中的每个【item】播放视频,在这种情况下全屏模式会随着【item】的复用出现问题。所以我禁用了全屏模式,添加了按钮跳转到一个独立的大屏播放界面过渡。在单一的新界面使用全屏模式是稳定的。
finally , i rebuild this module to resolve it that full screen change source problem . it means that i must be implement to fullscreen widget and state management and controller bar by myself.
I got the same problem
finally , i rebuild this module to resolve it that full screen change source problem . it means that i must be implement to fullscreen widget and state management and controller bar by myself.
how to you solve it please ?
finally , i rebuild this module to resolve it that full screen change source problem . it means that i must be implement to fullscreen widget and state management and controller bar by myself.
how to you solve it please ?
This is brief implementation that about solve it :
same issue
I guess that since full screen is entering a new page, the changes in page1 parameters cannot be responded to page2 in time (I tried to pass count from page1 to page2 and modify it, and it turned out that only page1 responded to the change).
Therefore, just encapsulate the parameters through ChangeNotifier and use them.
Here is a simple demo
class TestScreen extends StatefulWidget {
const TestScreen({super.key});
@override
State<TestScreen> createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> {
MyChewieControllerNotifier myChewieControllerNotifier =
MyChewieControllerNotifier();
toggleLink() {
myChewieControllerNotifier.updateChewieController(
onTap: _handleTap,
myChangeNotifier: myChewieControllerNotifier,
);
}
void _handleTap() {
toggleLink();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
myChewieControllerNotifier.chewieController == null
? const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 20),
Text('Loading'),
],
)
: Expanded(
child: Chewie(
controller: myChewieControllerNotifier.chewieController!)),
TextButton(onPressed: _handleTap, child: Text('切换链接')),
],
);
}
}
class TestFullScreen extends StatefulWidget {
final MyChewieControllerNotifier myChangeNotifier;
final void Function() onTest1;
const TestFullScreen({
super.key,
required this.onTest1,
required this.myChangeNotifier,
});
@override
State<TestFullScreen> createState() => _TestFullScreenState();
}
class _TestFullScreenState extends State<TestFullScreen> {
@override
void initState() {
widget.myChangeNotifier.addListener(_update);
super.initState();
}
_update() {
setState(() {});
}
@override
void setState(VoidCallback fn) {
if (!mounted) return;
super.setState(fn);
}
@override
void dispose() {
// TODO: implement dispose
widget.myChangeNotifier.removeListener(_update);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
// appBar: AppBar(title: Text("测试全屏页面")),
floatingActionButton: FloatingActionButton(onPressed: widget.onTest1),
body: Container(
alignment: Alignment.center,
color: Colors.red,
child: Chewie(controller: widget.myChangeNotifier.chewieController!),
),
);
}
}
class MyChewieControllerNotifier extends ChangeNotifier {
ChewieController? chewieController;
int currPlayIndex = 0;
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"
];
updateChewieController({
required void Function() onTap,
required MyChewieControllerNotifier myChangeNotifier,
}) {
currPlayIndex += 1;
if (currPlayIndex >= srcs.length) {
currPlayIndex = 0;
}
String link = srcs[currPlayIndex];
print("切换了链接 $link");
chewieController?.videoPlayerController.dispose();
chewieController?.dispose();
chewieController = ChewieController(
videoPlayerController: VideoPlayerController.networkUrl(
Uri.parse(srcs[currPlayIndex]),
),
autoPlay: true,
autoInitialize: true,
aspectRatio: 16 / 9,
routePageBuilder:
(context, animation, secondaryAnimation, controllerProvider) =>
AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget? child) {
return TestFullScreen(
onTest1: onTap,
myChangeNotifier: myChangeNotifier,
);
},
),
);
notifyListeners();
}
}
Based on your answer @azhezzzz , an alternative with ChangeNotifier.
List<String> srcs = [
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
"https://samplelib.com/lib/preview/mp4/sample-10s.mp4",
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
];
class NotFullScreen extends StatefulWidget {
const NotFullScreen({super.key});
@override
State<NotFullScreen> createState() => _NotFullScreenState();
}
class _NotFullScreenState extends State<NotFullScreen> {
final VideoNotifier _videoNotifier = VideoNotifier();
int indexVideoPlayed = 0;
bool videoIsPlaying = false;
@override
void initState() {
super.initState();
loadVideo(indexVideoPlayed);
}
void loadVideo(indexVideoPlayed) async {
final String videoUrl = srcs[indexVideoPlayed];
final videoPlayerController = VideoPlayerController.networkUrl(Uri.parse(videoUrl));
await videoPlayerController.initialize();
setState(() {});
_videoNotifier.initChewieController(videoPlayerController);
videoPlayerController.addListener(() {
if (videoPlayerController.value.isCompleted && videoIsPlaying) {
// videoIsPlaying prevent listener to call multiple time at end.
videoIsPlaying = false;
indexVideoPlayed++;
loadVideo(indexVideoPlayed);
}
videoIsPlaying = true;
});
}
@override
void dispose() {
_videoNotifier.chewieController?.dispose();
_videoNotifier.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _videoNotifier.chewieController != null
? SizedBox(
height: 400,
child: ChewieVideo(
notifier: _videoNotifier,
),
)
: const Center(
child: CircularProgressIndicator(),
),
);
}
}
class ChewieVideo extends StatelessWidget {
final VideoNotifier _videoNotifier;
const ChewieVideo({super.key, notifier}) : _videoNotifier = notifier;
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _videoNotifier,
builder: (context, child) => Chewie(
controller: _videoNotifier.chewieController!,
),
);
}
}
class VideoNotifier extends ChangeNotifier {
ChewieController? _chewieController;
ChewieController? get chewieController => _chewieController;
void initChewieController(videoPlayerController) {
_chewieController = ChewieController(
autoPlay: true,
videoPlayerController: videoPlayerController,
routePageBuilder: (context, animation, secondaryAnimation, controllerProvider) {
return ChewieVideo(notifier: this);
},
);
notifyListeners();
}
}
Result
Abnormal black screen is stuck
Error info