2012-05-09 9 views
0

私はアプリを作成しています。小さな問題に直面しています。私はこのことをしたい... 私はラジオボタンを持っています。今私は、このラジオボタンがクリックされるたびにループで小さな音楽を演奏したい。私は視覚スタジオを使用しています..それのための表現を使用することはできません。私は次のコードを使用してい ...Windows Phone 7で小さなヘルプが必要

public partial class Page3 : PhoneApplicationPage 
    { 

     private SoundEffect s1; 


     public Page3() 
     { 
      InitializeComponent(); 
      GameTimer gameTimer = new GameTimer(); 
      gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(10000); 

      // Call FrameworkDispatcher.Update to update the XNA Framework internals. 
      gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } }; 

      // Start the GameTimer running. 
      gameTimer.Start(); 

      // Prime the pump or we'll get an exception. 
      FrameworkDispatcher.Update(); 

      LoadSound("Views/1.wav", out s1); 


     } 

     private void LoadSound(String SoundFilePath, out SoundEffect Sound) 
     { 
      // For error checking, assume we'll fail to load the file. 
      Sound = null; 

      try 
      { 
       // Holds informations about a file stream. 
       StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative)); 

       // Create the SoundEffect from the Stream 
       Sound = SoundEffect.FromStream(SoundFileInfo.Stream); 
      } 
      catch (NullReferenceException) 
      { 
       // Display an error message 
       MessageBox.Show("Couldn't load sound " + SoundFilePath); 
      } 
     } 


     private void radioButton1_Checked(object sender, RoutedEventArgs e) 
     { 

       try 
       { 
        s1.Play(); 
       } 
       catch (NullReferenceException) 
       { 
        MessageBox.Show("Can't play, s1 is null."); 
       } 
      } 
+0

どのようなエラーが表示されますか? –

答えて

1

これは私が働く音、再生するために使用したコードです:

private void PlaySound() 
{ 
    Stream stream = TitleContainer.OpenStream("Media/Sounds/SomeFile.wav"); 
    SoundEffect effect = SoundEffect.FromStream(stream); 
    FrameworkDispatcher.Update(); 
    effect.Play(); 
} 

をも、サウンドファイルがコンテンツとしてマークされていることを確認してください。

関連する問題