coronalabs / corona

Solar2D Game Engine main repository (ex Corona SDK)
https://solar2d.com/
MIT License
2.54k stars 273 forks source link

Android: fix audio metatable being covered #698

Closed clang-clang-clang closed 3 months ago

clang-clang-clang commented 7 months ago

The metatable for Android audio2 overwrites the metatable for audio, causing the following properties (obtained by __index) to get incorrectly:

audio.freeChannels
audio.unreservedFreeChannels
audio.usedChannels
audio.unreservedUsedChannels
audio.totalChannels
audio.reservedChannels
audio.supportsSessionProperty

And an error prints:

Unsupported key: supportsSessionProperty in audio library

when obtaining the supportsSessionProperty instead of return false:

if supportsSessionProperty == true then
    audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)
end

AFAIK, there should be no side effects other than affecting the acquisition of the above properties. However, it is still necessary to be cautious about merging, because it is possible to break previous usage, although the previous value is always wrong.


Tested with Media/AudioPlayer and the following new lines:

timer.performWithDelay( 1000, function()
    print( "---------------------------------------------------------------------------------------" )
    print( "freeChannels:", audio.freeChannels, audio2.freeChannels )
    print( "totalChannels:", audio.totalChannels, audio2.totalChannels )
    print( "unreservedFreeChannels:", audio.unreservedFreeChannels, audio2.unreservedFreeChannels )
    print( "unreservedUsedChannels:", audio.unreservedUsedChannels, audio2.unreservedUsedChannels )
    print( "usedChannels:", audio.usedChannels, audio2.usedChannels )
    print( "reservedChannels:", audio.reservedChannels, audio2.reservedChannels )
end, 0)

Related to:

  1. audio.reserveChannels and audio.reservedChannels don't agree