OpenBve.SoundManager.HasFinishedPlaying C# (CSharp) Méthode

HasFinishedPlaying() static private méthode

static private HasFinishedPlaying ( int SoundSourceIndex ) : bool
SoundSourceIndex int
Résultat bool
		internal static bool HasFinishedPlaying(int SoundSourceIndex) {
			if (OpenAlContext != ContextHandle.Zero) {
				if (SoundSourceIndex >= 0 && SoundSources[SoundSourceIndex] != null) {
					return SoundSources[SoundSourceIndex].FinishedPlaying;
				} else {
					return true;
				}
			} else {
				return false;
			}
		}

Usage Example

        internal override void Elapse(ElapseData data)
        {
            try
            {
                double            time = data.TotalTime.Milliseconds;
                Win32VehicleState win32State;
                win32State.Location    = data.Vehicle.Location;
                win32State.Speed       = (float)data.Vehicle.Speed.KilometersPerHour;
                win32State.Time        = (int)Math.Floor(time - 2073600000.0 * Math.Floor(time / 2073600000.0));
                win32State.BcPressure  = (float)data.Vehicle.BcPressure;
                win32State.MrPressure  = (float)data.Vehicle.MrPressure;
                win32State.ErPressure  = (float)data.Vehicle.ErPressure;
                win32State.BpPressure  = (float)data.Vehicle.BpPressure;
                win32State.SapPressure = (float)data.Vehicle.SapPressure;
                win32State.Current     = 0.0f;
                Win32Handles win32Handles;
                win32Handles.Brake         = data.Handles.BrakeNotch;
                win32Handles.Power         = data.Handles.PowerNotch;
                win32Handles.Reverser      = data.Handles.Reverser;
                win32Handles.ConstantSpeed = data.Handles.ConstSpeed ? ConstSpeedInstructions.Enable : ConstSpeedInstructions.Disable;
                Win32Elapse(ref win32Handles.Brake, ref win32State.Location, ref base.Panel[0], ref this.Sound[0]);
                data.Handles.Reverser   = win32Handles.Reverser;
                data.Handles.PowerNotch = win32Handles.Power;
                data.Handles.BrakeNotch = win32Handles.Brake;
                if (win32Handles.ConstantSpeed == ConstSpeedInstructions.Enable)
                {
                    data.Handles.ConstSpeed = true;
                }
                else if (win32Handles.ConstantSpeed == ConstSpeedInstructions.Disable)
                {
                    data.Handles.ConstSpeed = false;
                }
                else if (win32Handles.ConstantSpeed != ConstSpeedInstructions.Continue)
                {
                    this.PluginValid = false;
                }

                /*
                 * Process the sound instructions
                 * */
                for (int i = 0; i < this.Sound.Length; i++)
                {
                    if (this.Sound[i] != this.LastSound[i])
                    {
                        if (this.Sound[i] == SoundInstructions.Stop)
                        {
                            if (i < base.Train.Cars[base.Train.DriverCar].Sounds.Plugin.Length)
                            {
                                SoundManager.StopSound(ref base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex);
                            }
                        }
                        else if (this.Sound[i] > SoundInstructions.Stop & this.Sound[i] <= SoundInstructions.PlayLooping)
                        {
                            if (i < base.Train.Cars[base.Train.DriverCar].Sounds.Plugin.Length)
                            {
                                int snd = base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundBufferIndex;
                                if (snd >= 0)
                                {
                                    double gain = (double)(this.Sound[i] - SoundInstructions.Stop) / (double)(SoundInstructions.PlayLooping - SoundInstructions.Stop);
                                    if (SoundManager.IsPlaying(base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex))
                                    {
                                        SoundManager.ModulateSound(base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex, 1.0, gain);
                                    }
                                    else
                                    {
                                        SoundManager.PlaySound(ref base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex, snd, base.Train, base.Train.DriverCar, base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].Position, SoundManager.Importance.AlwaysPlay, true, 1.0, gain);
                                    }
                                }
                            }
                        }
                        else if (this.Sound[i] == SoundInstructions.PlayOnce)
                        {
                            if (i < base.Train.Cars[base.Train.DriverCar].Sounds.Plugin.Length)
                            {
                                int snd = base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundBufferIndex;
                                if (snd >= 0)
                                {
                                    SoundManager.PlaySound(ref base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex, snd, base.Train, base.Train.DriverCar, base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].Position, SoundManager.Importance.AlwaysPlay, false);
                                }
                            }
                            this.Sound[i] = SoundInstructions.Continue;
                        }
                        else if (this.Sound[i] != SoundInstructions.Continue)
                        {
                            this.PluginValid = false;
                        }
                        this.LastSound[i] = this.Sound[i];
                    }
                    else
                    {
                        if (i < base.Train.Cars[base.Train.DriverCar].Sounds.Plugin.Length)
                        {
                            if (base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex >= 0)
                            {
                                if (SoundManager.HasFinishedPlaying(base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex))
                                {
                                    SoundManager.StopSound(ref base.Train.Cars[base.Train.DriverCar].Sounds.Plugin[i].SoundSourceIndex);
                                }
                            }
                        }
                        if ((this.Sound[i] < SoundInstructions.Stop | this.Sound[i] > SoundInstructions.PlayLooping) && this.Sound[i] != SoundInstructions.PlayOnce & this.Sound[i] != SoundInstructions.Continue)
                        {
                            this.PluginValid = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
        }