Skip to content

Commit b6b3ca7

Browse files
authored
fix(MDK): Exception when switching videos (#855)
1 parent 8aea793 commit b6b3ca7

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

lib/wrappers/players/lib_mdk.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ class LibMDK extends BasePlayer {
6262

6363
@override
6464
Future<void> dispose() async {
65-
_controller?.dispose();
65+
final oldController = _controller;
6666
_controller = null;
67+
oldController?.dispose();
6768
}
6869

6970
@override
7071
Future<void> loadVideo(String url, bool play) async {
71-
if (_controller != null) {
72-
_controller?.dispose();
73-
}
72+
_controller?.dispose();
73+
7474
final validUrl = isValidUrl(url);
7575
if (validUrl != null) {
7676
_controller = VideoPlayerController.networkUrl(validUrl);
@@ -203,7 +203,7 @@ class LibMDK extends BasePlayer {
203203
}
204204

205205
@override
206-
Future<void> stop() async => _controller?.dispose();
206+
Future<void> stop() async => dispose();
207207

208208
@override
209209
Widget? videoWidget(
@@ -223,14 +223,16 @@ class LibMDK extends BasePlayer {
223223
fit: fit,
224224
alignment: Alignment.center,
225225
child: ValueListenableBuilder<VideoPlayerValue>(
226-
valueListenable: _controller!,
226+
valueListenable: _controller ?? ValueNotifier(const VideoPlayerValue.uninitialized()),
227227
builder: (context, value, child) {
228228
final aspectRatio = value.isInitialized ? value.aspectRatio : 1.77;
229+
final controller = _controller;
230+
if (controller == null) return const SizedBox.shrink();
229231
return SizedBox(
230232
width: constraints.maxWidth,
231233
child: AspectRatio(
232234
aspectRatio: aspectRatio,
233-
child: VideoPlayer(_controller!),
235+
child: VideoPlayer(controller),
234236
),
235237
);
236238
},

0 commit comments

Comments
 (0)