Beispiel #1
0
 public void Dispose()
 {
     labels.Clear();
     sounds.Clear();
     for (var i = 0; i < 2; i++)
     {
         customImages[i] = null;
     }
     if (backgroundSound != null)
     {
         backgroundSound.Dispose();
         backgroundSound = null;
     }
     if (backgroundMusic != null)
     {
         backgroundMusic.Dispose();
         backgroundMusic = null;
     }
     if (videosnapVideo != null)
     {
         videosnapVideo.Dispose();
         videosnapVideo = null;
     }
     backgroundImage  = null;
     screenSaverImage = null;
     images.Clear();
 }
Beispiel #2
0
        public void SetBackgroundMusic(string musicPath, int volume)
        {
            if (backgroundMusicPath == musicPath)
            {
                if (backgroundMusicVolume != volume)
                {
                    backgroundMusicVolume = volume;
                    if (backgroundMusic != null)
                    {
                        backgroundMusic.Volume = backgroundMusicVolume;
                    }
                    else if (backgroundSound != null)
                    {
                        backgroundSound.Volume = backgroundMusicVolume;
                    }
                }
                return;
            }

            _multipleFilesMusic = false;
            backgroundMusicPlayList.Clear();
            if (backgroundSound != null)
            {
                backgroundSound.Dispose();
                backgroundSound = null;
            }
            if (backgroundMusic != null)
            {
                backgroundMusic.Dispose();
                backgroundMusic = null;
            }
            topmostForm.IsPlayEnded = true;
            currentBackgroundMusic  = -1;
            backgroundMusicVolume   = volume;
            backgroundMusicPath     = musicPath;

            // it's a directory..
            if (Directory.Exists(backgroundMusicPath))
            {
                var sourceList = new List <string>();
                sourceList.AddRange(Directory.GetFiles(backgroundMusicPath, "*.wav"));
                sourceList.AddRange(Directory.GetFiles(backgroundMusicPath, "*.mp3"));

                // shuffle list
                var rnd        = new Random();
                var itemsCount = sourceList.Count;

                _multipleFilesMusic = itemsCount > 1;
                while (itemsCount > 0)
                {
                    var index = rnd.Next(0, itemsCount);
                    backgroundMusicPlayList.Add(sourceList[index]);
                    sourceList.RemoveAt(index);
                    itemsCount--;
                }

                backgroundMusic = new CMusic();
                return;
            }

            var fileName = backgroundMusicPath;

            if (!File.Exists(fileName))
            {
                fileName = Application.StartupPath + Path.DirectorySeparatorChar + "media" + Path.DirectorySeparatorChar + backgroundMusicPath;
            }

            // it's a file
            if (File.Exists(fileName))
            {
                var ext = Path.GetExtension(fileName).Trim().ToLower();
                if (ext == ".wav")
                {
                    backgroundSound = new CSound(fileName, volume, topmostForm);
                }
                else
                {
                    backgroundMusicPlayList.Add(fileName);
                    backgroundMusic = new CMusic();
                }
            }
        }