teotigraphix / as3wavsound

Automatically exported from code.google.com/p/as3wavsound
Other
2 stars 1 forks source link

Random problem while playing WAV sounds #22

Open pedrosimao opened 7 years ago

pedrosimao commented 7 years ago

I am using your code for a mobile app project in which I need to record sounds and than playing them. As converting to mp3 is too CPU demanding for most devices your project just saved me. But I am experiencing some random errors. In one of my screen it works flawlessly, but in the other one I get an error when I play the wav file for the first time. Strangely when I call the method again, from the second time on it works without problems. Here is the error msg I get:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at org.as3wavsound::WavSound/load()[/Users/.../src/org/as3wavsound/WavSound.as:115] at org.as3wavsound::WavSound()[/Users/.../src/org/as3wavsound/WavSound.as:102]

I went checking the WavSound class and I found those line might be the root of the problem:

        public function WavSound(wavData:ByteArray, audioSettings:AudioSetting = null) {
            load(wavData, audioSettings);
        }
    internal function load(wavData:ByteArray, audioSettings:AudioSetting = null): void {
            this._bytesTotal = wavData.length;
            this._playbackSettings = (audioSettings != null) ? audioSettings : new AudioSetting();
            this._samples = new Wav().decode(wavData, audioSettings);
            this._length = samples.length / samples.setting.sampleRate * 1000;
        }

I imagine the source of the problem is the audioSettings values. Do you have any idea of how to solve this? I have tried a lot of things, and nothing works. Also, it is so strange that in one screen I don't have the problem but in another one I do, since I am using the code the exact same way in the exact same order...

pedrosimao commented 7 years ago

Just found a solution... loading the sound during initialize() function somehow did the trick.