System.Media.SoundPlayer
을 인스턴스화했으며 .wav 파일을 재생하려고합니다. 그러나이 제목에서 선택 했으므로 작동하지 않습니다 (소리가 출력되지 않음). Visual Studio에서 C#을 사용하고 콘솔 응용 프로그램을 만들고 있습니다. 2017 Mac. 여기 내 코드입니다 :Visual Studio 2017의 SoundPlayer Mac에서 소리가 출력되지 않습니다.
using System;
using System.Threading;
using System.IO; // Not needed yet
using System.Media;
namespace mathsTestConsoleC
{
public class OutputClass
{
public void PlayMusic()
{
SoundPlayer player = new SoundPlayer
{
SoundLocation = @"/Users/felix/Projects/mathsTestConsoleC/mathsTestConsoleC/backgroundMusic.wav"
};
player.Load();
player.Play();
}
}
}
(필자는 player.Play();
가 포함되어 있기 때문에 당신이 반드시 player.Load();
를 사용할 필요가 없습니다 것을 알고 있습니다.)
이 중 하나가 작동하지 않습니다
public void PlayMusic()
{
SoundPlayer player = new SoundPlayer
{
SoundLocation = "/Users/felix/Projects/mathsTestConsoleC/mathsTestConsoleC/backgroundMusic.wav"
};
player.Load();
Thread.Sleep(500);
if (player.IsLoadCompleted == true)
{
player.Play();
}
else if (player.IsLoadCompleted == false)
{
Console.WriteLine("player.IsLoadCompleted == false");
}
else
{
Console.WriteLine("player.IsLoadCompleted == not set");
}
}
PlayMusic()
에 전화하면 내 응용 프로그램에서 내가 준 .wav 파일을 재생하지 못합니다.
도와 드리겠습니다.
감사합니다. 잘 작동합니다. –