-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3.cs
311 lines (255 loc) · 11.5 KB
/
mp3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Vlc.DotNet.Forms;
using System.Net.Http;
using Newtonsoft.Json;
using Vlc.DotNet.Wpf;
namespace Proyecto_Reproductor
{
public partial class mp3 : Form
{
public mp3()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Canciones.SelectedItem != null)
{
string selectedFilePath = Canciones.SelectedItem.ToString();
string selectedFileName = Path.GetFileName(selectedFilePath);
string firstPart = GetFirstPart(selectedFileName);
string secondPart = GetSecondPart(selectedFileName);
label1.Text = firstPart;
label2.Text = secondPart;
}
}
private string GetFirstPart(string fileName)
{
const string Dash = "-";
int dashIndex = fileName.IndexOf(Dash);
if (dashIndex >= 0)
{
string firstPart = fileName.Substring(0, dashIndex).Trim();
return firstPart;
}
else
{
return string.Empty;
}
}
private string GetSecondPart(string fileName)
{
const string Dash = "-";
int dashIndex = fileName.IndexOf(Dash);
if (dashIndex >= 0 && dashIndex < fileName.Length - 1)
{
string secondPart = fileName.Substring(dashIndex + 1).Trim();
return secondPart;
}
else
{
return string.Empty;
}
}
private Dictionary<string, string> artistImages = new Dictionary<string, string>();
private void mp3_Load(object sender, EventArgs e)
{
artistImages.Add("Shawn Mendes", @"C:\Users\eduar\Downloads\shawn.jpg");
artistImages.Add("Imagine Dragons", @"C:\Users\eduar\Downloads\imgdr.jpg");
artistImages.Add("Hozier", @"C:\Users\eduar\Downloads\Hozier.jpg");
artistImages.Add("Paulo Londra" , @"C:\Users\eduar\Downloads\pl.jpg");
artistImages.Add("Julia Michaels", @"C:\Users\eduar\Downloads\jm.jpg");
artistImages.Add("Ed Sheeran", @"C:\Users\eduar\Downloads\si es ed.jpg");
vlcControl.Audio.Volume = 50; // Establecer el volumen inicial
string carpeta = @"C:\Users\eduar\OneDrive\Escritorio\mp3"; // Ruta de tu carpeta que contiene los archivos MP3
// Obtén la lista de archivos MP3 de la carpeta
string[] archivos = Directory.GetFiles(carpeta, "*.mp3");
// Agrega solo los nombres de los archivos al ListBox sin la extensión
foreach (string archivo in archivos)
{
string nombreArchivo = Path.GetFileNameWithoutExtension(archivo);
Canciones.Items.Add(nombreArchivo);
}
}
private void Canciones_DoubleClick(object sender, EventArgs e)
{
if (Canciones.SelectedItem != null)
{
if (Canciones.SelectedItem != null)
{
string nombreArtista = GetSecondPart(Canciones.SelectedItem.ToString());
MostrarImagenArtista(nombreArtista);
string nombreArchivo = Canciones.SelectedItem.ToString();
string rutaArchivo = Path.Combine(@"C:\Users\eduar\OneDrive\Escritorio\mp3", nombreArchivo + ".mp3");
label1.Text = Path.GetFileNameWithoutExtension(rutaArchivo);
vlcControl.Stop(); // Detener la reproducción actual antes de cargar el nuevo archivo
vlcControl.SetMedia(new FileInfo(rutaArchivo));
vlcControl.Play();
}
}
}
private string GetTruncatedFileName(string fileName)
{
const string Dash = "-";
int dashIndex = fileName.IndexOf(Dash);
if (dashIndex >= 0)
{
string truncatedFileName = fileName.Substring(0, dashIndex);
return truncatedFileName;
}
else
{
return fileName;
}
}
private void button19_Click(object sender, EventArgs e)
{
button19.SendToBack();
vlcControl.Pause();
}
private void button18_Click(object sender, EventArgs e)
{
currentFileIndex--; // disminuye el índice
if (currentFileIndex < 0) // si el índice es menor a 0, significa que estamos en el primer archivo, así que establece el índice en el último archivo en el ListBox
{
currentFileIndex = Canciones.Items.Count - 1;
}
string nombreArchivo = Canciones.Items[currentFileIndex].ToString(); // obtiene el nombre del archivo correspondiente al índice actual
string rutaArchivo = Path.Combine(@"C:\Users\eduar\OneDrive\Escritorio\mp3", nombreArchivo + ".mp3"); // construye la ruta completa del archivo
vlcControl.SetMedia(new FileInfo(rutaArchivo)); // establece la ruta del archivo en el control de VLC
vlcControl.Play(); // reproduce el archivo en el control de VLC
string nombreArtista = GetSecondPart(Canciones.Items[currentFileIndex].ToString());
MostrarImagenArtista(nombreArtista);
Canciones.SelectedIndex = currentFileIndex; // Mueve la selección del ListBox al índice actual
}
private int currentFileIndex = 0;
private void button20_Click(object sender, EventArgs e)
{
currentFileIndex++; // incrementa el índice
if (currentFileIndex >= Canciones.Items.Count) // si el índice supera la cantidad de archivos en el ListBox, vuelve al primer archivo
{
currentFileIndex = 0;
}
string nombreArchivo = Canciones.Items[currentFileIndex].ToString(); // obtiene el nombre del archivo correspondiente al índice actual
string rutaArchivo = Path.Combine(@"C:\Users\eduar\OneDrive\Escritorio\mp3", nombreArchivo + ".mp3"); // construye la ruta completa del archivo
vlcControl.SetMedia(new FileInfo(rutaArchivo)); // establece la ruta del archivo en el control de VLC
vlcControl.Play(); // reproduce el archivo en el control de VLC
string nombreArtista = GetSecondPart(Canciones.Items[currentFileIndex].ToString());
MostrarImagenArtista(nombreArtista);
Canciones.SelectedIndex = currentFileIndex; // Mueve la selección del ListBox al índice actual
}
private void button24_Click(object sender, EventArgs e)
{
button24.SendToBack();
vlcControl.Play();
}
private void macTrackBar2_ValueChanged(object sender, decimal value)
{
vlcControl.Audio.Volume = 50; // Establecer el volumen inicial
vlcControl.Audio.Volume = macTrackBar2.Value * 10;
}
private async Task<string> ObtenerLetraDesdeJson(string json)
{
dynamic response = await Task.Run(() => JsonConvert.DeserializeObject(json));
string letra = response.message.body.lyrics.lyrics_body;
return letra;
}
private async Task<string> BuscarLetraCancion(string artistName, string trackName)
{
try
{
string apiKey = "afa99817e0dd31c785ba4d712401c631"; // Reemplaza "tu_clave_de_API" con tu clave de API de Musixmatch
string url = $"https://api.musixmatch.com/ws/1.1/matcher.lyrics.get?apikey={apiKey}&q_track={Uri.EscapeDataString(trackName)}&q_artist={Uri.EscapeDataString(artistName)}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
string letraCancion = await ObtenerLetraDesdeJson(json);
return letraCancion;
}
else
{
return "Error al obtener la letra de la canción.";
}
}
}
catch (Exception ex)
{
return $"Error al obtener la letra de la canción: {ex.Message}";
}
}
private async void button22_Click(object sender, EventArgs e)
{
string artistName = label2.Text;
string trackName = label1.Text;
string letraCancion = await BuscarLetraCancion(artistName, trackName);
richTextBox1.Text = letraCancion;
}
private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void macTrackBar1_ValueChanged(object sender, decimal value)
{
if (vlcControl.GetCurrentMedia() != null)
{
// Calcula la posición en base al valor del control MacTrackBar
float position = (float)macTrackBar1.Value / macTrackBar1.Maximum;
// Establece la posición del video en VLCControl
vlcControl.Position = position;
}
}
private void vlcControl_PositionChanged(object sender, Vlc.DotNet.Core.VlcMediaPlayerPositionChangedEventArgs e)
{
// Calcula el valor del control MacTrackBar en base a la posición del video
int trackBarValue = (int)(e.NewPosition * macTrackBar1.Maximum);
// Actualiza la posición del control MacTrackBar
macTrackBar1.Value = trackBarValue;
}
// Declarar una lista para almacenar las rutas de las canciones
private List<string> rutasCanciones = new List<string>();
private void button21_Click(object sender, EventArgs e)
{
string rutaCancion = Canciones.SelectedItem.ToString();
rutasCanciones.Add(rutaCancion);
}
private void btnVerCanciones_Click(object sender, EventArgs e)
{
testdeapp formularioDestino = new testdeapp(rutasCanciones);
formularioDestino.Show();
}
private void MostrarImagenArtista(string nombreArtista)
{
if (artistImages.ContainsKey(nombreArtista))
{
string rutaImagen = artistImages[nombreArtista];
pictureBox3.Image = Image.FromFile(rutaImagen);
}
else
{
// No se encontró una imagen para el artista, puedes mostrar una imagen predeterminada o hacer algo más
pictureBox3.Image = null; // Borra la imagen del PictureBox si no hay una imagen disponible para el artista
}
}
private void vlcControl_Click(object sender, EventArgs e)
{
}
private void pictureBox3_Click(object sender, EventArgs e)
{
}
}
}