gpt4 book ai didi

c - 在 C 中播放 mp3 文件

转载 作者:太空宇宙 更新时间:2023-11-04 02:45:16 28 4
gpt4 key购买 nike

我想在 Internet 上播放 mp3 文件而不下载它们。因此,我使用 libcurl 将其作为内存中的流获取,如下所示:

static size_t use_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
/* stream is NULL */
/* What to do with the stream of data ? */
}

CURLcode download_file(const char *url, const char *path, curl_progress_callback progress) {
CURL *curl;
CURLcode res = 0;
FILE *fp;
if ((curl = curl_easy_init())) {
if (progress) {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress);
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, use_data);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
}
return res;
}

如何解析内存中的流来播放声音?

最佳答案

恕我直言,最简单的方法是使用轻量级 MP3 解码库。例如,minimp3 完成它的工作并且仅包含 2 个文件。

http://keyj.emphy.de/minimp3

API 非常简单,可以在此处找到使用示例:https://github.com/corporateshark/PortAMP/tree/master/src/Decoders/MP3

关于c - 在 C 中播放 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28114432/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com