FMOD的循环播放

来源:互联网 发布:android记账软件源码 编辑:程序博客网 时间:2024/04/26 05:00

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
原创粉丝点击