SDL_Mixer再次播放时,从随机位置开始一段时间,然后从头开始
SDL_Mixer when play again, starts from random place for a while then from the beginning
嗨,我正在尝试在这里触发播放多首音乐,这里有一些代码。
Mix_Music *mix_list[MUSIC_COUNT] ;
//init music with SDL
int result = 0;
int flags = MIX_INIT_MP3;
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
printf("Failed to init SDLn");
exit(1);
}
if (flags != (result = Mix_Init(flags))) {
printf("Could not initialize mixer (result: %d).n", result);
printf("Mix_Init: %sn", Mix_GetError());
exit(1);
}
//load music
Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 640);
for (int i = 0 ; i < musiclist.size() ; ++i){
mix_list[i] = Mix_LoadMUS(musiclist[i].c_str());
}
然后在循环中,
for (; ;){
//trigger from here, some code detect if there's a new music need to be played
//play sound here
if (!Mix_PlayingMusic()){
//if not playing just start fresh play
std::cout << "Start Play " << musiclist[markerIds[0]] << std::endl ;
Mix_FadeInMusic(mix_list[markerIds[0]],1,1000) ;
}
else{
//only if change to next music
if (lastDetected != markerIds[0]){
std::cout << "Fading out current" << std::endl ;
//first need to fade out current
while(!Mix_FadeOutMusic(2000) && Mix_PlayingMusic()) {
// wait for any fades to complete
SDL_Delay(100);
}
Mix_HaltMusic() ;
//then start the one
//problem happens here
//there will always be several seconds it plays from the middle somewhere, then plays from the beginning.
Mix_FadeInMusic(mix_list[markerIds[0]],1,4000) ;
}
}
}
我的问题列在代码中,问题是在播放以前播放的音乐时,无论Mix_FadeInMusic ()
还是Mix_PlayMusic()
总是先从随机位置播放音乐几秒钟,然后从头开始。但我所需要的只是顺利地玩。
操作系统: 乌班图 16.04SDL:2.0.4混音器:2.0.1
我自己想的,这实际上是mp3问题。与 Ubuntu 16.04 捆绑在一起的 SDL 库在播放某些 mp3 文件时几乎没有问题。因此,在我将文件转换为OGG并使用int flags = MIX_INIT_OGG;
问题就消失了。
相关文章:
- 如果不初始化结构中的向量,它会自动为空还是具有随机内存位置的值?
- 如何在 3x4 数组中随机 4 个不同的位置
- SDL_Mixer再次播放时,从随机位置开始一段时间,然后从头开始
- 在长字符串(随机位置)中的C char搜索
- 动态分配存储数据在堆中的随机位置中
- C 2D char阵列有时会在随机位置复制数据
- 在圆内的框外的随机位置
- 如何在c++中从txt文件的随机位置读取数据
- 如何在随机位置用特定数量的 1 和 0 填充数组?
- 在随机位置产卵怪物
- 在随机位置生成QPush按钮的计时器
- 最佳的c++方式来随机选择设置位在位集中的位置
- 二进制输出到C++中随机位置的文件
- 初始化随机生成器的最佳位置
- gdb控件跳转到随机位置
- 从随机起始位置开始的螺旋阵列
- 如何将元素添加到二维数组/矩阵的随机位置
- C++程序在随机位置无缘无故地停止
- 从数组中的随机位置复制到另一个数组
- 如何处理随机访问ifstream使用?-位置/偏移量/尺寸问题