【发布时间】:2015-10-28 07:32:44
【问题描述】:
我想在互联网上播放 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;
}
如何解析内存中的流来播放声音?
【问题讨论】:
-
您的问题有很多可能的答案。
-
@iharob:好吧,看来,我没有得到任何答案。
-
是的,因为您必须提出一个具体问题。你的问题很模棱两可。您是否搜索过可以帮助播放 mp3 的库?
-
@iharob:是的,很多。但我想要的比从文件中读取更具体。直接从内存中逐行读取。
-
我认为
ffmpeg的libavcodec可以从内存缓冲区中读取,我只是不记得具体如何,搜索它的文档。
标签: c mp3 libcurl audio-player