diff --git a/media_kit_test/lib/tests/09.seamless.dart b/media_kit_test/lib/tests/09.seamless.dart index 06479aa91..29cf164df 100644 --- a/media_kit_test/lib/tests/09.seamless.dart +++ b/media_kit_test/lib/tests/09.seamless.dart @@ -84,6 +84,24 @@ class _SeamlessState extends State { onPageChanged: (i) { // Play the current page's video. players[i]?.play(); + + // Dispose the [Player]s & [VideoController]s of the pages that are not visible & not adjacent to the current page. + players.removeWhere( + (page, player) { + final remove = ![i, i - 1, i + 1].contains(page); + if (remove) { + player.dispose(); + } + return remove; + }, + ); + controllers.removeWhere( + (page, controller) { + final remove = ![i, i - 1, i + 1].contains(page); + return remove; + }, + ); + // Pause other pages' videos. for (final e in players.entries) { if (e.key != i) { @@ -104,23 +122,6 @@ class _SeamlessState extends State { createPlayer(i - 1); } - // Dispose the [Player]s & [VideoController]s of the pages that are not visible & not adjacent to the current page. - players.removeWhere( - (page, player) { - final remove = ![i, i - 1, i + 1].contains(page); - if (remove) { - player.dispose(); - } - return remove; - }, - ); - controllers.removeWhere( - (page, controller) { - final remove = ![i, i - 1, i + 1].contains(page); - return remove; - }, - ); - debugPrint('players: ${players.keys}'); debugPrint('controllers: ${controllers.keys}'); },