【发布时间】:2015-11-16 02:42:40
【问题描述】:
我正在尝试使用 irrKlang 库加载声音,它在播放时效果很好,但我想获得 PlayLength() 和 PlayPosition() 属性,但完成后程序崩溃。我就是这样做的:
#define ResX "res.mod"
irrklang::ISoundEngine* se = irrklang::createIrrKlangDevice();
if( !se->isCurrentlyPlaying( ResX ) ){
irrklang::ISound *s = se->play2D( ResX, false, false, false );
while( s->getPlayPosition() < s->getPlayLength() ) //Do something
}
当我执行s->getPlayPosition() 或s->getPlayLength() 时程序崩溃
我先在这里澄清一下:
我不能使用while( se->isCurrentlyPlaying( ResX ) ),因为有时媒体停止播放时isCurrentlyPlaying() 不会返回0。
【问题讨论】:
-
您不检查 play2D 是否返回有效指针。根据文档
Only returns a pointer to an ISound if the parameters 'track', 'startPaused' or 'enableSoundEffects' have been set to true. Note: if this method returns an ISound as result, you HAVE to call ISound::drop() after you don't need the ISound interface anymore. Otherwise this will cause memory waste. This method also may return 0 altough 'track', 'startPaused' or 'enableSoundEffects' have been set to true, if the sound could not be played.