mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Pass all stopped sources on love.audiodisconnected callback.
The behavior of sources re-played during these times is inconsistent. Streaming sources will desync while static sources stop completely.
This commit is contained in:
@@ -30,6 +30,16 @@ namespace audio
|
|||||||
namespace openal
|
namespace openal
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static Variant::SharedTable *putSourcesAsSharedTable(std::vector<audio::Source *> &sources)
|
||||||
|
{
|
||||||
|
Variant::SharedTable *table = new Variant::SharedTable();
|
||||||
|
|
||||||
|
for (int i = 0; i < sources.size(); i++)
|
||||||
|
table->pairs.emplace_back((double) (i + 1), Variant(&Source::type, sources[i]));
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
Pool::Pool(ALCdevice *device)
|
Pool::Pool(ALCdevice *device)
|
||||||
: device(device)
|
: device(device)
|
||||||
, sources()
|
, sources()
|
||||||
@@ -125,8 +135,17 @@ void Pool::update()
|
|||||||
disconnectNotified = false;
|
disconnectNotified = false;
|
||||||
else if (!disconnectNotified)
|
else if (!disconnectNotified)
|
||||||
{
|
{
|
||||||
StrongRef<event::Message> msg(new event::Message("audiodisconnected"), Acquire::NORETAIN);
|
// Get all sources in this Pool then stop it
|
||||||
|
// since they're all internally stopped.
|
||||||
|
std::vector<audio::Source *> sources = getPlayingSources();
|
||||||
|
Source::stop(sources);
|
||||||
|
|
||||||
|
std::vector<Variant> vargs;
|
||||||
|
vargs.emplace_back(putSourcesAsSharedTable(sources));
|
||||||
|
|
||||||
|
StrongRef<event::Message> msg(new event::Message("audiodisconnected", vargs), Acquire::NORETAIN);
|
||||||
eventModule->push(msg);
|
eventModule->push(msg);
|
||||||
|
|
||||||
disconnectNotified = true;
|
disconnectNotified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,8 +129,8 @@ function love.createhandlers()
|
|||||||
localechanged = function ()
|
localechanged = function ()
|
||||||
if love.localechanged then return love.localechanged() end
|
if love.localechanged then return love.localechanged() end
|
||||||
end,
|
end,
|
||||||
audiodisconnected = function ()
|
audiodisconnected = function (sources)
|
||||||
if not love.audiodisconnected or not love.audiodisconnected() then
|
if not love.audiodisconnected or not love.audiodisconnected(sources) then
|
||||||
love.audio.setOutputDevice()
|
love.audio.setOutputDevice()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user