1
I’m a programming intern and I’ve decided to do something I’ve never tried before, a music player. I am building the functions that each button should do but I noticed that I made a mistake in the Pause part by actually making the button stop the music, I wanted a lot of help to discover my mistake.
//===================================================================================
//Começa a reproduzir a música escolhida
private void Iniciar_Click(object sender, RoutedEventArgs e)
{
//Código que reproduz uma música escolhida
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"C:\Users\Juan\Desktop\Biblioteca do Juan\Praticando WPF\musicPlayer\musicPlayer\Vessel.WAV";
player.Play();
//esconder botão iniciar
Iniciar.Visibility = Visibility.Collapsed;
Pausar.Visibility = Visibility.Visible;
}
//===================================================================================
//Para a música que está sendo reproduzida
private void Pausar_Click(object sender, RoutedEventArgs e)
{
//Código que para a música que está rodando
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stop();
//esconder butão pause
Iniciar.Visibility = Visibility.Visible;
Pausar.Visibility = Visibility.Collapsed;
}
I tried to use this code but when I got to the part of "if(openFileDialog1.Showdialog() == Dialogresult.OK" he accused that ". OK" was incorrect, as was "media.Source = openFileDialog1.Filename;" it accuses a code error after the "="
– Juan Veras
If your program is console
using System.Windows.Forms;
If wpf putusing Microsoft.Win32;
– Augusto Vasques
Opa Augusto, I’m using WPF msm but already used Win32, when I debug the application I get two errors 1- over the ". OK" ( read below ) 'bool? 'does not contain a definition for 'OK' and no accessible extension method 'OK' accepts a first argument of type 'bool'? 'can be found (you are missing a directive using or a reference from Assembly?) 2- on openFileDialog1,Filename; (below tbm) Cannot implicity Convert type 'string' to 'System.Uri'
– Juan Veras
Barter
if (openFileDialog1.ShowDialog() == DialogResult.OK)
forif (openFileDialog1.ShowDialog())
– Augusto Vasques
I still have 2 errors, I think instead of if (openFileDialog1.Showdialog() == Dialogresult.OK) or if (openFileDialog1.Showdialog().... i should put if(openFileDialog1.Showdialog() == true) and on the line below a media.Open(new Uri(openFileDialog1.Filename));
– Juan Veras
although it would still be wrong because of "media. Open"
– Juan Veras
I made an edition the code runs 100%.
– Augusto Vasques