2012-11-11 3 views
0

안녕하세요. List<SystemSound> 리콜 대상 음악을 만드는 방법은 무엇입니까?리스트를 만드는 방법

나는 이것을 시도,하지만 난 예외 아래 얻을 :

List<System.Media.SystemSound> music = new List<System.Media.SystemSound> 
    { 
     global::Launcher.Properties.Resources.music_quit_1, 
     global::Launcher.Properties.Resources.music_quit_2, 
     global::Launcher.Properties.Resources.music_quit_3, 
     global::Launcher.Properties.Resources.music_quit_4, 
    }; 

"인수 1 :. 에 System.IO.UnmanagedMemoryStream에서 변환 할 수 없습니다 System.Media.SystemSound"

나는 무작위로 음악을 연주하고 그 후에 연주합니다.

+2

어떻게 작동하지 않습니까? 컴파일러 오류가 있습니까? 예외? 정확 해! – Adam

+0

죄송합니다. 내가 그것을 실행하려고하면 "인수 1 : System.IO.UnmanagedMemoryStream에서 System.Media.SystemSound로 변환 할 수 없습니다." – tonykapa89

+0

music_quit_1은 시스템 사운드 또는 다른 사운드입니까? –

답변

1

System.Media.SystemSound이 방법을 사용하지 않는 클래스이 클래스는 단지 시스템 사운드 유형 같은 Asterisk, Beep, Hand, Question 또는 Exclamation를 나타내는 데 사용된다. 시스템 사운드SystemSounds을 통해 재생할 수 있습니다.

SystemSounds.Asterisk.Play(); 

이 예 시스템Asterisk 소리를 재생한다. System.Drawing.Brush.Black을 말할 수는 없으므로 System.Drawing.Brush과 비슷하지만 System.Drawing.Brushes.Black이라고 말할 수 있습니다. System.Drawing.Brush은 새 클래스 System.Drawing.BrushesBlack이라는 이름의 개체를 정의하는 데에만 사용되었습니다. 색은 Black입니다. 새 웨이브 사운드을 재생하려는 경우 우리는 당신이 사운드 웨이브에서 사운드의 재생을 제어 SoundPlayer의 새로운 클래스를 만들 수 있습니다, 또한 System.Drawing.Brushes

// 
// Summary: 
//  Gets a system-defined System.Drawing.Brush object. 
// 
// Returns: 
//  A System.Drawing.Brush object set to a system-defined color. 
public static Brush Black { get; } 

의 정의에서 볼 수 있습니다 (.wav)을 예

SoundPlayer _SoundPlayer = new SoundPlayer(); //Initializes a new SoundPlayer of name _SoundPlayer 
_SoundPlayer.SoundLocation = @"D:\Resources\International\Greetings.wav"; //Sets the target Wave Sound file to D:\...\Greetings.wav 
_SoundPlayer.Play(); //Plays the target Wave Sound file 

여전히한다면

파일 일반 List을 사용하고 싶습니다. 그런 다음, 아마도 다음과 같은 예는

List<string> WaveSoundCollections = new List<string> { @"D:\Resources\International\Greetings.wav", @"D:\Resources\International\Good-Bye.wav" }; //Initializes a new Generic Collection of class List of type string and injecting TWO strings into the Generic Collection 
SoundPlayer NewPlayer = new SoundPlayer(); //Initializes a new SoundPlayer 
if (Client.Start) //Client refers to a particular Class that has Start and End as bool 
{ 
    NewPlayer.SoundLocation = WaveSoundCollections[0]; //Set the SoundLocation of NewPlayer to D:\Resources\International\Greetings.wav 
    NewPlayer.Play(); //Plays the target Wave Sound file 
} 
else if (Client.End) 
{ 
    NewPlayer.SoundLocation = WaveSoundCollections[1]; //Set the SoundLocation of NewPlayer to D:\Resources\International\Good-Bye.wav 
    NewPlayer.Play(); //Plays the target Wave Sound file 
} 

공지 사항 도움이 될 수 있습니다 : SoundPlayer웨이브 사운드 파일을 재생하는 데 사용 입니다. 당신은 다른 미디어 파일을 재생하려는 경우와 같은 .MP3, .MPEG 등이 ... 그런 다음 MediaPlayer의 새로운 클래스를 만들 수 Object Browser에서 가져올 수 있습니다 System.Windows.Media.MediaPlayer를 사용하여 특정 파일을 재생할 수 있습니다 .

string TargetFile = @"D:\File.mp3"; 
MediaPlayer _MediaPlayer = new MediaPlayer(); 
_MediaPlayer.Open(new Uri(TargetFile)); 
_MediaPlayer.Play(); 

중요 : MediaPlayer를 사용하려면 WindowsBase의 새로운 참조를 추가해야합니다.

  • 마우스 오른쪽 단추로 클릭 ... 참조를 추가 솔루션 탐색기에서 참조를을 선택
  • 선택 WindowsBase :

    WindowsBase의 새로운 참조를 추가하려면 다음을 수행하십시오 을 클릭하십시오 OK
  • 방금 추가 한 새 참조 그래서 클라이언트가 초기화

    It's important to set CopyLocal to True in such cases

감사 중에 오류가 발생하지 않습니다 진정한에 이름 로컬 복사 세트의 부울의 그것의 속성이 전자 ,
이 도움이 되었기를 바랍니다 :)

+0

WindowBase를 C# 프로젝트에 포함 시켰지만 미디어 플레이어 개체가 없습니다. @Picrofo EGY –

+0

@MuhammadUmar'System.Windows.Media.MediaPlayer'는 기본적으로 특정 프로젝트로 가져 오지 않습니다. [그것을 사용하려면'Object Browser'를 통해 가져와야합니다.] (http://i.stack.imgur.com/kJpMm.png). 그러나 'WindowsBase'에 대한 참조를 추가하지 않고 사용하려고하면 [this] (http://i.stack.imgur.com/ut80l.png) 오류가 발생합니다. 이것이 WindowsBase가 필요한 이유입니다. 또한 클라이언트가 초기화하는 동안 오류가 발생하지 않도록 참조의 속성을 통해'Copy Local'을'True'로 설정하는 것도 중요합니다. 좋은 하루 되세요 :) –

관련 문제