Playing sounds with C++?

删除回忆录丶 提交于 2019-12-03 13:50:42

问题


How would i make it so in my program there is a button when that button is clicked i want it to play a .wma file without opening and media player?


回答1:


The C++ standard does not include this functionality. That means it depends on what your system offers.

For Windows, you can try something like PlaySound.

However, you best bet is to use a pre-existing library, like:

  • OpenAL
  • BASS
  • FMOD
  • SDL's: Sound.

Searching for C++ Sound Library brings up a lot of information.

Also, check out these three other SO topics:

  • What Is The Best C++ Sound API For Windows?
  • How to play MP3 files in C?
  • Learning to work with audio in C++



回答2:


Although the above answer mentions it (and everything else, it doesn't give any recommendations so...), FMOD is the king of C++ sound (the most used) and works great so I'd recommend FMOD in particular.




回答3:


Gstreamer is a free, cross-platform multimedia framework written in C (using GObject) that allows encoding/decoding for many types of media, including wma. Very easy to use and well documented.




回答4:


KDE's Phonon is a cross-platform(!) C++ multimedia library. It supports native sound systems as backends. Worth a look if you haven't seen it before, and a simple video player can be written in a mere 83 lines of code.




回答5:


For Windows, in all honesty your best bet is DirectShow. The RenderFile API allows you to play most audio file types with just a few lines of code.

The best part about DirectShow is that it's a part of the Windows platform so you don't need to bundle an external component.



来源:https://stackoverflow.com/questions/789942/playing-sounds-with-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!