[video_player] Dispose all players on hot reload (#97)

* Dispose all players on hot reload

* Update AUTHORS

---------

Co-authored-by: Anonymous <>
This commit is contained in:
barribarrier
2024-09-22 03:12:08 -04:00
committed by GitHub
parent 10a89e1421
commit 7696d211ee
2 changed files with 18 additions and 0 deletions

View File

@ -8,3 +8,4 @@ Sony Group Corporation
Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com)
Makoto Sato (makoto.sato@atmark-techno.com)
Arjun Patel (patel.arjun50@gmail.com)
Bari Rao (bari.rao@gmail.com)

View File

@ -276,6 +276,23 @@ void VideoPlayerPlugin::RegisterWithRegistrar(
void VideoPlayerPlugin::HandleInitializeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
// Dispose of all existing players. This helps to shut down existing players
// on a hot restart.
// https://github.com/flutter/flutter/issues/10437
for (auto itr = players_.begin(); itr != players_.end(); itr++) {
auto texture_id = itr->first;
auto* player = itr->second.get();
player->event_sink = nullptr;
if (player->event_channel) {
player->event_channel->SetStreamHandler(nullptr);
}
player->player = nullptr;
player->buffer = nullptr;
player->texture = nullptr;
texture_registrar_->UnregisterTexture(texture_id);
}
players_.clear();
flutter::EncodableMap result;
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),