# After Closing and Stopping Sound, FMOD Fails to Play Audio When Quickly Reinitializing

**URL:** <https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026>\
**Category:** FMOD Engine\
**Tags:** android, cpp\
**Created:** [March 26, 2023, 11:13pm UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026 "2023-03-26T23:13:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tienthuan05082002](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tienthuan05082002](https://qa.fmod.com/u/tienthuan05082002)\
**Post date:** [March 26, 2023, 11:13pm UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026/1 "2023-03-26T23:13:56Z")

</div>

I’ve encountered an issue when working with FMOD, a widely used sound system library, where no sound is being played by the system after closing and stopping the sound and quickly reinitializing FMOD. The problem persists despite the absence of any errors during the initialization process and sound playback.

Here’s a snippet of the code I’ve been working with:

```auto
JNIEnv *mEnv = env;
int code = 0;
code = System_Create(&system_);
LOGI("playAiSound-%s-%d", "System_Create", code)
bool isPlaying = true;
jclass cls;
jmethodID methodid;
const char *path_cstr = mEnv->GetStringUTFChars(path, nullptr);
LOGI("playAiSound-%s", path_cstr)
try {
    cls = (env)->FindClass("dev/keego/voice/fmodsound/bridge/SoundPlayUtil");
    methodid = (env)->GetStaticMethodID(cls, "onInitSound", "()V");
    (env)->CallStaticVoidMethod(cls, methodid);
    system_->init(32, FMOD_INIT_NORMAL, nullptr);
    // Create sound
    code = system_->createSound(path_cstr, FMOD_LOOP_NORMAL, nullptr, &sound_);
    LOGI("playAiSound-%s-%d", "createSound", code)
    if (path != nullptr) {
        mEnv->ReleaseStringUTFChars(path, path_cstr);
    }
    code = system_->playSound(sound_, nullptr, false, &channel_);
    LOGI("playAiSound-%s-%d", "playSound", code)
    methodid = (env)->GetStaticMethodID(cls, "onPlaySound", "()V");
    (env)->CallStaticVoidMethod(cls, methodid);
    unsigned int length = 0;
    sound_->getLength(&length, FMOD_TIMEUNIT_MS);
    LOGI("playAiSound-%d", length)

} catch (...) {
    LOGE("playAiSound-%s", "play error!")
    code = 1;
    goto end;
}
while (isPlaying) {
    usleep(100);
    channel_->isPlaying(&isPlaying);
}
LOGI("playAiSound-%s", "play over！")
goto end;
end:

code = sound_->release();
LOGI("playAiSound-%s-%d", "release sound！", code);
code = system_->close();
LOGI("playAiSound-%s-%d", "close system！", code);
code = system_->release();
LOGI("playAiSound-%s-%d", "release system！", code);
methodid = (env)->GetStaticMethodID(cls, "onComplete", "()V");
(env)->CallStaticVoidMethod(cls, methodid);
return code;

```

Here’s the logcat:

```auto
2023-03-27 05:57:11.472 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-System_Create-0
2023-03-27 05:57:11.472 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-/storage/emulated/0/Music/VoiceChanger/1679844887938.wav
2023-03-27 05:57:11.522 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-createSound-0
2023-03-27 05:57:11.522 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-playSound-0
2023-03-27 05:57:11.522 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-14293
2023-03-27 05:57:11.586 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-play over！
2023-03-27 05:57:11.586 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-release sound！-0
2023-03-27 05:57:11.598 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-close system！-0
2023-03-27 05:57:11.598 3890-4056 FmodSound dev.keego.voice.changer I playAiSound-release system！-0

```

````auto

Upon closer inspection, my program is getting stuck in the following loop:

```cpp
while (isPlaying) {
    usleep(100);
    channel_->isPlaying(&isPlaying);
}

````

At this point, no sound is being played by the system.As you can see, no errors are detected in FMOD, and I don’t understand where my issue lies. Please help me, and thank you very much.

---

<div class="post-metadata">

**Author:** ![tienthuan05082002](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tienthuan05082002](https://qa.fmod.com/u/tienthuan05082002)\
**Post date:** [March 26, 2023, 11:20pm UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026/2 "2023-03-26T23:20:05Z")

</div>

I have added an additional log at:

```auto
system_->init(32, FMOD_INIT_NORMAL, nullptr);
LOGI("playAiSound-%s-%d", "init", code)

```

However, I still couldn’t detect any errors occurring:

```auto
2023-03-27 06:18:25.639 11203-11355 FmodSound dev.keego.voice.changer I playAiSound-init-0

```

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [March 30, 2023, 3:38am UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026/3 "2023-03-30T03:38:41Z")

</div>

Hi,

What version of FMOD are you using?

How/where are you reinitializing FMOD? Are you restarting the application?

I can see in your log `playAiSound-14293`, would it be possible to change `int code = 0` to `FMOD_RESULT result` and put a breakpoint on line `22` of the code you have provided to see what that error is?

---

<div class="post-metadata">

**Author:** ![tienthuan05082002](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tienthuan05082002](https://qa.fmod.com/u/tienthuan05082002)\
**Post date:** [March 30, 2023, 3:42am UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026/4 "2023-03-30T03:42:27Z")

</div>

thanks! i solved, it has some problems when working with multithreads after release system.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [March 30, 2023, 3:43am UTC](https://qa.fmod.com/t/after-closing-and-stopping-sound-fmod-fails-to-play-audio-when-quickly-reinitializing/20026/5 "2023-03-30T03:43:15Z")

</div>

Hi,

Thanks for sharing the solution!
