[code language=”CSharp”]
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
public string Pcommand;
public bool isOpen;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
textBox1.Text = openFileDialog1.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
Pcommand = "open "" + textBox1.Text + "" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = true;
Play(true);
}
private void button3_Click(object sender, EventArgs e)
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = false;
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
public void Play(bool loop)
{
if (isOpen)
{
Pcommand = "play MediaFile";
if (loop)
Pcommand += " REPEAT";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}
} [/code]

benim projemde müzik çalar kullanmam gerekiyor. fakat kodları sürekli karıştırıyorum. bana daha kolay bi yol göstermeniz mümkün mü?
using System.Media;
SoundPlayer cal = new SoundPlayer();
string dizin = Application.StartupPath + “\\song.wav”;
cal.SoundLocation = dizin;
cal.Play();
bu hatayı verior neden
Please be sure a sound file exists at the specified location.
Volkan:
song.wav dosyası belirtilen konumda yok.Yani exe nin çalıştığı yerde. exe nin çalıştığı yer–> bin–debug klasörü.
bin-debug klasöründe var ama hala ayni hata kafayi yicem
volkan :
\\song.wav iafedesini song.wav olarak değiştir.yani \\ sil.
İlginiz İçin Teşekürler Sayafanız çok faydali gelişmemde yardimci oluor
hocam play yok hata veriyor
Murad :
Hata olarak hangi mesajı alıyorsunuz.
Error 1 The type or namespace name ‘Dllimport’ could not be found (are you missing a using directive or an assembly reference?) C:\Users\oğuzhan\Desktop\visuallllll\WindowsFormsApplication5\WindowsFormsApplication5\Form1.cs 14 10 WindowsFormsApplication5
oğuzhan :
Using System.Runtime.InteropServices; isim uzayını eklemeyi deneyin