You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tested version 3 on iOS and I saw that when trying to hot reload my app, the app gets into ANR and I need to fully reset it, something that didn't happen in v2. for now going back to v2 until fixed :)
using Flutter 3.24.4
video source : file / network
code to replicate:
class VideoListItem extends StatefulWidget {
const VideoListItem({
required this.videoSource,
super.key,
});
final VideoSource videoSource;
@override
State<VideoListItem> createState() => _VideoListItemViewState();
}
class _VideoListItemViewState extends State<VideoListItem> {
NativeVideoPlayerController? _controller;
StreamSubscription<void>? _eventsSubscription;
bool _isPlaying = true;
@override
void dispose() {
_eventsSubscription?.cancel();
_controller?.dispose();
_controller = null;
super.dispose();
}
@override
void didUpdateWidget(VideoListItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.videoSource != widget.videoSource && context.mounted) {
unawaited(_controller?.loadVideo(widget.videoSource));
}
}
void _onPlaybackStatusChanged() {
setState(() {});
}
void _onPlaybackPositionChanged() {
// setState(() {});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
print('tap tap atp');
togglePlayback();
},
child: AbsorbPointer(
child: AspectRatio(
aspectRatio: 16 / 9,
child: VisibilityDetector(
key: Key(widget.videoSource.path),
onVisibilityChanged: (info) async {
if (!context.mounted) return;
if (info.visibleFraction < 0.15) {
await _controller?.pause();
} else {
await _controller?.play();
}
},
child: NativeVideoPlayerView(
onViewReady: (controller) async {
_controller = controller;
await _controller?.setVolume(1);
await _controller?.loadVideo(widget.videoSource);
_eventsSubscription = _controller?.events.listen((event) {
switch (event) {
case PlaybackStatusChangedEvent():
_onPlaybackStatusChanged();
case PlaybackPositionChangedEvent():
_onPlaybackPositionChanged();
case PlaybackEndedEvent():
_onPlaybackEnded();
case PlaybackSpeedChangedEvent():
// TODO: Handle this case.
case VolumeChangedEvent():
// TODO: Handle this case.
case PlaybackReadyEvent():
// TODO: Handle this case.
case PlaybackErrorEvent():
// TODO: Handle this case.
}
});
},
),
),
),
),
);
}
Future<void> togglePlayback() async {
final controller = _controller;
if (controller == null) return;
if (_isPlaying) {
await controller.pause();
} else {
await controller.play();
}
final isPlaying = await controller.isPlaying();
setState(() {
_isPlaying = isPlaying;
});
}
void _onPlaybackEnded() {
final controller = _controller;
if (controller == null) return;
unawaited(controller.stop());
unawaited(controller.play());
}
}
The text was updated successfully, but these errors were encountered:
@VerioN1 you don't need a VisibilityDetector, NativeVideoPlayerViews are automatically stopped and disposed when going off screen. That might be why you get ANR issues. I've tested your code without the visibility detector and hot-reloading the app works fine for me. Let me know if you still have issues, thanks.
I tested version 3 on iOS and I saw that when trying to hot reload my app, the app gets into ANR and I need to fully reset it, something that didn't happen in v2. for now going back to v2 until fixed :)
using Flutter 3.24.4
video source : file / network
code to replicate:
The text was updated successfully, but these errors were encountered: