mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-27 20:28:54 +01:00
audio/internal/oboe: Bug fix: Not all players should not be suspended
This commit is contained in:
parent
7487222740
commit
ae9e89b814
22
audio/internal/oboe/binding_android.cpp
vendored
22
audio/internal/oboe/binding_android.cpp
vendored
@ -26,24 +26,29 @@ namespace {
|
|||||||
class Player : public oboe::AudioStreamDataCallback {
|
class Player : public oboe::AudioStreamDataCallback {
|
||||||
public:
|
public:
|
||||||
static const char* Suspend() {
|
static const char* Suspend() {
|
||||||
std::lock_guard<std::mutex> lock(GetPlayersMutex());
|
std::lock_guard<std::mutex> lock(PlayersMutex());
|
||||||
for (Player* player : GetPlayers()) {
|
for (Player* player : GetPlayers()) {
|
||||||
|
if (!player->IsPlaying()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Close should be called rather than Pause for onPause.
|
// Close should be called rather than Pause for onPause.
|
||||||
// https://github.com/google/oboe/blob/master/docs/GettingStarted.md
|
// https://github.com/google/oboe/blob/master/docs/GettingStarted.md
|
||||||
if (const char* msg = player->Close(); msg) {
|
if (const char* msg = player->Close(); msg) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
GetPlayersToResume().insert(player);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* Resume() {
|
static const char* Resume() {
|
||||||
std::lock_guard<std::mutex> lock(GetPlayersMutex());
|
std::lock_guard<std::mutex> lock(PlayersMutex());
|
||||||
for (Player* player : GetPlayers()) {
|
for (Player* player : GetPlayersToResume()) {
|
||||||
if (const char* msg = player->Play(); msg) {
|
if (const char* msg = player->Play(); msg) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GetPlayersToResume().clear();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +59,7 @@ public:
|
|||||||
go_player_{go_player} {
|
go_player_{go_player} {
|
||||||
std::atomic_store(&volume_, volume);
|
std::atomic_store(&volume_, volume);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(GetPlayersMutex());
|
std::lock_guard<std::mutex> lock(PlayersMutex());
|
||||||
GetPlayers().insert(this);
|
GetPlayers().insert(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +138,7 @@ public:
|
|||||||
const char* CloseAndRemove() {
|
const char* CloseAndRemove() {
|
||||||
// Close and remove self from the players atomically.
|
// Close and remove self from the players atomically.
|
||||||
// Otherwise, a removed player might be resumed at Resume unexpectedly.
|
// Otherwise, a removed player might be resumed at Resume unexpectedly.
|
||||||
std::lock_guard<std::mutex> lock(GetPlayersMutex());
|
std::lock_guard<std::mutex> lock(PlayersMutex());
|
||||||
const char* msg = Close();
|
const char* msg = Close();
|
||||||
GetPlayers().erase(this);
|
GetPlayers().erase(this);
|
||||||
return msg;
|
return msg;
|
||||||
@ -176,7 +181,12 @@ private:
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::mutex& GetPlayersMutex() {
|
static std::set<Player*>& GetPlayersToResume() {
|
||||||
|
static std::set<Player*> players_to_resume;
|
||||||
|
return players_to_resume;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::mutex& PlayersMutex() {
|
||||||
static std::mutex mutex;
|
static std::mutex mutex;
|
||||||
return mutex;
|
return mutex;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user