Dobrý den. Dělám si takovy drobný prográmek a chtel jsem si ozvučit tlačítka. Vše funguje až na to, že zvuk se přehraje jen poprvé , když kliknu na tlačítko po druhé tak už se zvuk nepřehraje.
Nevíte jaký kus kódu mám změnit popř. přidat ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string _command;
private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
this.OpenPlayer(@"c:\click.wav");
this.Play(false);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void OpenPlayer(string sFileName)
{
_command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isOpen = true;
}
public void Play(bool loop)
{
if (isOpen)
{
_command = "play MediaFile";
if (loop)
_command += " REPEAT";
mciSendString(_command, null, 0, IntPtr.Zero);
}
}
}
}