【发布时间】:2013-08-26 01:00:11
【问题描述】:
我正在编写一个程序,它不断生成声音效果并将它们输出到 SDL 回调函数中的声音缓冲区。现在我还需要在后台播放 MP3。我该怎么做呢?我需要自己解码 MP3 并与音效混合吗?
如有需要,我可以换一个库。
【问题讨论】:
我正在编写一个程序,它不断生成声音效果并将它们输出到 SDL 回调函数中的声音缓冲区。现在我还需要在后台播放 MP3。我该怎么做呢?我需要自己解码 MP3 并与音效混合吗?
如有需要,我可以换一个库。
【问题讨论】:
你必须创建一个线程来播放你的 MP3,你可以使用“pthread lib”你只需要在你的项目中添加 pthread lib(不需要下载任何东西)
在一个线程中,您的歌曲将在不干扰您的主线程的情况下运行
我用线程给你写一个例子
#include <pthread.h>
void * Play(void * ptr)
{
/*
HERE PLAY your MP3
you can also do a loop inside your thread
*/
return NULL;
}
//in your main for example
int main()
{
//create a thread that play yout song in backround of main
pthread_t thread_play_MP3;
pthread_create(&thread_play_MP3,NULL,Play,NULL);
while(1)
{
// HERE : your main code
}
return 0;
}
【讨论】: