安装SDL_mixer with smpeg
来源:互联网 发布:mysql批量insert限制 编辑:程序博客网 时间:2024/06/05 10:20
SDL提供了数种控制图像、声音、输出入的函数,让开发者只要用相同或是相似的代码就可以开发
出跨多个平台(Linux、Windows、Mac OS X等)的应用软件。目前SDL多用于开发游戏、模拟器、媒体播放器等多媒体应用领域。
SDL本身只支持WAV, 其他个数可以使用SDL_mixer扩展库
而SDL_mixer 本身也只提供WAV的解码播放功能.其余格式都是封装第三方库来实现的.
其中对于常见的MP3格式, requiring SMPEG or MAD library on system
经过摸索, 成功结合SMPEG, 编译SDL_mixer库, 并播放mp3文件, 下面是过程
1. 安装SDL
官方下载地址: http://www.libsdl.org/centos5下安装比较简单, 一般步骤即可
./configure --prefix=Dirmakemake install
2. 安装SDL_mixer需要的库
SMPEG被SDL_mixer用于对MP3文件解码
下载地址: http://www.libsdl.org/projects/SDL_mixer/该网页提供的相应的smpeg的tar包, 直接下载
安装方法:
./configure --prefix=Dirmake make install
3. 安装SDL_mixer
在安装SDL_mixer时, 需要指定SMPEG的安装路径(上一个步骤中指定的prefix)
SDL_mixer下载地址: http://www.libsdl.org/projects/SDL_mixer/
查看configure文件发现:
--with-sdl-prefix=PFX Prefix where SDL is installed (optional)
--with-smpeg-prefix=PFX Prefix where SMPEG is installed (optional), 找到这个不容易呀:)
因为我的centos5自带了SDL, 不太确定是否必须指定--with-sdl-prefix.
安装
./configure --prefix=Dir --with-smpeg-prefix=smpeg-home-dir --with-sdl-prefix=sdl-home-dirmakemake install
4. 测试
测试代码(摘自网络):
#include <SDL.h> #include <SDL_mixer.h> // //Code irrelevant to the situation // //Code irrelevant to the situation // int musicPlaying = 1; void musicFinished() { musicPlaying = 0; } int main(int argc, char *argv[]) { // Initialize SDL's subsystems if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); exit(1); } int audio_rate = 44100; Uint16 audio_format = AUDIO_S16SYS; int audio_channel = 1; int audio_buffer = 2048; if (Mix_OpenAudio(audio_rate, audio_format, audio_channel, audio_buffer) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } Mix_Music *music; music = Mix_LoadMUS(argv[1]); if (music == NULL) { // This is where the error occurs. fprintf(stderr, "Unable to load mp3 file: %s\n", Mix_GetError()); exit(1); } if (Mix_PlayMusic(music, 0) == -1) { fprintf(stderr, "Unable to play mp3 file: %s\n", Mix_GetError()); exit(1); } musicPlaying = 1; Mix_HookMusicFinished(musicFinished); while (musicPlaying) { // do nothing SDL_Delay(2500); } Mix_HaltMusic(); Mix_FreeMusic(music); Mix_CloseAudio(); atexit(SDL_Quit); return 0; }
编译运行test.c
假设:
SDL 目录为: SDL_HOME
SDL_mixer目录为: SDL_MIXER_HOME
gcc -o test test.c -L${SDL_HOME}/lib -L${SDL_MIXER_HOME}/lib -lSDL -lSDLmain -lSDL_mixer -I${SDL_HOME}/include/SDL -I${SDL_MIXER_HOME}/include/SDL./test test.mp3
如果在运行时遇到找不到SDL_mixer共享库的问题, 可以通过指定LD_LIBRARY_PATH=${SDL_MIXER_HOME}/lib解决
或者在/etc/ld.so.conf.d/下添加SDL.conf
export LD_LIBRARY_PATH=${SDL_MIXER_HOME}/lib#或者在SDL.conf中添加${SDL_MIXER_HOME}/lib
ok, listen~
你的反馈就是博主进步的最大动力
- 安装SDL_mixer with smpeg
- 基于SDL的SDL_mixer音乐播放器
- sdl2.0使用SDL_Mixer播放音乐
- 基于SDL的SDL_mixer库的音乐播放器
- SDL-1.2.13 SDL_mixer-1.2.8 测试程序
- android SDL系列讲解(十三) 播放音乐库 SDL_mixer教程
- 安装TensorFlow with GPU
- Innodb with Memcached –安装
- DiskSim 4.0 with dixtrac 安装
- Ubuntu安装opencv with cuda
- Mac安装Opencv3 --with-all
- mac安装LightGBM with Anaconda
- linux中安装opencv with ffmpeg and with python
- 安装 Qt4.3.3 with Visual Studio 2005
- 安装Windows Server 2008 with Hyper-V
- linux下编译安装Python with Tkinter
- GTK+-2.0 安装手记(with GLIB)
- Start with Mule (1) -- 下载安装
- TabHost详解0
- Android Manifest.xml 结构详解
- 计算该日是该年的第几天
- sgu 133 Border
- v$session SERIAL#字段的含义
- 安装SDL_mixer with smpeg
- sgu 326 最大流 不错的构图。。哦哦类。。。
- 遍历WPF窗体元件的两种方法
- <转载>基础篇、AlarmManager类的作用
- Eclipse中添加MyEclipse插件
- 笔记本创建wifi
- V$SESSION 较详细解释
- ZOJ_1240_IBM Minus One
- 用C语言数组实现位操作(位数组)