Esempio n. 1
0
        void PlayCurrentSound(IAudioOutput[] outputs, float volume)
        {
            for (int i = 0; i < monoOutputs.Length; i++)
            {
                IAudioOutput output = outputs[i];
                if (output == null)
                {
                    output = MakeSoundOutput(outputs, i);
                }
                if (!output.DoneRawAsync())
                {
                    continue;
                }

                LastChunk l = output.Last;
                if (l.Channels == 0 || (l.Channels == chunk.Channels && l.BitsPerSample == chunk.BitsPerSample &&
                                        l.SampleRate == chunk.SampleRate))
                {
                    PlaySound(output, volume); return;
                }
            }

            // This time we try to play the sound on all possible devices,
            // even if it requires the expensive case of recreating a device
            for (int i = 0; i < monoOutputs.Length; i++)
            {
                IAudioOutput output = outputs[i];
                if (!output.DoneRawAsync())
                {
                    continue;
                }

                PlaySound(output, volume); return;
            }
        }
        void PlayCurrentSound(IAudioOutput[] outputs)
        {
            for (int i = 0; i < monoOutputs.Length; i++)
            {
                IAudioOutput output = outputs[i];
                if (output == null)
                {
                    output = GetPlatformOut();
                    output.Create(1, firstSoundOut);
                    if (firstSoundOut == null)
                    {
                        firstSoundOut = output;
                    }
                    outputs[i] = output;
                }
                if (!output.DoneRawAsync())
                {
                    continue;
                }

                try {
                    output.PlayRawAsync(chunk);
                } catch (InvalidOperationException ex) {
                    HandleSoundError(ex);
                }
                return;
            }
        }
        void PlayCurrentSound(IAudioOutput[] outputs)
        {
            for (int i = 0; i < monoOutputs.Length; i++)
            {
                IAudioOutput output = outputs[i];
                if (output == null)
                {
                    output = GetPlatformOut();
                    output.Create(1, firstSoundOut);
                    if (firstSoundOut == null)
                    {
                        firstSoundOut = output;
                    }
                    outputs[i] = output;
                }

                if (output.DoneRawAsync())
                {
                    output.PlayRawAsync(chunk);
                    return;
                }
            }
        }