Exemple #1
0
        void DoMusicThread()
        {
            Random rnd = new Random();

            while (!disposingMusic)
            {
                string file = musicFiles[rnd.Next(0, musicFiles.Length)];
                string path = Path.Combine(Program.AppDirectory, file);
                Utils.LogDebug("playing music file: " + file);

                using (FileStream fs = File.OpenRead(path)) {
                    OggContainer container = new OggContainer(fs);
                    try {
                        musicOut.PlayStreaming(container);
                    } catch (InvalidOperationException ex) {
                        HandleMusicError(ex);
                        return;
                    }
                }
                if (disposingMusic)
                {
                    break;
                }

                int delay = 2000 * 60 + rnd.Next(0, 5000 * 60);
                musicHandle.WaitOne(delay);
            }
        }
Exemple #2
0
        void DoMusicThread()
        {
            if (musicFiles.Length == 0)
            {
                return;
            }
            Random rnd = new Random();

            while (!disposingMusic)
            {
                string file = musicFiles[rnd.Next(0, musicFiles.Length)];
                string path = Path.Combine(Program.AppDirectory, file);
                Utils.LogDebug("playing music file: " + file);

                using (FileStream fs = File.OpenRead(path)) {
                    OggContainer container = new OggContainer(fs);
                    try {
                        musicOut.PlayStreaming(container);
                    } catch (InvalidOperationException ex) {
                        HandleMusicError(ex);
                        return;
                    } catch (Exception ex) {
                        ErrorHandler.LogError("AudioPlayer.DoMusicThread()", ex);
                        game.Chat.Add("&cError while trying to play music file " + Path.GetFileName(file));
                    }
                }
                if (disposingMusic)
                {
                    break;
                }

                int delay = 2000 * 60 + rnd.Next(0, 5000 * 60);
                musicHandle.WaitOne(delay, false);
            }
        }
Exemple #3
0
        void DoMusicThread()
        {
            if (musicFiles.Length == 0)
            {
                return;
            }
            Random rnd = new Random();

            while (!disposingMusic)
            {
                string file = musicFiles[rnd.Next(0, musicFiles.Length)];
                Utils.LogDebug("playing music file: " + file);

                string path = Path.Combine("audio", file);
                using (Stream fs = Platform.FileOpen(path)) {
                    try {
                        musicOut.SetVolume(game.MusicVolume / 100.0f);
                        musicOut.PlayStreaming(fs);
                    } catch (InvalidOperationException ex) {
                        HandleMusicError(ex);
                        try { musicOut.Dispose(); } catch { }
                        return;
                    } catch (Exception ex) {
                        ErrorHandler.LogError("AudioPlayer.DoMusicThread()", ex);
                        game.Chat.Add("&cError while trying to play music file " + file);
                        try { musicOut.Dispose(); } catch { }
                        return;
                    }
                }
                if (disposingMusic)
                {
                    break;
                }

                int delay = 1000 * 120 + rnd.Next(0, 1000 * 300);
                musicHandle.WaitOne(delay, false);
            }
        }