- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 54
fix: stop() takes too much time #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -108,8 +108,23 @@ extern "C" | |
| /// and comes from the audio thread (so on the web, from a different web worker). | ||
| FFI_PLUGIN_EXPORT void voiceEndedCallback(unsigned int *handle) | ||
| { | ||
| bool isHandleFound; | ||
| if (player != nullptr) | ||
| player->removeHandle(*handle); | ||
| { | ||
| isHandleFound = player->findByHandle(*handle) != nullptr; | ||
| if (isHandleFound) | ||
| player->removeHandle(*handle); | ||
| else | ||
| // If the handle is not found, for sure it is already | ||
| // removed by a previous call to `voiceEndedCallback`. | ||
| // For example triggering a `stop` in a `Future` after the sound is ended or | ||
| // vice versa. | ||
| return; | ||
| } | ||
|  | ||
| // Here the internal flutter_soloud handle, doesn't exist anymore, whether this | ||
| // callback is called directly from `stop`, or whether it is called from an | ||
| // event in `Soloud::stopVoice_internal (unsigned int aVoice)`. | ||
|  | ||
| #ifdef __EMSCRIPTEN__ | ||
| // Calling JavaScript from C/C++ | ||
|  | @@ -121,7 +136,12 @@ extern "C" | |
| // The `dartVoiceEndedCallback` is not set on Web. | ||
| if (dartVoiceEndedCallback == nullptr) | ||
| return; | ||
| // [n] pointer must be deleted on Dart. | ||
| // So, if the handle was already found before (henche the handle is not found), the | ||
| // callback to Dart has been already called. If this is the fist time this handle | ||
| // is found, the callback to Dart must be called. | ||
| if (!isHandleFound) | ||
|         
                  filiph marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| return; | ||
| // [n] pointer must be deleted in Dart. | ||
| unsigned int *n = (unsigned int *)malloc(sizeof(unsigned int *)); | ||
| *n = *handle; | ||
| dartVoiceEndedCallback(n); | ||
|  | @@ -770,10 +790,10 @@ extern "C" | |
| /// [handle] | ||
| FFI_PLUGIN_EXPORT void stop(unsigned int handle) | ||
| { | ||
| if (player.get() == nullptr || !player.get()->isInited() || | ||
| !player.get()->isValidHandle(handle)) | ||
| 
      Comment on lines
    
      -773
     to 
      -774
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, why are we no longer checking whether the handle is valid? Does  Oh wait, we checked whether the handle was not valid? And then we stopped it? Sorry, I'm getting confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the handle validity is managed by the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! | ||
| if (player.get() == nullptr || !player.get()->isInited()) | ||
| return; | ||
| player.get()->stop(handle); | ||
| voiceEndedCallback(&handle); | ||
| } | ||
|  | ||
| /// Stop all handles of the already loaded sound identified by [hash] and dispose it | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -634,7 +634,6 @@ PlayerErrors Player::play( | |
|  | ||
| void Player::stop(unsigned int handle) | ||
| { | ||
| removeHandle(handle); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] I guess I'd like to see it documented (in comments in this file, ideally) who is responsible for removing the handle (e.g. calling  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the handle here is now an error because it is now the  | ||
| soloud.stop(handle); | ||
| } | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.