Ejemplo n.º 1
0
        /// <summary>
        /// Play the sound effect with the given path and optionally set it to lopo.
        /// </summary>
        /// <param name="pszFilePath">The path to the sound effect file.</param>
        /// <param name="bLoop">True if the sound effect will play continuously, and false if it will play then stop.</param>
        /// <returns></returns>
        public int PlayEffect(string pszFilePath, bool bLoop)
        {
            int nId = pszFilePath.GetHashCode();

            PreloadEffect(pszFilePath);

            lock (SharedList)
            {
                try
                {
                    if (SharedList.ContainsKey(nId))
                    {
                        SharedList[nId].Play(bLoop);
                        if (bLoop)
                        {
                            _LoopedSounds[nId] = nId;
                        }
                    }
                }
                catch (Exception ex)
                {
                    CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", pszFilePath);
                    CCLog.Log(ex.ToString());
                }
            }

            return(nId);
        }
Ejemplo n.º 2
0
        public int PlayEffect(string filename, bool loop = false)
        {
            int nId = filename.GetHashCode();

            PreloadEffect(filename);

            lock (SharedList)
            {
                try
                {
                    if (SharedList.ContainsKey(nId))
                    {
                        SharedList[nId].Play(loop);
                        if (loop)
                        {
                            loopedSounds[nId] = nId;
                        }
                    }
                }
                catch (Exception ex)
                {
                    CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", filename);
                    CCLog.Log(ex.ToString());
                }
            }

            return(nId);
        }
Ejemplo n.º 3
0
        /**
         * @brief       preload a compressed audio file
         * @details	    the compressed audio will be decode to wave, then write into an
         * internal buffer in SimpleaudioEngine
         */


        /// <summary>
        /// Load the sound effect found with the given path. The sound effect is only loaded one time and the
        /// effect is cached as an instance of EffectPlayer.
        /// </summary>
        public void PreloadEffect(string pszFilePath)
        {
            if (_NoAudioHardware)
            {
                return;
            }
            if (string.IsNullOrEmpty(pszFilePath))
            {
                return;
            }

            int nId = pszFilePath.GetHashCode();

            lock (SharedList)
            {
                if (SharedList.ContainsKey(nId))
                {
                    return;
                }
            }
            try
            {
                CCEffectPlayer eff = new CCEffectPlayer();
                eff.Open(FullPath(pszFilePath), nId);
                SharedList[nId] = eff;
            }
            catch (NoAudioHardwareException ex)
            {
                _NoAudioHardware = true;
                CCLog.Log(ex.ToString());
            }
        }
Ejemplo n.º 4
0
        public int PlayEffect(int fxid, bool bLoop)
        {
            if (_NoAudioHardware)
            {
                return(-1);
            }
            lock (SharedList)
            {
                try
                {
                    if (SharedList.ContainsKey(fxid))
                    {
                        SharedList[fxid].Play(bLoop);
                        if (bLoop)
                        {
                            _LoopedSounds[fxid] = fxid;
                        }
                    }
                }
                catch (Exception ex)
                {
                    CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", fxid);
                    CCLog.Log(ex.ToString());
                }
            }

            return(fxid);
        }
Ejemplo n.º 5
0
 public void PauseEffect(int fxid)
 {
     if (_NoAudioHardware)
     {
         return;
     }
     try
     {
         if (SharedList.ContainsKey(fxid))
         {
             SharedList[fxid].Pause();
         }
     }
     catch (NoAudioHardwareException ex)
     {
         CCLog.Log("NoAudioHardware! while playing a SoundEffect: {0}", fxid);
         CCLog.Log(ex.ToString());
         _NoAudioHardware = true;
     }
     catch (Exception ex)
     {
         CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", fxid);
         CCLog.Log(ex.ToString());
     }
 }
Ejemplo n.º 6
0
 public void PauseEffect(int fxid)
 {
     try
     {
         if (SharedList.ContainsKey(fxid))
         {
             SharedList[fxid].Pause();
         }
     }
     catch (Exception ex)
     {
         CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", fxid);
         CCLog.Log(ex.ToString());
     }
 }
Ejemplo n.º 7
0
 public void StopEffect(int soundId)
 {
     lock (SharedList)
     {
         if (SharedList.ContainsKey(soundId))
         {
             SharedList[soundId].Stop();
         }
     }
     lock (loopedSounds)
     {
         if (loopedSounds.ContainsKey(soundId))
         {
             loopedSounds.Remove(soundId);
         }
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Stops the sound effect with the given id.
 /// </summary>
 /// <param name="nSoundId"></param>
 public void StopEffect(int nSoundId)
 {
     lock (SharedList)
     {
         if (SharedList.ContainsKey(nSoundId))
         {
             SharedList[nSoundId].Stop();
         }
     }
     lock (_LoopedSounds)
     {
         if (_LoopedSounds.ContainsKey(nSoundId))
         {
             _LoopedSounds.Remove(nSoundId);
         }
     }
 }
Ejemplo n.º 9
0
        /**
         * @brief       unload the preloaded effect from internal buffer
         * @param[in]		pszFilePath		The path of the effect file,or the FileName of T_SoundResInfo
         */

        public void UnloadEffect(string pszFilePath)
        {
            int nId = pszFilePath.GetHashCode();

            lock (SharedList) {
                if (SharedList.ContainsKey(nId))
                {
                    SharedList.Remove(nId);
                }
            }
            lock (_LoopedSounds)
            {
                if (_LoopedSounds.ContainsKey(nId))
                {
                    _LoopedSounds.Remove(nId);
                }
            }
        }
Ejemplo n.º 10
0
        public void UnloadEffect(string filename)
        {
            int nId = filename.GetHashCode();

            lock (SharedList)
            {
                if (SharedList.ContainsKey(nId))
                {
                    SharedList.Remove(nId);
                }
            }
            lock (loopedSounds)
            {
                if (loopedSounds.ContainsKey(nId))
                {
                    loopedSounds.Remove(nId);
                }
            }
        }
Ejemplo n.º 11
0
        /**
         * @brief       preload a compressed audio file
         * @details	    the compressed audio will be decode to wave, then write into an
         * internal buffer in SimpleaudioEngine
         */


        /// <summary>
        /// Load the sound effect found with the given path. The sound effect is only loaded one time and the
        /// effect is cached as an instance of EffectPlayer.
        /// </summary>
        public void PreloadEffect(string pszFilePath)
        {
            if (string.IsNullOrEmpty(pszFilePath))
            {
                return;
            }

            int nId = pszFilePath.GetHashCode();

            lock (SharedList)
            {
                if (SharedList.ContainsKey(nId))
                {
                    return;
                }
            }
            EffectPlayer eff = new EffectPlayer();

            eff.Open(FullPath(pszFilePath), nId);
            SharedList[nId] = eff;
        }
Ejemplo n.º 12
0
        // Load the sound effect found with the given path. The sound effect is only loaded one time and the
        // effect is cached as an instance of EffectPlayer.
        public void PreloadEffect(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            int nId = filename.GetHashCode();

            lock (SharedList)
            {
                if (SharedList.ContainsKey(nId))
                {
                    return;
                }
            }
            CCEffectPlayer eff = new CCEffectPlayer();

            eff.Open(FullPath(filename), nId);
            eff.Volume      = effectsVolume;
            SharedList[nId] = eff;
        }