MFC中使用SDL播放音频没有声音的解决方法
2013-11-10 20:30
651 查看
本文所说的音频是指的纯音频,不包含视频的那种。
在控制台中使用SDL播放音频,一般情况下不会有问题。
但是在MFC中使用SDL播放音频的时候,会出现没有声音的情况。经过长时间探索,没有找到特别好的解决方案,但是有一种方式可以让声音播放出来:那就是让SDL显示图像(视频)时候的那个对话框弹出来,声音就会出现了。
具体的方法可以加载一张图片(比如说BMP),下图所示代码片段为加载BMP图片的代码。
不明白这是为什么,但是程序就可以出声了。
在控制台中使用SDL播放音频,一般情况下不会有问题。
但是在MFC中使用SDL播放音频的时候,会出现没有声音的情况。经过长时间探索,没有找到特别好的解决方案,但是有一种方式可以让声音播放出来:那就是让SDL显示图像(视频)时候的那个对话框弹出来,声音就会出现了。
具体的方法可以加载一张图片(比如说BMP),下图所示代码片段为加载BMP图片的代码。
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); SDL_Surface *image; /* Load the BMP file into a surface */ image = SDL_LoadBMP("background.bmp"); if (image == NULL) { return 0; } /* * Palettized screen modes will have a default palette (a standard * 8*8*4 colour cube), but if the image is palettized as well we can * use that palette for a nicer colour matching */ if (image->format->palette && screen->format->palette) { SDL_SetColors(screen, image->format->palette->colors, 0, image->format->palette->ncolors); } /* Blit onto the screen surface */ if(SDL_BlitSurface(image, NULL, screen, NULL) < 0) fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError()); SDL_UpdateRect(screen, 0, 0, image->w, image->h);
不明白这是为什么,但是程序就可以出声了。
相关文章推荐
- Java小对象的解决之道——对象池(Object Pool)的设计与应用
- MFC中使用SDL播放音频没有声音的解决方法
- linux 汇编程序实例
- MessageBox的常见用法
- 自学java时的笔记(一)
- EL表达式语言
- DIALOG开发中的ALV
- [LeetCode] Best Time to Buy and Sell Stock
- Java中的对象池技术
- CF 136B Ternary Logic
- FZU 2138 && FOJ11月赛G题 容斥
- 死锁活锁饥饿
- C语言打印统计单词长度的直方图<The C Programming Language>课后习题
- __asm__ __volatile__ GCC的内嵌汇编语法 AT&T汇编语言语法(一)
- C++ primer读书笔记——5.12 类型转换
- 新手入门 acm 输入输出练习
- 网页视频插件
- FZU 2135 && FOJ11月赛E题
- oracle学习笔记-1
- HTML文本框 圆角显示 样式设置方法