Skip to content

Commit

Permalink
v3.0
Browse files Browse the repository at this point in the history
- Se agregó un botón para borrar todo el historial.
- Sistema de favoritos completa.
- Se agregó información al momento de agregar una música.
- Se agregaron más temas.
  • Loading branch information
Ts-Pytham committed Jan 4, 2021
1 parent 6c6fed7 commit b9e2ce5
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 93 deletions.
Binary file modified .vs/Reproductor de Musica/v16/.suo
Binary file not shown.
15 changes: 14 additions & 1 deletion Reproductor de Musica/ColorsRGB.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,21 @@ private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<d
}
else if (rect.Name == "Rectangle5")
{
Window.Mainwindow.LTheme[4] = Window.Rectangle5.Fill.ToString();
Window.Mainwindow.LTheme[6] = Window.Rectangle5.Fill.ToString();

Window.Mainwindow.Button_Erase.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
Window.Mainwindow.ListBox.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
int len = Window.Mainwindow.ListBox.Items.Count;
for(int i = 0; i != len; ++i)
{
if (i != Window.Mainwindow.IsSelected)
{

TextBlock data = (TextBlock)Window.Mainwindow.ListBox.Items[i];
data.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
}
}

Window.Mainwindow.TextBlock_Add.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
Window.Mainwindow.TextBlock_Favorite.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
Window.Mainwindow.TextBlock_PlayList.Foreground = new SolidColorBrush(Color.FromRgb((byte)R.Value, (byte)G.Value, (byte)B.Value));
Expand Down
187 changes: 132 additions & 55 deletions Reproductor de Musica/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public partial class MainWindow : Window
private string Name_Song_URL;
public Historial historial = new Historial();
private TimeSpan position;
private int IsSelected = -1; // Comprueba que canción está seleccionada para darle color
public int IsSelected = -1; // Comprueba que canción está seleccionada para darle color

private TimeSpan suma = new TimeSpan();
public WinAjuste win;
Expand All @@ -57,6 +57,7 @@ public MainWindow()

if (IO.File.Exists("theme.pytham"))
{

GetTheme();
}

Expand All @@ -71,6 +72,7 @@ public MainWindow()

if (IO.File.Exists("historial.pytham"))
{
MessageBox.Show(IO.Path.GetFullPath("historial.pytham"));
historial = Utilities<Historial>.GetFile("historial");
URLS = historial.LURL;
int i = 0;
Expand Down Expand Up @@ -165,6 +167,12 @@ private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e
/* Creo el try catch para comprobar si lo que ingresa es un botón o un imagen
* Sirve para que tanto el botón como el textBlock puedan acceder a sus bloque de código.
*/
if (IsFavorited)
{
MessageBox.Show("¡No puedes agregar una o varias música cuando estés en modo favorito!", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}

TextBlock textBlock = new TextBlock();
Image image = new Image();
try
Expand All @@ -190,18 +198,14 @@ private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e

using (var fd = new WinForms.OpenFileDialog())
{
fd.Filter = "Music Files(*.MP3; *.Webm)|*.MP3; *.Webm";
fd.Filter = "Music Files(*.MP3; *.Webm; *.wav)|*.MP3; *.Webm; *.wav";

fd.FilterIndex = 1;

if (fd.ShowDialog() == WinForms.DialogResult.OK)
{



mediaPlayer.Open(new Uri(fd.FileName));


Image img = new Image { Source = new BitmapImage(new Uri(@"pack://application:,,,/IMG/pausa.png")) };
Button_Reproductor.Content = img;
IsPaused = false;
Expand All @@ -221,7 +225,6 @@ private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e

TagLib.File tagFile = TagLib.File.Create(fd.FileName, "audio/mp3", TagLib.ReadStyle.Average);


string str = $"Autor: {(!String.IsNullOrEmpty(tagFile.Tag.FirstAlbumArtist) ? tagFile.Tag.FirstAlbumArtist : "N/A")}.\n" +
$"Duración: {tagFile.Properties.Duration:hh\\:mm\\:ss}.\n" +
$"Tamaño: {Math.Round(new IO.FileInfo(fd.FileName).Length/ 1048576d, 3)} MB.\n" +
Expand Down Expand Up @@ -321,19 +324,23 @@ private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e
suma += tagFile.Properties.Duration;
}

if (IsSelected != -1)
((TextBlock)ListBox.Items[IsSelected]).Foreground = Brushes.White;

// Comprueba si en la lista hay música, si no hay pone el index en 0.
if (IsEmpty)
{
ListBox.SelectedIndex = 0;
((TextBlock)ListBox.Items[0]).Foreground = (Brush)new BrushConverter().ConvertFrom("#FFFE4164");
mediaPlayer.Open(new Uri(URLS[0]));

IsSelected = 0;
}
else
{
ListBox.SelectedIndex = ListBox.Items.Count - 1;
((TextBlock)ListBox.Items[ListBox.SelectedIndex]).Foreground = (Brush)new BrushConverter().ConvertFrom("#FFFE4164");
mediaPlayer.Open(new Uri(URLS[URLS.Count - 1]));

IsSelected = ListBox.Items.Count - 1;
}
}
}
Expand All @@ -343,7 +350,6 @@ private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e

private void MediaPlayer_MediaOpened(object sender, EventArgs e)
{


mediaPlayer.Play();
GetFavorite();
Expand Down Expand Up @@ -472,12 +478,20 @@ private void ListBox_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs
timer.Start();

mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;

mediaPlayer.Open(new Uri(URLS[ListBox.SelectedIndex]));

if (IsSelected != -1)
((TextBlock)ListBox.Items[IsSelected]).Foreground = Brushes.White;

{
try
{
((TextBlock)ListBox.Items[IsSelected]).Foreground = (Brush)new BrushConverter().ConvertFrom(LTheme[4]);
}
catch (System.ArgumentOutOfRangeException)
{
((TextBlock)ListBox.Items[IsSelected - 1]).Foreground = (Brush)new BrushConverter().ConvertFrom(LTheme[4]);
}
}
((TextBlock)ListBox.Items[ListBox.SelectedIndex]).Foreground = (Brush)new BrushConverter().ConvertFrom("#FFFE4164");
IsSelected = ListBox.SelectedIndex;
IsPaused = true;
Expand All @@ -494,7 +508,69 @@ private void ListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
ListBox.SelectedIndex = -1;
}


/* Esta función sirve para arrastrar archivos de música*/

private void ListBox_Drop(object sender, DragEventArgs e)
{
if (IsFavorited)
{
MessageBox.Show("¡No puedes agregar una o varias músicas cuando estés en modo favorito!", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}

/*Obtiene la url del archivo*/
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

//MessageBox.Show($"la posición 0 es: {files[0]}");
foreach (var file in files)
{
string GetExtensionFile = IO.Path.GetExtension(file);
int CompareResult1 = String.Compare(GetExtensionFile, ".mp3", StringComparison.OrdinalIgnoreCase);
int CompareResult2 = String.Compare(GetExtensionFile, ".WebM", StringComparison.OrdinalIgnoreCase);
int CompareResult3 = String.Compare(GetExtensionFile, ".wav", StringComparison.OrdinalIgnoreCase);
if (CompareResult1 != 0 && CompareResult2 != 0 && CompareResult3 != 0)
{
MessageBox.Show($"Formato de archivo inválido.\nArchivo: {file}", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);

}
else
{
TagLib.File tagLib = TagLib.File.Create(file, "audio/mp3", TagLib.ReadStyle.Average);

string str = $"Autor: {(!String.IsNullOrEmpty(tagLib.Tag.FirstAlbumArtist) ? tagLib.Tag.FirstAlbumArtist : "N/A")}.\n" +
$"Duración: {tagLib.Properties.Duration:hh\\:mm\\:ss}.\n" +
$"Tamaño: {Math.Round(new IO.FileInfo(file).Length / 1048576d, 3)} MB.\n" +
$"Album: {(!String.IsNullOrEmpty(tagLib.Tag.Album) ? tagLib.Tag.Album : "N/A")}.";

ToolTip toolTip = new ToolTip
{
Content = str
};
TextBlock tb = new TextBlock
{
Text = $"{ListBox.Items.Count + 1} - {IO.Path.GetFileNameWithoutExtension(file)}",
ToolTip = toolTip
};
ListBox.Items.Add(tb);
URLS.Add(file);
}

}

DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
timer.Tick += Timer_Tick;
timer.Start();

mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;

TextBlock_Info_PlayList.Text = $"Duración total: {suma:dd\\:hh\\:mm\\:ss}";


}


//=======================================================================

Expand All @@ -508,7 +584,7 @@ void Timer_Tick(object sender, EventArgs e)
if(ListBox.Items.Count != 1 && ListBox.SelectedIndex != ListBox.Items.Count - 1)
{
mediaPlayer.Open(new Uri(URLS[ListBox.SelectedIndex + 1]));
Name_Music.Text = ListBox.Items[ListBox.SelectedIndex + 1].ToString();
Name_Music.Text = ((TextBlock)ListBox.Items[ListBox.SelectedIndex + 1]).Text;
ListBox.SelectedIndex += 1;
mediaPlayer.Play();
}
Expand Down Expand Up @@ -625,46 +701,6 @@ private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
}



/* Esta función sirve para arrastrar archivos de música*/

private void ListBox_Drop(object sender, DragEventArgs e)
{
/*Obtiene la url del archivo*/
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

//MessageBox.Show($"la posición 0 es: {files[0]}");
foreach (var file in files)
{
if (IO.Path.GetExtension(file) != ".mp3" && IO.Path.GetExtension(file) != ".WebM")
{
MessageBox.Show("Formato de archivo inválido", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}

}

DispatcherTimer timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
timer.Tick += Timer_Tick;
timer.Start();

mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;

int len = files.Length;
for(int i = 0; i != len; ++i)
{
TagLib.File tagLib = TagLib.File.Create(files[i], "audio/mp3", TagLib.ReadStyle.Average);

ListBox.Items.Add($"{ListBox.Items.Count + 1} - {IO.Path.GetFileNameWithoutExtension(files[i])}");
URLS.Add(files[i]);
suma += tagLib.Properties.Duration;
}

TextBlock_Info_PlayList.Text = $"Duración total: {suma:dd\\:hh\\:mm\\:ss}";
}
/* Eventos para guardar las canciones favoritas */


Expand All @@ -683,7 +719,16 @@ private void Image_Favorite_MouseLeftButtonDown(object sender, MouseButtonEventA
}
else
{

IMG_Favorite.Source = new BitmapImage(new Uri(@"pack://application:,,,/IMG/Favorite/favorite.png"));
if (IsFavorited)
{
URLS.RemoveAt(ListBox.SelectedIndex);
ListBox.Items.RemoveAt(ListBox.SelectedIndex);
mediaPlayer.Stop();

}

ListFavorites.Remove(Name_Music.Text);
F_URLS.Remove(Name_Song_URL);
}
Expand Down Expand Up @@ -770,6 +815,38 @@ private void TextBlock_Favorite_MouseLeftButtonDown(object sender, MouseButtonEv

}
}
else if(ListBox.Items.Count == 0 && IsFavorited)
{
TextBlock_Favorite.Text = "Favoritas";
int i = 0;
URLS = LAux_URLS.ToList();

foreach (var data in LAux_Songs)
{
TagLib.File tagFile = TagLib.File.Create(URLS[i], "audio/mp3", TagLib.ReadStyle.Average);

string str = $"Autor: {(!String.IsNullOrEmpty(tagFile.Tag.FirstAlbumArtist) ? tagFile.Tag.FirstAlbumArtist : "N/A")}.\n" +
$"Duración: {tagFile.Properties.Duration:hh\\:mm\\:ss}.\n" +
$"Tamaño: {Math.Round(new IO.FileInfo(URLS[i]).Length / 1048576d, 3)} MB.\n" +
$"Album: {(!String.IsNullOrEmpty(tagFile.Tag.Album) ? tagFile.Tag.Album : "N/A")}.";

ToolTip toolTip = new ToolTip
{
Content = str
};
TextBlock tb = new TextBlock
{
Text = data,
ToolTip = toolTip
};

ListBox.Items.Add(tb);
i++;
}


IsFavorited = false;
}


}
Expand Down
Loading

0 comments on commit b9e2ce5

Please sign in to comment.