Skip to content

Commit

Permalink
fix(test/seamless): fix players lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
birros committed Sep 9, 2023
1 parent 7d34252 commit 34aa1ec
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions media_kit_test/lib/tests/09.seamless.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ class _SeamlessState extends State<Seamless> {
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) {
Expand All @@ -104,23 +122,6 @@ class _SeamlessState extends State<Seamless> {
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}');
},
Expand Down

0 comments on commit 34aa1ec

Please sign in to comment.