Exemple #1
0
        /// <summary>
        /// You cannot call <see cref="Play"> anymore after unloading. It will throw an exception if you do so.
        ///
        /// [iOS] Unload OpenAL buffer. The total number of 16 OpenAL source does not change. Immediately stop the sound if it is playing.
        ///
        /// [Android] `free` the unmanaged audio data array at C code part of OpenSL ES code.
        ///
        /// It is HIGHLY recommended to stop those audio player via <see cref="NativeAudioController.Stop"> before unloading because the play head will continue
        /// running into oblivion if you unload data while it is still reading. I have seen 2 cases :
        ///
        /// - The game immediately crash with signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) on my 36$ low end phone. Probably it does not permit freed memory reading.
        /// - In some device it produce scary noisehead sound if you load something new, `malloc` decided to use the same memory area you just freed,
        /// and the still running playhead pick that up.
        /// </summary>
        public void Unload()
        {
            if (!isUnloaded)
            {
#if UNITY_IOS
                NativeAudio._UnloadAudio(startingIndex);
                isUnloaded = true;
#elif UNITY_ANDROID
                for (int i = startingIndex; i < startingIndex + amount; i++)
                {
                    NativeAudio.unloadAudio(i);
                }
#endif
                isUnloaded = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Do not call `Play` anymore after unloading.

        /// [iOS] Unload OpenAL buffer. The total number of 32 OpenAL source does not change.
        /// [Android] Unload the `byte[]` array by dereferencing it. We have to wait for the actual unload is by Java's garbage collector. The total number of `AudioTrack` does not change.

        /// </summary>
        public void Unload()
        {
#if UNITY_IOS
            if (!isUnloaded)
            {
                NativeAudio._UnloadAudio(startingIndex);
                isUnloaded = true;
            }
#elif UNITY_ANDROID
            if (!isUnloaded)
            {
                for (int i = startingIndex; i < startingIndex + amount; i++)
                {
                    NativeAudio.AndroidNativeAudio.CallStatic(NativeAudio.AndroidUnloadAudio, i);
                }
                isUnloaded = true;
            }
#endif
        }