2013-03-19 3 views
0

나는 C#에서 사운드를 추가하는 방법을 이미 따르지만 사운드를 재생할 수는 없지만 오류는 아닙니다. 어떻게해야합니까?C에서 백그라운드 사운드를 재생하는 방법 #

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.Media; 

namespace WindowsFormsApplication2 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      SoundPlayer myPlayer = new SoundPlayer(WindowsFormsApplication2.Properties.Resources.sound1); 
      myPlayer.PlayLooping(); 
     } 
    } 
} 
+5

SoundPlayer는 WAV 파일에서만 작동합니다. WAV 파일을로드하려는 파일이 있습니까? – keyboardP

+0

이미 소리가 전혀 들리지 않는다. – user2187491

+1

@user2187491, ***는 WAV 파일인가? *** 알다시피, WAV 파일 형식입니다. –

답변

0

당신이 Form1_Load()이 양식 Load 이벤트에 할당되어 있는지 확인합니다. 나는 당신의 코드를 넣었고, 잘 작동합니다.

이벤트를 할당하려면 다음 이미지를보십시오. enter image description here.

이렇게하면 양식이로드 될 때 Form1_Load()이 호출됩니다.

Error 1 The best overloaded method match for 'System.Media.SoundPlayer.SoundPlayer(string)' has some invalid arguments : 당신이 SoundPlayer에 비 .wav 파일을 통과 할 때 무슨 일이 일어날 지보고 테스트 한 후

, 그것은 오류가 발생합니다.

이렇게하면 코드가 호출되지 않는다고 생각합니다.

+0

친절한 메모 : 일반적으로 대답하기 전에 정확한 문제를 이해하는 것이 좋습니다. 때로는 운이 좋을 수도 있지만 그렇지 않은 경우가 많습니다. –

관련 문제