// Stop lecture en cours + delete temporary midi file void stop_and_delete_file() { mplayer.Stop(); mplayer.Close(); isPlaying = false; deleteFile(); }
//protected override void Dispose(Boolean disposing) protected virtual void Dispose(Boolean disposing) { if (_disposed) { return; } if (disposing) { if (_mediaPlayer != null && (_mediaPlayer.HasAudio || _mediaPlayer.HasVideo)) { _mediaPlayer.Close(); _mediaPlayer = null; } } if (_scanTimer != null) { _scanTimer.Stop(); _scanTimer = null; } if (_secondTimer != null) { _secondTimer.Stop(); _secondTimer = null; } }
private void DownloadButton_Click(object sender, RoutedEventArgs e) { mediaPlayer.Close(); PlayButton.Visibility = Visibility.Visible; StopButton.Visibility = Visibility.Hidden; string finalmp3 = finalFile(); SaveFileDialog savepdf = new SaveFileDialog(); savepdf.DefaultExt = ".mp3"; // Default file extension savepdf.Filter = "MP3 File (.mp3)|*.mp3"; if (savepdf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string newDirectory = savepdf.FileName; if (!File.Exists(newDirectory)) { File.Copy(finalmp3, newDirectory); System.Windows.MessageBox.Show("Download Completed"); } else { System.Windows.MessageBox.Show("A File with same name Exists "); } } }
public void cevapla(string soru) { string text = ""; mediaPlayer.Close(); if (String.IsNullOrEmpty(soru)) { text = "yoksa bana küstün mü ?"; } else { try { soru = soru.Substring(0, yazi.Length - 6); Console.WriteLine("soru :" + soru); text = db.sor(soru.ToLower()); cevaplayamadim = false; durdurma = false; durdurmaBtn.Visibility = Visibility.Hidden; } catch (Exception e) { text = "Anlamadım. Lütfen tekrar söyle."; cevaplayamadim = true; durdurmaBtn.Visibility = Visibility.Visible; } finally { db.bagKapat(); } } yazi = text; VoiceSelectionParams voice = new VoiceSelectionParams { LanguageCode = "tr-TR", SsmlGender = SsmlVoiceGender.Male }; AudioConfig config = new AudioConfig { AudioEncoding = AudioEncoding.Mp3 }; SynthesisInput input = new SynthesisInput { Text = text }; var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest { Input = input, Voice = voice, AudioConfig = config }); using (Stream output = File.Create("C:\\Users\\corx\\source\\repos\\Selami\\Selami\\ses\\sample.mp3")) { response.AudioContent.WriteTo(output); } mediaPlayer.Open(new Uri("C:\\Users\\corx\\source\\repos\\Selami\\Selami\\ses\\sample.mp3")); mediaPlayer.Play(); }
static void GetMediaDurationThreadStart(object context) { var mediaData = (MediaData)context; var mediaPlayer = new MediaPlayer(); mediaPlayer.MediaOpened += delegate { if (mediaPlayer.NaturalDuration.HasTimeSpan) { mediaData.Duration = mediaPlayer.NaturalDuration.TimeSpan; } mediaData.Success = true; mediaPlayer.Close(); }; mediaPlayer.MediaFailed += delegate { mediaData.Failure = true; mediaPlayer.Close(); }; mediaPlayer.Open(mediaData.MediaUri); Dispatcher.Run(); }
internal void Open(string fullName, string shortName) { FileName = shortName; _player.Close(); _player.Open(new Uri(fullName)); }
private async void Button_Click(object sender, RoutedEventArgs e) { engine.CurrentGame.ForceEndGame(); soundTrackMediaPlayer.Close(); gameOverStoryboard.Begin(GameBackground); if (engine.CurrentGame.GameStats.RedPoints > engine.CurrentGame.GameStats.BluePoints) { WinnerLabel.Content = "Red Wins!"; soundEffectPlayer.WinSound(); } else if (engine.CurrentGame.GameStats.RedPoints < engine.CurrentGame.GameStats.BluePoints) { WinnerLabel.Content = "Blue Wins!"; soundEffectPlayer.LostSound(); } else { WinnerLabel.Content = "It's a tie!"; soundEffectPlayer.LostSound(); } await Task.Delay(4000); Switcher.Switch(new Scores(engine.CurrentGame.GameStats)); }
/// <summary> /// Show same informations of Current Country /// </summary> /// <param name="countrySelect"></param> private void ShowInfoCountry(Country countrySelect) { //Media Player _mediaPlayer.Close(); sliProgress.Value = 0; pbVolume.Value = 0; if (countrySelect.AnthemPath != null) { Player(countrySelect); } //Visibility LabelHour.Visibility = Visibility.Hidden; LabelInfo.Visibility = Visibility.Hidden; MainPanel.Visibility = Visibility.Visible; //Data Context MainPanel.DataContext = countrySelect; TabLanguage.DataContext = countrySelect.Translations; //Information About Coutry Wiki TextBlockOthers.Text = ReadInfoCountry(countrySelect); //Currency Converter TextBoxInput.Text = string.Empty; TextBoxOutput.Text = string.Empty; CheckCurrency(countrySelect, Rates); //Covid19 Information if (_rootCovid != null) { if (_rootCovid.Countries.Count != 0) { var infocovid = _rootCovid.Countries.SingleOrDefault(c => c.CountryCode == countrySelect.Alpha2Code); if (infocovid != null) { PanelCovidCountry.DataContext = infocovid; } } if (!_rootCovid.Global.Equals(null)) { PanelCovidGlobal.DataContext = _rootCovid.Global; TxtRootdate.DataContext = _rootCovid; } else { TxtRootdate.Text = "Not Available"; } } else { TxtCovidC.Text = "Not Available"; TxtRootdate.Text = "Not Available"; } //Populate ListBox listBoxCurrency.ItemsSource = countrySelect.Currencies; listBoxLanguage.ItemsSource = countrySelect.Languages; //Borders BorderInfo.DataContext = null; Borders(countrySelect); TabControlMain.SelectedIndex = 0; }
void mediaPlayer_MediaEnded(object sender, EventArgs e) { mediaPlayer.Close(); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); }
public void Stop() { _synthesizer.SpeakAsyncCancelAll(); _player.Stop(); _player.Close(); State = TalkerStatus.Stop; _randomIndexes = null; ResetTaskAudioFilePreparation(); }
private void BandInfo_Click(object sender, RoutedEventArgs e) { this.Close(); mplayer.Close(); this.Close(); BandInfoView bandInfoView = new BandInfoView(); bandInfoView.Show(); }
private void MiniPlayerButton_Click(object sender, RoutedEventArgs e) { if (SongsListBox.Items.Count != 0) { MiniPlayer mp = new MiniPlayer(); for (int i = 0; i < SongsListBox.Items.Count; i++) { mp.SongsListBox.Items.Add(SongsListBox.Items[i]); } mp.playing = playing; mp.SongsListBox.SelectedIndex = SongsListBox.SelectedIndex; mp.isPlaying = isPlaying; mp.timer.Interval = timer.Interval; mp.timer.Tick += mp.Timer_Tick; mp.timer.Start(); mp.PositionSlider.Value = PositionSlider.Value; mp.PositionSlider.Maximum = PositionSlider.Maximum; mp.PositionSlider.IsEnabled = PositionSlider.IsEnabled; mp.PositionLabel.Content = PositionLabel.Content; mp.VolumeSlider.Value = VolumeSlider.Value; mp.VolumeLabel.Content = VolumeLabel.Content; mp.mediaPlayer.Volume = VolumeSlider.Value; mp.mediaPlayer.Balance = mediaPlayer.Balance; mp.PlayPauseButton.Background = PlayPauseButton.Background; mp.StopButton.Background = StopButton.Background; mp.RepeatButton.Background = RepeatButton.Background; mp.RepeatButton.Content = RepeatButton.Content; mp.repeatType = repeatType; mp.ShuffleButton.Background = ShuffleButton.Background; mp.shuffle = shuffle; try { mp.mediaPlayer.Open(new Uri(SongsListBox.Items[playing].ToString())); mp.Show(); if (mp.isPlaying == 2) { mp.mediaPlayer.Play(); } else if (mp.isPlaying == 1) { mp.mediaPlayer.Pause(); } mp.mediaPlayer.Position = mediaPlayer.Position; } catch { mp.Show(); } mediaPlayer.Close(); Close(); } else { MessageWindow.Show("Empty playlist", "Please add some songs to your playlist first.", MessageBoxButton.OK, MessageWindow.MessageBoxImage.Information); } }
private void btnStop_Click(object sender, RoutedEventArgs e) { mediaPlayer.Stop(); tbPlaybackState.Text = "00:00 / 00:00"; mediaPlayer.Close(); btnPause.IsEnabled = false; btnPlay.IsEnabled = true; btnStop.IsEnabled = false; }
private void Player_MediaEnded(object sender, EventArgs e) { if (++currentPlayIndex < length) { player.Close(); player.Open(new Uri(songPaths[currentPlayIndex])); player.Play(); OnMediaChange(new PlaylistEventArgs(songPaths[currentPlayIndex])); } }
private void GameOver_Click(object sender, RoutedEventArgs e) { unstable.Close(); neutralize.Close(); deposit.Close(); orbGrab.Close(); powerup.Close(); collapse.Close(); ghost.Close(); boost.Close(); }
/// ############################### /// CHECKBOX METHODS /// ############################### // defines behavior upon checking the "Deactivate Hotkeys" checkbox // deactivates all currently registered global hotkeys and prevents new hotkeys from being registered private void checkInactive_Checked(object sender, RoutedEventArgs e) { bIsInactive = true; // dispose of all active globalhotkeys for (int i = 0; i < globalHotkeys.Count; i++) { globalHotkeys[i].Unregister(); } player.Close(); // ensure that the media player is closed }
private void TestButton_Click(object sender, RoutedEventArgs e) { try { mediaPlayer.Stop(); mediaPlayer.Close(); var uri = new Uri(FileOpener.GetAbsoluteFilePath(SoundFile.Text)); mediaPlayer.Open(uri); mediaPlayer.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override sealed void Update(MediaPlayer mediaPlayer, CustomControls.ClickableProgressBar timeProgressBar, out string title, Button playButton, Button pauseButton) { title = string.Empty; if (mediaPlayer != null) { mediaPlayer.Stop(); mediaPlayer.Close(); } if (timeProgressBar != null) { timeProgressBar.Value = 0; timeProgressBar.Minimum = 0; timeProgressBar.Maximum = 1; } if (playButton != null) { playButton.IsEnabled = false; playButton.Visibility = Visibility.Visible; } if (pauseButton != null) { pauseButton.IsEnabled = false; pauseButton.Visibility = Visibility.Collapsed; } }
private void Mp_MediaEnded(object sender, EventArgs e) { Dispatcher.BeginInvoke((Action)(() => { foreach (var button in buttons) { button.Tag = "0"; button.Content = ""; } mp.Stop(); mp.Close(); System.IO.File.Delete(this.downloadFileName); this.PlayingRandomSong(); })); }
private void BT_Click_Stop(object sender, RoutedEventArgs e) { mediaPlayer.Stop(); filename = ""; File_Name.Text = filename; url_youtube.Text = ""; mediaPlayer.Close(); controls.Visibility = Visibility.Hidden; if (!is_syncing) { file_search.Visibility = Visibility.Visible; } youtube_search.Visibility = Visibility.Visible; sync_bar.Visibility = Visibility.Collapsed; curr_time.Text = "--:--:--"; final_time.Text = "--:--:--"; is_playing = "0"; last_is_playing = "0"; if (is_syncing) { if (is_host) { update_clients(); } } play_pause_button.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play; is_total_time_set = false; slider_to_be_updated = false; slider_timer.Value = 0; }
public static void Close() { ambienceSound.Stop(); startSound.Close(); ambienceSound.Close(); hornSound.Close(); }
private void Editbutton_Click(object sender, EventArgs e) { // Stop music from playing while edditing isPlaying = false; gif.Enabled = false; Play_button.Text = "Play"; media.Close(); try { string producer = songsInfo[Songs.SelectedIndex, 0]; string realeaseYear = songsInfo[Songs.SelectedIndex, 1]; string genre = songsInfo[Songs.SelectedIndex, 2]; string language = songsInfo[Songs.SelectedIndex, 3]; int index = Songs.SelectedIndex; Form2 editForm = new Form2(producer, realeaseYear, genre, language, index, this); editForm.Show(); } catch (IndexOutOfRangeException) { MessageBox.Show("Please select the song you want to edit, and then click the edit button"); } }
public override void Unload() { Click.Close(); DialogBox.Dispose(); DialogBox = null; foreach (var i in CharImages) { i.Value.Dispose(); } CharImages.Clear(); foreach (var i in BGImages) { i.Value.Dispose(); } BGImages.Clear(); Dialog.Dispose(); Dialog = null; if (Game.worldscreen != null) { Game.worldscreen.Active = true; Game.worldscreen.MapName.Visible = true; } Game.InScene = false; base.Unload(); }
/// <summary> /// Gets the play time for a music file. /// </summary> /// <param name="fileName"> /// The full path of the music file e.g. "C:\Users\Public\Music\song.mp3". /// </param> /// <returns> /// The file play time in seconds (0 if failed). /// </returns> public static Primitive MusicPlayTime(Primitive fileName) { if (!System.IO.File.Exists(fileName)) { Utilities.OnFileError(Utilities.GetCurrentMethod(), fileName); return(0); } try { MediaPlayer mediaPlayer = new MediaPlayer(); Uri uri = new Uri(fileName); mediaPlayer.Open(uri); //Wait for the player to open the file (up to 1 sec) int iCount = 0; while (!mediaPlayer.NaturalDuration.HasTimeSpan && iCount < 100) { Thread.Sleep(10); iCount++; } Duration duration = mediaPlayer.NaturalDuration; int sec = duration.TimeSpan.Minutes * 60 + duration.TimeSpan.Seconds + 1; //Round up mediaPlayer.Close(); return(sec); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(0); }
private void Window_Closed(object sender, EventArgs e) { soundMulti(); song.Close(); vm.Open -= OpenWin; vm.closeGame(); }
static void Main(string[] args) { if (args.Length == 0) { return; } Console.Write(args[0] + ": "); MediaPlayer player = new MediaPlayer(); Uri path = new Uri(args[0]); player.Open(path); TimeSpan maxWaitTime = TimeSpan.FromSeconds(10); DateTime end = DateTime.Now + maxWaitTime; while (DateTime.Now < end) { System.Threading.Thread.Sleep(100); Duration duration = player.NaturalDuration; if (duration.HasTimeSpan) { Console.WriteLine(duration.TimeSpan.ToString()); break; } } player.Close(); }
private void fileExistsErrorHandling(object sender, RoutedEventArgs e, string filename, InvalidOperationException ex) { MessageBox.Show(ex.Message, "Error!"); if (MessageBox.Show("Do you want to delete the existing file?", "Suggestion", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { _mediaPlayer.Close(); playerButtonsState(false); if (File.Exists(filename + ".wav")) { File.SetAttributes(filename + ".wav", FileAttributes.Normal); File.Delete(filename + ".wav"); } File.SetAttributes(filename, FileAttributes.Normal); File.Delete(filename); } else { return; } }
public Task Play(string filePath, int volume) { if (File.Exists(filePath)) { volume = MathHelper.Clamp(volume, 0, 100); Task.Run(async() => { bool mediaEnded = false; MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.MediaEnded += (object sender, EventArgs e) => { mediaEnded = true; }; mediaPlayer.Open(new Uri(filePath)); mediaPlayer.Volume = ((double)volume / 100.0); mediaPlayer.Play(); while (!mediaEnded) { await Task.Delay(500); } mediaPlayer.Close(); }); } return(Task.FromResult(0)); }
private void SeekNextFrame() { //If more frames remain to capture... if (_positions.Count > 0) { //Seek to next position. //_lowerPlayer.Position = _positions.Dequeue(); Dispatcher?.BeginInvoke(new Action(() => { //_lowerPlayer.Changed -= CapturePlayer_Changed; //_lowerPlayer.Position = TimeSpan.Zero; //_lowerPlayer.Changed += CapturePlayer_Changed; _lowerPlayer.Position = _positions.Dequeue(); })); UpdateProgressBar(_positions.Count); return; } _lowerPlayer.Changed -= CapturePlayer_Changed; _lowerPlayer.Close(); GC.Collect(); DialogResult = true; }
private void SetSound() { OpenFileDialog fileBrowser = new OpenFileDialog() { Filter = "Sound files | *.wav; *.mp3; *.mid", }; if ((bool)fileBrowser.ShowDialog()) { if (soundPlayer != null) { soundPlayer.Stop(); soundPlayer.Close(); soundPlayer = null; } soundPlayer = new MediaPlayer(); soundPlayer.Open(new Uri(fileBrowser.FileName)); soundPlayer.MediaEnded += (a, b) => { soundPlayer.Stop(); }; SoundFileName = Path.GetFileNameWithoutExtension(fileBrowser.FileName); } }