Pronounce button: stop if already playing #1002
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request provides a way to stop a long "pronunciation" with a button click or Alt+S shortcut. Such long "pronunciations" are common in Wikipedia - musical compositions, spoken articles, etc. They can be triggered inadvertently or automatically when "Auto-pronounce words ..." options are enabled. See individual commit messages for more details.
I'm not sure if changing the pronounce buttons' tooltip back and forth is worth the amount of code in the third and fourth commits. These two commits are optional and can be removed.
The pronounce button checked state can temporarily get out of sync with the actual audio playback state in case of asynchronous resource downloading errors, as described in the fifth commit message. I don't think that this is a critical issue. The situation can be improved by merging my other pull request #972. See the merge commit message in https://github.com/vedgy/goldendict/tree/wip-pronounce-stop-if-playing-and-from-next-dictionary for details [this is a separate branch that merges my pronounce-button-stop-if-playing branch (on which this pull request is based) and my wip-auto-pronounce-from-next-dictionary branch (on which #972 is based)].
There are 3 old
audioPlayer->stop();
calls inArticleView
member functions. They were briefly discussed in comments to #983. With the changes in this pull request there is a universal reliable way to stop audio playback, so there seems to be little reason to stop it before showing Dictionaries or Preferences windows (this might be marginally useful to avoid long annoying "pronunciation", which can't be stopped while one of these modal windows is open). Stopping playback before loading a new article has some benefit though: it can reduce the delay before the next pronunciation starts, because some audio player implementations may take several hundred milliseconds to stop. This delay reducing is not consistent however: clicking a Back or Forward navigation button does not stop current playback. Overall it is not clear to me whether these stop function calls should be removed or not. Perhaps they should if there is a common use case, for which stopping playback in these situations is undesirable.