作者:liuyidii | 来源:互联网 | 2023-05-17 20:41
SoinWindows,youcanusethePlaySoundfunctiontoplayanMP3fileinaC++application.Whatwou
So in Windows, you can use the PlaySound
function to play an MP3 file in a C++ application. What would be some similar functions available for use in Mac OS X/Linux? I would also appreciate it if you could link to some sample Hello-World type programs demonstrating this.
因此在Windows中,您可以使用PlaySound功能在C ++应用程序中播放MP3文件。在Mac OS X / Linux中可以使用哪些类似的功能?如果您可以链接到一些示例Hello-World类型的程序,我也将不胜感激。
3 个解决方案
3
Concerning Audio: Linux != Mac, so I will answer both separately.
关于音频:Linux!= Mac,所以我会单独回答。
MacOS uses the core audio framework for low level audio. Building on that there are several higher level APIs. If you just want to play a sound file the AV Foundation Framework is most likely the way to go. Here you find an example to build a simple app for iOS, which can be ported to MacOS easily.
MacOS将核心音频框架用于低级音频。在此基础上,有几个更高级别的API。如果您只想播放声音文件,AV Foundation Framework很可能是最佳选择。在这里,您可以找到为iOS构建简单应用程序的示例,该应用程序可以轻松移植到MacOS。
For Linux the whole situation is quite delicate. There exist many different frameworks and libraries and it very unclear which is low and which is high level, since some of them are emulating the others. Basically there is ALSA and OSS for low level audio. Both of them are crap. Jack is aiming to provide a framework for professional audio but it's not very portable (at least if you are interested in embedded devices). Most Linux OS currently are using PulseAudio as their audio server, which has also a simple API for just playing a single sound and a very difficult API for low level stuff. And then there is the gstreamer library, which is rather portable and has a half way descent API and is especially designed for playing audio & video files and streams, and so probably the way to go on linux.
对于Linux来说,整个情况非常微妙。存在许多不同的框架和库,并且非常不清楚哪个是低的并且是高级的,因为其中一些正在模仿其他的。基本上ALSA和OSS用于低级音频。他们俩都是垃圾。 Jack的目标是提供专业音频的框架,但它不是非常便携(至少如果你对嵌入式设备感兴趣)。目前大多数Linux操作系统都使用PulseAudio作为他们的音频服务器,它还有一个简单的API,只用于播放单个声音,而且是一个非常难以用于低级别的API。然后有gstreamer库,它相当便携,有半路下降API,专门用于播放音频和视频文件和流,所以可能是继续使用linux的方法。
I personally recommend to use PortAudio, which is a library that provides – as the name states – an audio framework which is portable across several operating systems and audio frameworks. PortAudio is also well designed and has a simple but flexible API.
我个人建议使用PortAudio,它是一个提供 - 如名称所示 - 的音频框架,可以跨多个操作系统和音频框架移植。 PortAudio设计精良,具有简单但灵活的API。