FMOD的循环播放

1. 如何实现在两点间循环播放

(1)Sound的创建必须是FMOD_SOFTWARE, 或者FMODE_CREATESTREAM类型

(2)Channel::setMode要使用LOOP相关的枚举

(3)之后当然可以调用 setLoopCount, setLoopPoints的相关接口了

例如:

jint Java_eugen_mymusic_PlayCtrl_playSound
  (JNIEnv *env, jobject thiz, jstring filepath){
	if( !g_pSystem )
		return -1;

	Java_eugen_mymusic_PlayCtrl_stopSound( env, thiz, 0 );

	std::string cFilePath = jstring2str( env, filepath );

	LOG_DEBUG("Begin to play sound: %s", cFilePath.c_str() );

	FMOD::Sound* sound = 0;
	FMOD_RESULT result = g_pSystem ->createSound( cFilePath.c_str(), FMOD_SOFTWARE|FMOD_CREATESTREAM , 0, &sound);
    ERRCHECK(result);
    if( sound == 0 )
    	return -2;
    FMOD::Channel* channel = 0;
    g_pSound = sound;
    result = g_pSystem ->playSound(sound, 0, false, &channel);
    ERRCHECK(result);
    if( !channel ){
    	LOG_DEBUG("Fail to create channel" );
    	return -3;
    }
    g_pCurChannel = channel;
    return 0;
}
void Java_eugen_mymusic_PlayCtrl_setSoundLoopPoint
  (JNIEnv *env, jobject thiz, jint id, jint start, jint end){
	if( !g_pSystem || !g_pSound ){
		return;
	}
	if( g_pCurChannel == 0 ){
		LOG_DEBUG( "Fail to set loop points" );
	}else{
		FMOD_RESULT res = g_pCurChannel ->setMode( FMOD_LOOP_NORMAL );
		ERRCHECK( res );
		g_pCurChannel ->setLoopCount( -1 );
		g_pCurChannel ->setLoopPoints( start, FMOD_TIMEUNIT_MS, end, FMOD_TIMEUNIT_MS );
		g_pCurChannel ->setPosition( (unsigned)start, FMOD_TIMEUNIT_MS );
		g_pCurChannel ->setPaused( false );
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值