예제 #1
0
        /// <summary>
        /// Pause the <see cref="SoundSource"/> object.
        /// </summary>
        /// <param name="source">The <see cref="SoundSource"/> to pause.</param>
        public virtual void Pause(SoundSource source)
        {
            // Audio Device no longer active?
            if (AudioDevice.IsDisposed)
            {
                throw new ObjectDisposedException("AudioDevice");
            }

            // Nothing to pause
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Ignore if sources is not listed or handle is not yet created
            if (!_sources.Contains(source) || source.Handle <= 0)
            {
                return;
            }

            // Check whether the specified source has valid handle
            bool valid = false;

            ALChecker.Check(() => valid = AL.IsSource(source.Handle));

            // ignore if its not valid
            if (!valid)
            {
                return;
            }

            // Pause the sound
            try
            {
                _pause.Invoke(source, null);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
예제 #2
0
        /// <summary>
        /// Stop playing the <see cref="SoundSource"/> object.
        /// </summary>
        /// <param name="source">The <see cref="SoundSource"/> to stop.</param>
        public virtual void Stop(SoundSource source)
        {
            // Nothing to pause
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Ignore if sources is not listed or handle is not yet created
            if (!_sources.Contains(source) || source.Handle <= 0)
            {
                return;
            }

            // Check whether the specified source has valid handle
            bool valid = false;

            ALChecker.Check(() => valid = AL.IsSource(source.Handle));

            // ignore if its not valid
            if (!valid)
            {
                return;
            }

            // Stop the sound
            try
            {
                _stop.Invoke(source, null);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }

            // Force to remove the source
            Update();
        }
예제 #3
0
 /// <summary>
 /// Determines whether the specified <see cref="SoundSource"/> is in current <see cref="SoundGroup"/> object.
 /// </summary>
 /// <param name="source">The <see cref="SoundSource"/> to check.</param>
 /// <returns><code>true</code> if the <see cref="SoundSource"/> exist, otherwise false.</returns>
 public bool Contains(SoundSource source)
 {
     return _sources.Contains(source);
 }
예제 #4
0
 /// <summary>
 /// Determines whether the specified <see cref="SoundSource"/> is in current <see cref="SoundGroup"/> object.
 /// </summary>
 /// <param name="source">The <see cref="SoundSource"/> to check.</param>
 /// <returns><code>true</code> if the <see cref="SoundSource"/> exist, otherwise false.</returns>
 public bool Contains(SoundSource source)
 {
     return(_sources.Contains(source));
 }
예제 #5
0
        /// <summary>
        /// Stop playing the <see cref="SoundSource"/> object.
        /// </summary>
        /// <param name="source">The <see cref="SoundSource"/> to stop.</param>
        public virtual void Stop(SoundSource source)
        {
            // Nothing to pause
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Ignore if sources is not listed or handle is not yet created
            if (!_sources.Contains(source) || source.Handle <= 0)
            {
                return;
            }

            // Check whether the specified source has valid handle
            bool valid = false;
            ALChecker.Check(() => valid = AL.IsSource(source.Handle));

            // ignore if its not valid
            if (!valid)
                return;

            // Stop the sound
            try
            {
                _stop.Invoke(source, null);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }

            // Force to remove the source
            Update();
        }
예제 #6
0
        /// <summary>
        /// Pause the <see cref="SoundSource"/> object.
        /// </summary>
        /// <param name="source">The <see cref="SoundSource"/> to pause.</param>
        public virtual void Pause(SoundSource source)
        {
            // Audio Device no longer active?
            if (AudioDevice.IsDisposed)
            {
                throw new ObjectDisposedException("AudioDevice");
            }

            // Nothing to pause
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Ignore if sources is not listed or handle is not yet created
            if (!_sources.Contains(source) || source.Handle <= 0)
            {
                return;
            }

            // Check whether the specified source has valid handle
            bool valid = false;
            ALChecker.Check(() => valid = AL.IsSource(source.Handle));

            // ignore if its not valid
            if (!valid)
                return;

            // Pause the sound
            try
            {

                _pause.Invoke(source, null);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
예제 #7
0
        /// <summary>
        /// Start or resume playing the <see cref="SoundSource"/> object.
        /// </summary>
        /// <param name="source">The <see cref="SoundSource"/> to play or resume.</param>
        public virtual void Play(SoundSource source)
        {
            // Audio Device no longer active?
            if (AudioDevice.IsDisposed)
            {
                throw new ObjectDisposedException("AudioDevice");
            }

            // Nothing to play?
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Check whether the number of playing sounds is exceed the limit
            if (_sources.Count >= MAX_SOURCE_COUNT)
            {
                // Force to recycle unused source
                Update();

                // Check again if it exceed the limit
                if (_sources.Count >= MAX_SOURCE_COUNT)
                {
                    // It still exceed and throw the exception
                    throw new InvalidOperationException("Failed to play the source:\n" +
                        "The number of playing sources is exceed the limit.");
                }
            }

            // Create the source handle, in case it is first call
            bool valid = false;
            ALChecker.Check(() => valid = AL.IsSource(source.Handle));
            if (!valid)
            {
                int handle = 0;
                ALChecker.Check(() => handle = AL.GenSource());
                ALChecker.Check(() => AL.Source(handle, ALSourcei.Buffer, 0));

                source.Handle = handle;
            }

            // Play the sound
            try
            {
                _play.Invoke(source, null);

                // Add to the list
                _sources.Add(source);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }