پخش موسیقی با کد نویسی در C#

  1. #region Play WAV
  2. /// <summary>
  3. /// Plays a .wav File with the Option to Repeat.
  4. /// </summary>
  5. /// <param name="Location">The Location to the Sound File.</param>
  6. /// <param name="Repeat">True to Repeat, False to Play Once.</param>
  7. publicstaticvoid PlayWAV(String Location, Boolean Repeat)
  8. {
  9. //Declare player as a new SoundPlayer with SoundLocation as the sound location
  10. System.Media.SoundPlayer player = new System.Media.SoundPlayer(Location);
  11. //If the user has Repeat equal to true
  12. if(Repeat == true)
  13. {
  14. //Play the sound continuously
  15. player.PlayLooping();
  16. }
  17. else
  18. {
  19. //Play the sound once
  20. player.Play();
  21. System.Media.SystemSound sound = System.Media.SystemSounds.Beep;
  22. sound.Play();
  23. }
  24. }
  25.    
  26. #region Play MP3
  27. /// <summary>
  28. /// Plays a .mp3 File.
  29. /// </summary>
  30. /// <param name="Location">The Location to the Sound File.</param>
  31. publicstaticvoid PlayMP3(String Location)
  32. {
  33. music = new Microsoft.DirectX.AudioVideoPlayback.Audio(Location);
  34. music.Play();
  35. }
  36.    
  37. #region Play MIDI
  38. /// <summary>
  39. /// Plays a .mid File.
  40. /// </summary>
  41. /// <param name="Location">The Location to the Sound File.</param>
  42. publicstaticvoid PlayMIDI(String Location)
  43. {
  44. music = new Microsoft.DirectX.AudioVideoPlayback.Audio(Location);
  45. music.Play();
  46. }
  47.    
  48. #region Play Other
  49. /// <summary>
  50. /// Plays any other sound File.
  51. /// </summary>
  52. /// <param name="Location">The Location to the Sound File.</param>
  53. publicstaticvoid PlayOther(String Location)
  54. {
  55. music = new Microsoft.DirectX.AudioVideoPlayback.Audio(Location);
  56. music.Play();
  57. }

 

/ 0 نظر / 237 بازدید