/// <summary>
        /// Handle panel creation - initialize slimdx directsound players
        /// </summary>
        /// <param name="e"></param>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            DirectSoundWrapper.Initialize(this);

            #region Create controls

            string soundFolder = Application.StartupPath + "\\AudioPanel";

            if (!Directory.Exists(soundFolder))
            {
                logger.Warn("AudioPanel: the sound folder '" + soundFolder + "' does not exist. No sounds have been loaded");
            }
            else
            {
                foreach (string file in Directory.GetFiles(soundFolder))
                {
                    AudioChannel ch = new AudioChannel(file, Path.GetFileName(file), true);
                    audioChannels.Add(ch);
                }
            }
            #endregion

            foreach (AudioChannel ac in audioChannels)
            {
                Controls.Add(ac);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a media player with the given file
        /// </summary>
        /// <param name="fileName">the file to play</param>
        /// <returns>true if successful</returns>
        private bool _setupSoundPlayer(string filename)
        {
            bool retval = false;

            soundPlayer = null;

            if ((filename.Length != 0))
            {
                try
                {
                    fileName    = filename;
                    soundPlayer = DirectSoundWrapper.CreateSoundBufferFromWave(fileName);
                    SlimDX.Multimedia.WaveStream waveFile = new SlimDX.Multimedia.WaveStream(fileName);

                    List <NotificationPosition> pos = new List <NotificationPosition>();
                    notificationPosition.Offset = (int)waveFile.Length - 1;
                    notificationPosition.Event  = new AutoResetEvent(false);

                    pos.Add(notificationPosition);
                    soundPlayer.SetNotificationPositions(pos.ToArray());
                }
                catch (Exception ex)
                {
                    logger.Error("[SoundPlayer] Error creating soundplayer: " + ex.Message);
                }

                _updateVolume(volume);

                retval = true;
            }

            return(retval);
        }
 /// <summary>
 /// Handle panel destruction - clean up slimdx directsound
 /// </summary>
 /// <param name="e"></param>
 protected override void OnHandleDestroyed(EventArgs e)
 {
     base.OnHandleDestroyed(e);
     DirectSoundWrapper.Shutdown();
 }