// Utility methodes private void StopAndCloseStream() { if (_waveOutDevice != null) { _waveOutDevice.Stop(); } if (_activeStream != null) { try { _inputStream.Close(); _inputStream = null; } catch { _inputStream = null; } } if (_waveOutDevice != null) { _waveOutDevice.Dispose(); _waveOutDevice = null; } }
private void wavePlayer_PlaybackStopped(object sender, StoppedEventArgs e) { if (wavePlayer != null) { wavePlayer.Stop(); wavePlayer.Dispose(); wavePlayer = null; } }
public void Stop() { if (playbackDevice != null && playbackDevice.PlaybackState != PlaybackState.Stopped) { playbackDevice.Stop(); } }
public void PlaySound(SwavStream input) { m_OutputDevice.Stop(); input.Reset(); m_OutputDevice.Init(input.m_Resampled); m_OutputDevice.Play(); }
/// <summary> /// stops current playback (if any) /// </summary> public void StopPlayback() { if (wp.PlaybackState != PlaybackState.Stopped) { wp.Stop(); } }
/// <summary> /// Unloads the sound /// </summary> /// <returns></returns> public override bool Unload() { if (Filename == "") { return(true); } if (mWaveOut != null) { mWaveOut.Stop(); } if (mWaveStream != null) { mWaveStream.Close(); mWaveStream = null; } if (mWaveOut != null) { mWaveOut.Dispose(); mWaveOut = null; } return(true); }
/// <summary> /// Skips to the next song. /// </summary> public void Skip() { waveOutDevice.Stop(); while (waveOutDevice.PlaybackState != PlaybackState.Stopped) { } }
public static void StopAudio() { if (playbackDevice != null) { playbackDevice.Stop(); } }
private void labelMusic_Click(object sender, EventArgs e) { try { musicPlaying = !musicPlaying; if (musicPlaying) { try { var tracks = FindTracks(); var track = tracks[new Random().Next(tracks.Count)]; audioFileReader = new AudioFileReader(track); audioFileReader.Volume = 0.3f; waveOutDevice = new WaveOut(); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); waveOutDevice.PlaybackStopped += new EventHandler <StoppedEventArgs>(onMusicStopped); } catch (Exception ex) { musicPlaying = false; } } else { //waveOutDevice.PlaybackStopped = null; waveOutDevice.Stop(); } } catch (Exception ex) { } }
public void Stop() { if (audioPlayer != null) { audioPlayer.Stop(); } }
public static void PlayFile(String url) { if (url != "" && url != null) { url = @System.IO.Directory.GetCurrentDirectory() + url; if (NAudio.audioFileReader == null) { audioFileReader = new AudioFileReader(url); //waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(Loop); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } else if (url != NAudio.audioFileReader.FileName) { waveOutDevice.Stop(); NAudio.audioFileReader.Dispose(); audioFileReader = new AudioFileReader(url); //waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(Loop); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); } } else if (NAudio.audioFileReader != null) { waveOutDevice.Stop(); NAudio.audioFileReader = null; } }
public void Play(Model.Song song) { if (song == null) { return; } if (audioFileReader != null) { audioFileReader.Dispose(); audioFileReader = null; } var t = Mp3Frame.LoadFromStream(null); NAudio.Wave.AcmMp3FrameDecompressor dec = new AcmMp3FrameDecompressor(new Mp3WaveFormat(t.SampleRate, 2, t.FrameLength, t.BitRate)); audioFileReader = new AudioFileReader(song.mp3Url); if (waveOutDevice != null) { waveOutDevice.Stop(); waveOutDevice.Dispose(); waveOutDevice = null; } waveOutDevice = new WaveOut(); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); }
public void Stop() { if (_waveOut != null) { _waveOut.Stop(); } }
private void TickTimer(object sender, EventArgs e) { if (msecsRemaining > 0) { msecsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds; var pos = cdgLength - msecsRemaining; cdgFile.renderAtPosition(pos); var image = (System.Drawing.Bitmap)cdgFile.get_RGBImage(); if (!firstFrame) { ChangeAnnounceColor(image); } if (step1 && pos > 10000) { txtAnuncio.Visibility = System.Windows.Visibility.Hidden; step1 = false; step2 = true; } if (step2 && msecsRemaining < 15000) { txtAnuncio.Visibility = System.Windows.Visibility.Visible; txtAnuncio.Text = messageEnd; step2 = false; } karImage.Source = loadBitmap(image); } else { waveOutDevice.Stop(); KaraokeEnded(currentId); } }
private void btnPlay_Click(object sender, EventArgs e) { if (_Player != null && _Reader != null && _Reader.FileLoaded) { //In case launching a new player, reset the old one if (_CurrentVGMStreamPlayer != null && _CurrentVGMStreamPlayer != this) { StopCurrentVGMStreamPlayback(); } if (_Player.PlaybackState == PlaybackState.Playing) { _Player.Stop(); btnPlay.Image = Properties.Resources.icon_play; } else { if (_CurrentVGMStreamPlayer == null) { _Player.Init(_Reader); } _Player.Play(); _Timer.Start(); _CurrentVGMStreamPlayer = this; btnPlay.Image = Properties.Resources.icon_stop; } } }
public void PlaybackStop() { if (_waveOut != null) { _waveOut.Stop(); } _timer.Stop(); }
public void pause() { if (!pausebool) { wavePlayer.Stop(); pausebool = true; } }
// btn Stop private void OnButtonStopClick(object sender, EventArgs e) { if (driverOut != null) { driverOut.Stop(); StartStopEnabled(); } }
public void Stop() { lock (_lock) { System.Diagnostics.Debug.WriteLine("Stopping audio"); outputDevice.Stop(); IsPlaying = false; } }
public void Next() { lock (monitor) { if (volumeStream != null) { waveOutDevice.Stop(); } } }
private void CloseWaveOut() { _waveOut?.Stop(); if (_waveOut != null) { _waveOut.Dispose(); _waveOut = null; } }
public LiveAudioPlayer Stop() { _waveOut.Stop(); _provider.Stop(); _buffer.ClearBuffer(); _bufferedLength = 0; _bufferLock.Reset(); return(this); }
public void OnTimer() { if (player != null && player.PlaybackState == PlaybackState.Playing) { if (outStream.Position >= outStream.Length) { player.Stop(); } } }
public void Stop() { try { waveOut.Stop(); } catch (Exception e) { throw new RAudioNAudioException("error al parar la reproduccio", e); } }
public void Stop() { _player.Stop(); _positionTimer.Stop(); IsPlaying = false; IsPaused = false; IsStopped = true; Position = 0.0; }
public void Stop() { if (Status != PlaybackStatus.Stopped) { if (_wavePlayer != null) { _wavePlayer.Stop(); _mixer.CurrentTime = TimeSpan.Zero; Status = PlaybackStatus.Stopped; } } }
public void Play(string musicFileName) { WaveStream stream = new Mp3FileReader(musicFileName); stream = new LoopStream(stream); _waveOutDevice.Volume = 0.25f; _waveOutDevice.Stop(); _waveOutDevice.Init(stream); _waveOutDevice.Play(); }
private void EpisodePlayerForm_FormClosed(object sender, FormClosedEventArgs e) { client.CancelAsync(); waveOutDevice.Stop(); if (isCreated) { audioFileReader.Dispose(); } waveOutDevice.Dispose(); }
/// <summary> /// Stops the underlying audio device /// </summary> /// <exception cref="System.InvalidOperationException">Wave device not started</exception> public void Stop() { lock (SyncLock) { if (this.HasInitialized == false) { throw new InvalidOperationException("Wave device not started"); } m_Device.Stop(); // System.Diagnostics.Debug.WriteLine("STOP called on audio renderer."); } }
private static void stop() { if (playbackInitialised) { wavePlayer.Stop(); } currentlyPlaying = false; response.Status = Response.OK; response.Message = "Playback stopped"; writeToLog("Playback stopped"); }
public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav") { KillStreakDevice = KillStreakDevice ?? new WaveOutEvent(); var path = SFXPath + sfxName + "." + ext; Wait(250); AudioFileReader audioFileReader = new AudioFileReader(path); audioFileReader.Volume = 0.6f * Volume; KillStreakDevice.Stop(); KillStreakDevice.Init(audioFileReader); KillStreakDevice.Play(); return KillStreakDevice; }
public static void AskUserToRestartLevelTwo(IWavePlayer waveOutDevice, AudioFileReader audioFileReader) { waveOutDevice.Stop(); Console.Clear(); Console.SetCursorPosition(5, 15); Console.Write("Do you want to RESTART"); Console.SetCursorPosition(13, 16); Console.WriteLine("Y/N"); var check = Console.ReadKey(); Console.Clear(); if (check.Key.ToString().ToLower() == "y") { Console.Clear(); PackManHydra.monsterOneCounter = 0; PackManHydra.monsterTwoCounter = 0; PackManHydra.monsterThreeCounter = 0; PackManHydra.monsterFourCounter = 0; PackManHydra.points = 0; PackManHydra.lives = 3; PackManHydra.currentLevel = 2; Console.ForegroundColor = ConsoleColor.White; Mariyan.DrawGameBoardLevelTwo(); Dimitar.StartCounter(); PackManHydra.InitDotsArray(1); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); PackManHydra.endGame = true; Georgi.RefreshScreen(PackManHydra.badGuysCoordinates, Mariyan.wallsLevelTwo); } else if (check.Key.ToString().ToLower() == "n") { Console.Clear(); PackManHydra.monsterOneCounter = 0; PackManHydra.monsterTwoCounter = 0; PackManHydra.monsterThreeCounter = 0; PackManHydra.monsterFourCounter = 0; PackManHydra.points = 0; PackManHydra.lives = 3; PackManHydra.currentLevel = 1; PackManHydra.endGame = true; PackManHydra.endLevelOne = false; PackManHydra.returnFromLevelTwo = false; Console.Clear(); PackManHydra.Main(); } }
// Stops and disposes of the wave player. Wave players created through // the CreateWavePlayer method should be released by this method. private void ReleaseWavePlayer(IWavePlayer player) { if (player != null) { player.Stop(); player.Dispose(); } }
public void Run(string[] args) { m_settingsModel = LoadSettings(); m_running = true; m_eyeClients = new Dictionary<string, TcpClient>(); m_controllerClients = new Dictionary<string, ControllerItem>(); m_eyeDataQueue = new Queue<byte[]>(); m_controllerDataQueue = new Queue<ControllerData>(); m_commandsQueue = new Queue<Command>(); m_waveOutDevice = new WaveOut(); m_audioFileReader = new AudioFileReader("alarms/default.mp3"); m_waveOutDevice.Init(m_audioFileReader); var argMode = ArgMode.None; foreach (var arg in args) { if (argMode == ArgMode.None) { if (arg == "-ep" || arg == "--eye-port") argMode = ArgMode.EyePort; else if (arg == "-cp" || arg == "--controller-port") argMode = ArgMode.ControllerPort; else if (arg == "-t" || arg == "--token") argMode = ArgMode.Token; else if (arg == "-tr" || arg == "--treshold") argMode = ArgMode.Treshold; else if (arg == "-aa" || arg == "--armed-alarm") argMode = ArgMode.ArmedAlarm; else if (arg == "-s" || arg == "--silent") argMode = ArgMode.Silent; } else if (argMode == ArgMode.EyePort) { var v = m_settingsModel.EyePort; if (int.TryParse(arg, out v)) m_settingsModel.EyePort = v; argMode = ArgMode.None; } else if (argMode == ArgMode.ControllerPort) { var v = m_settingsModel.ControllerPort; if (int.TryParse(arg, out v)) m_settingsModel.ControllerPort = v; argMode = ArgMode.None; } else if (argMode == ArgMode.Token) { m_settingsModel.Token = arg.Trim(); argMode = ArgMode.None; } else if (argMode == ArgMode.Treshold) { var v = m_settingsModel.Treshold; if (int.TryParse(arg, out v)) m_settingsModel.Treshold = v; argMode = ArgMode.None; } else if (argMode == ArgMode.ArmedAlarm) { if (arg == "y" || arg == "yes" || arg == "t" || arg == "true") m_settingsModel.ArmedAlarm = true; else if (arg == "n" || arg == "no" || arg == "f" || arg == "false") m_settingsModel.ArmedAlarm = false; argMode = ArgMode.None; } else if (argMode == ArgMode.Silent) { if (arg == "y" || arg == "yes" || arg == "t" || arg == "true") m_settingsModel.Silent = true; else if (arg == "n" || arg == "no" || arg == "f" || arg == "false") m_settingsModel.Silent = false; argMode = ArgMode.None; } } m_alarmIsArmed = m_settingsModel.ArmedAlarm; Console.WriteLine("* Connection token: " + m_settingsModel.Token); SpawnEyeListenerTask(); SpawnControllerListenerTask(); SpawnEyeProcessorTask(); SpawnControllerProcessorTask(); SpawnCommandsExecutorTask(); while (m_running) { var line = Console.ReadLine(); if (line == "exit") m_running = false; else if (line == "arm") ArmAlarm(); else if (line == "disarm") DisarmAlarm(); else if (line == "alarm-on") StartAlarm(); else if (line == "alarm-off") StopAlarm(); } lock (m_commandsLock) { if (m_commandsQueue != null) { foreach (var command in m_commandsQueue) command.PerformAction(); m_commandsQueue.Clear(); } } lock (m_eyeClientsLock) { if (m_eyeClients != null) foreach (var eye in m_eyeClients) eye.Value.Close(); } lock (m_controllerClientsLock) { if (m_controllerClients != null) foreach (var controller in m_controllerClients) controller.Value.Client.Close(); } while (true) { lock (m_lock) { if (m_eyeListener == null && m_controllerListener == null && m_eyeDataQueue == null && m_controllerDataQueue == null && m_commandsQueue == null) break; } Thread.Sleep(10); } m_alarmIsPlaying = false; lock (m_alarmLock) { m_waveOutDevice.Stop(); m_audioFileReader.Dispose(); m_audioFileReader = null; m_waveOutDevice.Dispose(); m_waveOutDevice = null; } m_eyeClients = null; m_controllerClients = null; SaveSettings(m_settingsModel); Thread.Sleep(1000); }
public IWavePlayer PlayKillStreak(string sfxName, string ext = "wav") { if (!RPGSettings.PlayKillstreaks) return null; KillStreakDevice = KillStreakDevice ?? new WaveOutEvent(); var path = SFXPath + sfxName + "." + ext; Wait(250); if (!File.Exists(path)) { RPGLog.Log("Did not find killstreak SFX to play"); return KillStreakDevice; } AudioFileReader audioFileReader = new AudioFileReader(path); audioFileReader.Volume = 0.6f * Volume; KillStreakDevice.Stop(); KillStreakDevice.Init(audioFileReader); KillStreakDevice.Play(); return KillStreakDevice; }
public static void Main() { Console.Title = "EatSharp"; Dimitar.SetConsoleWidthAndHeight(); Console.OutputEncoding = Encoding.UTF8; if (returnFromHighScores && returnFromInstructions && returnFromLevelOne && returnFromLevelTwo) { DrawLogo(20); DimitarPiskov.PrintGameName(); Console.ReadKey(); Console.Clear(); DimitarPiskov.Introduction(); Console.ReadKey(); Console.Clear(); } // Menu Ivaylo.PrintingMenuGame(); waveOutDevice = new WaveOut(); ConsoleKeyInfo choice = Console.ReadKey(); StringBuilder userNickname = new StringBuilder(); if (choice.Key == ConsoleKey.D1) { Console.Clear(); int currentColumn = 15; bool inputSuccess = true; var nickname = new List<ConsoleKeyInfo>(); Dimitar.AskUserForNickname(ref currentColumn, ref inputSuccess, nickname); Console.ForegroundColor = ConsoleColor.White; Mariyan.DrawGameBoardLevelOne(); Dimitar.StartCounter(); InitDotsArray(1); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); while (!endLevelOne) { Thread.Sleep(200); Ivaylo.MonsterNMovingLevelOne(); Dimitar.MonsterIMovingLevelOne(); Mariyan.MonsterDLevelOne(); Antonina.monsterEMovingLevelOne(); Georgi.RefreshScreen(badGuysCoordinates, Mariyan.wallsLevelOne); if (points >= 1280) //1280 { Thread.Sleep(1500); endLevelOne = true; currentLevel = 2; break; } else if (endGame == false) { Dimitar.AskUserToRestartLevelOne(waveOutDevice, audioFileReader); } } waveOutDevice.Stop(); Dimitar.LevelTwoMessage(); Console.ReadKey(); Console.Clear(); Console.ForegroundColor = ConsoleColor.White; Mariyan.DrawGameBoardLevelTwo(); Dimitar.StartCounter(); InitDotsArray(2); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); monsterOneCounter = 0; monsterTwoCounter = 0; monsterThreeCounter = 0; monsterFourCounter = 0; while (!endLevelTwo) { Thread.Sleep(200); Ivaylo.MonsterNMovingLevelTwo(); Mariyan.MonsterILevelTwo(); Evgeni.MonsterDMovingLevelTwo(); Ivaylo.MonsterEMovingLevelTwo(); Georgi.RefreshScreen(badGuysCoordinates, Mariyan.wallsLevelTwo); if (points >= 2600) //2600 { Thread.Sleep(1500); endLevelTwo = true; try { StreamWriter userScores = new StreamWriter(@"..\..\HighScores.txt"); using (userScores) { user.Append(points); userScores.WriteLine(user); } } catch (FileNotFoundException exMessage) { Console.WriteLine("The file is not found!"); Console.WriteLine(exMessage.Message); } break; } else if (endGame == false) { Dimitar.AskUserToRestartLevelTwo(waveOutDevice, audioFileReader); } } } else if (choice.Key == ConsoleKey.D2) { UserChooseInstructionsMenu(); } else if (choice.Key == ConsoleKey.D3) { UserChooseHighScoresMenu(); } else if (choice.Key == ConsoleKey.D4) { Console.Clear(); Environment.Exit(-1); } Console.Clear(); Mariyan.GameOutro(); Console.CursorVisible = false; }
/// <summary> /// Method that plays whatever the current song is /// </summary> private void playSong() { skipThis = false; Stream stream = Subsonic.StreamSong(currentSong.id); // Try to move this filling of memory stream into the background... Stream ms = new MemoryStream(); byte[] buffer = new byte[32768]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { playerThread.ReportProgress(50); ms.Write(buffer, 0, read); } ms.Position = 0; Mp3FileReader mp3Reader = new Mp3FileReader(ms); WaveStream blockAlignedStream = new BlockAlignReductionStream( WaveFormatConversionStream.CreatePcmStream(mp3Reader)); WaveOut waveOut; waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.Init(blockAlignedStream); waveOut.Play(); playState = PlaybackState.Playing; bool songEnd = false; while (playState != PlaybackState.Stopped && !songEnd && !skipThis) { if (waveOut.PlaybackState == PlaybackState.Stopped) songEnd = true; else { switch (playState) { case PlaybackState.Paused: waveOut.Pause(); break; case PlaybackState.Playing: if (waveOut.PlaybackState != PlaybackState.Playing) waveOut.Play(); else { int progress = (int)(100.0 * mp3Reader.CurrentTime.TotalSeconds / mp3Reader.TotalTime.TotalSeconds); playerThread.ReportProgress(progress); Thread.Sleep(100); } break; default: break; } } } //if (playState == PlaybackState.Stopped) waveOut.Stop(); //waveOut.Dispose(); }