How to play sound | C# .NET

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • How to play a sound in C# .NET.
    What is the SoundPlayer Class?
    The SoundPlayer class controls playback of a sound from a .wav file.
    1. Define a new SoundPlayer pointing to your WAV file
    2. Ensure the Wav file is located within the bin\Debug folder or bin\Debug
    etcoreapp folder for console applications
    3. Install the package System.Windows.Extensions and use the System.Media namespace
    4. Tell the SoundPlayer variable to execute the PlaySync(); method
    5. Run your program to play the Wav file

Комментарии • 27

  • @greghanson7047
    @greghanson7047 Год назад +3

    Short, exactly to the point, answers exactly the question asked. Subscribed.

  • @signaller
    @signaller 2 года назад +5

    If you want to loop it without the application freezing under sound.play(); type sound.PlayLooping(); this will loop the song.

  • @gamerletsjonas7442
    @gamerletsjonas7442 6 месяцев назад +2

    Omg thank you Bro

  • @aquacuzaviation2415
    @aquacuzaviation2415 3 года назад +5

    wow i need more like this short and simple, Thanks :D

  • @robertcalhoun1258
    @robertcalhoun1258 3 года назад +2

    you knows what you are talking about and i respect that so i subscribe

  • @phuocsanghuynh2935
    @phuocsanghuynh2935 3 года назад +1

    thank you for your video! i have been finding this video for a long time! from VietNam with love!

    • @Tech_Ez
      @Tech_Ez  3 года назад

      My pleasure friend!

  • @ParaLizzard
    @ParaLizzard Год назад +1

    If you get warning CA1416. Edit your .csproj file with net5.0-windows Also you need to save sound file to net X.0-windows in bin,debug

  • @pfeifenderleidender7320
    @pfeifenderleidender7320 2 года назад +2

    Awesome sauce!🛸

  • @fabulous7ssbu
    @fabulous7ssbu 3 года назад +3

    Thank you! This was really helpful, if its possible, would you be able to demostrate the same thing but instead of playing a wav file open a image file?

  • @grex1202
    @grex1202 3 года назад +5

    When the sound plays, the program stops. I mean, I put lines of codes after the PlaySync(); method and there's only a black screen on the console application. How do I make it play whilst the other line of codes are running?

    • @TheRealLyonic
      @TheRealLyonic 3 года назад +4

      So I had this problem too, and from what I've found all you need to do is replace the 'PlaySync();' line with just 'Play();' , the only downside to this is the music won't loop the program anymore, and the application will end as soon as it runs out of instructions as normal, I'm not sure if there's a way to play the music infinitely and do all the instructions but this is the only fix I've found for now, hope this helps!

    • @signaller
      @signaller 2 года назад +2

      @@TheRealLyonic Under the line type sound.PlayLooping();

    • @TheRealLyonic
      @TheRealLyonic 2 года назад +1

      @@signaller Thanks!

  • @user-bs2yz1gt8x
    @user-bs2yz1gt8x Год назад +1

    Thank you so muchh!!

  • @ADALA2024
    @ADALA2024 Год назад +1

    Thanks ❤❤❤❤❤❤

  • @DarkCloud0000
    @DarkCloud0000 Год назад +1

    thanks man :D

  • @Tistan01
    @Tistan01 2 месяца назад

    Is there a way to stop a sound from playing?

  • @osamamahmoud7539
    @osamamahmoud7539 2 года назад

    Thank you man

  • @marinhoassis1402
    @marinhoassis1402 3 года назад +1

    THANKS !!!!

    • @Tech_Ez
      @Tech_Ez  3 года назад

      WELCOME !!!!

  • @dibbo6975
    @dibbo6975 2 года назад +1

    "System.IO.FileNotFoundException: Verify that there is an audio file in the specified location.'" Also I don't have the netcoreapp folder for some reason. anybody know how to fix?

  • @oggerito2027
    @oggerito2027 Год назад +1

    how to install the package

  • @_.Fl4vio._
    @_.Fl4vio._ Год назад

    How can I change its volume? Does anyone know ???´

  • @Kostyatf
    @Kostyatf 3 года назад

    1:27 music pls?....

    • @Kostyatf
      @Kostyatf 3 года назад

      @@Tech_Ez Thank you!!!))))