
Reproducir un sonido un determinado numero de veces
Publicado por And (5 intervenciones) el 15/03/2018 03:35:10
Estoy elaborando un proyecto pequeño sobre un reloj con campanadas estilo big ben, Necesito reproducir las campanadas de la hora en punto según la hora ej: si son las 7 se deben reproducir 7 campanadas ¿Cómo haría eso?
Este es todo el código que llevo: Mas abajo hice un posible for para reproducir según la hora, sin embargo solo se reproduce una vez
Este es todo el código que llevo: Mas abajo hice un posible for para reproducir según la hora, sin embargo solo se reproduce una vez
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;
using System.Media;
namespace BigBen
{
public partial class Form1 : Form
{
Int16 cont= 0;
SoundPlayer Player = new SoundPlayer(); //Variable para el reproductor
public Form1()
{
InitializeComponent();
timer1.Enabled = true; //Inicia el cronómetro
}
private void timer1_Tick(object sender, EventArgs e)//Tiempo/Cronómetro
{
DateTime Hora = DateTime.Now; //Coge la hora del sistema
labelHora.Text = Hora.ToString(); //Imprime en tiempo real en un label (se actualiza cada segundo)
if (Hora.Second == 00 && Hora.Minute == 30)//Media hora
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\Andres\Documents\Chimes\BIG_BEN_Chiming_Half_Hour_-_Sound_Effect.wav"); //Carga el archivo correspondiente de audio
player.Play(); //Inicia la reproducción
}
if (Hora.Second == 00 && Hora.Minute == 15)//Cuarto de hora
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\Andres\Documents\Chimes\BIG_BEN_Chiming_Quarter_Hour_-_Sound_Effect.wav");
player.Play();
}
if (Hora.Second == 00 && Hora.Minute == 45)//3 cuartos de hora
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\Andres\Documents\Chimes\BIG_BEN_Chiming_Three_Quarter_Hour_-_Sound_Effect.wav");
player.Play();
}
if (Hora.Second == 36 && Hora.Minute == 59)//Anuncia la hora 24 segundos antes de la hora en punto
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\Andres\Documents\Chimes\BIG_BEN_Hourly_Chiming_Sound.wav");
player.Play();
}
if (Hora.Second == 20 && Hora.Minute == 49)//Hora en punto
{
//Aquí va el código para reproducir el sonido dependiendo de la hora
//Este es un ciclo que supose que determinaría la hora, sin embargo siempre suena una sola vez
cont = Convert.ToInt16(Hora.Hour);
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\Users\Andres\Documents\Chimes\BIG_BEN_Count_Chiming_-_Sound_Effect.wav");
for (int i= 1; i<=4; i++)// 4 es un valor de prueba para ver si se reproduce 4 veces
{
player.Play();
}
}
}
}
}
Valora esta pregunta


0