我想为.wav创建一个声音播放器。文件.wav从.bsctm转换为.exe,名为vgmstream。转换是成功的,但如果我在winforms中调用proccess,它就不起作用。
这里是代码:
private void btn_player_Click(object sender, EventArgs e)
{
try
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
if (!status_player)
{
btn_player.BackgroundImage = Properties.Resources.btn_pause;
if (!File.Exists(((Theme)lbx.SelectedItem).Bgm))
// No exist
{
MessageBox.Show("Bgm not found");
return;
}
else
{
player.SoundLocation = ConvertWAW();
player.Play();
}
else
{
btn_player.BackgroundImage = Properties.Resources.btn_player;
player.Stop();
}
}
catch (System.InvalidOperationException error)
{
MessageBox.Show(error.Message);
}
catch (System.IO.FileNotFoundException error)
{
//Always show this error.
MessageBox.Show(error.Message);
}
finally {
status_player = !status_player;
}
private String ConvertWAW()
{
Process proc = new Process();
proc.StartInfo.FileName = "vgmstream.exe";
if (File.Exists(((Theme)lbx.SelectedItem).Bgm))
{
proc.StartInfo.Arguments = "-o " + @"temp.wav" + @" " + ((Theme)lbx.SelectedItem).Bgm;
// BGM => @"Thems\" + folder_name + @"\bgm.bcstm"
proc.Start();
proc.WaitForExit();
return "temp.wav";
}
return "";
}