mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Allow <audio> to play without user interaction in accordance to autoplay setting v2 (#1539)
Adds back setting Chromium's autoplay policy according to Anki's, this time without globals.
This commit is contained in:
parent
0de24122ad
commit
9becb4c11f
4 changed files with 11 additions and 0 deletions
|
@ -203,6 +203,7 @@ class Previewer(QDialog):
|
||||||
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
|
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
|
||||||
|
|
||||||
if c.autoplay():
|
if c.autoplay():
|
||||||
|
self._web.setPlaybackRequiresGesture(False)
|
||||||
if self._show_both_sides:
|
if self._show_both_sides:
|
||||||
# if we're showing both sides at once, remove any audio
|
# if we're showing both sides at once, remove any audio
|
||||||
# from the answer that's appeared on the question already
|
# from the answer that's appeared on the question already
|
||||||
|
@ -217,6 +218,7 @@ class Previewer(QDialog):
|
||||||
audio = c.answer_av_tags()
|
audio = c.answer_av_tags()
|
||||||
av_player.play_tags(audio)
|
av_player.play_tags(audio)
|
||||||
else:
|
else:
|
||||||
|
self._web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
av_player.clear_queue_and_maybe_interrupt()
|
||||||
|
|
||||||
txt = self.mw.prepare_card_text_for_display(txt)
|
txt = self.mw.prepare_card_text_for_display(txt)
|
||||||
|
|
|
@ -525,12 +525,14 @@ class CardLayout(QDialog):
|
||||||
self.have_autoplayed = True
|
self.have_autoplayed = True
|
||||||
|
|
||||||
if c.autoplay():
|
if c.autoplay():
|
||||||
|
self.preview_web.setPlaybackRequiresGesture(False)
|
||||||
if self.pform.preview_front.isChecked():
|
if self.pform.preview_front.isChecked():
|
||||||
audio = c.question_av_tags()
|
audio = c.question_av_tags()
|
||||||
else:
|
else:
|
||||||
audio = c.answer_av_tags()
|
audio = c.answer_av_tags()
|
||||||
av_player.play_tags(audio)
|
av_player.play_tags(audio)
|
||||||
else:
|
else:
|
||||||
|
self.preview_web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
av_player.clear_queue_and_maybe_interrupt()
|
||||||
|
|
||||||
self.updateCardNames()
|
self.updateCardNames()
|
||||||
|
|
|
@ -320,10 +320,12 @@ class Reviewer:
|
||||||
q = c.question()
|
q = c.question()
|
||||||
# play audio?
|
# play audio?
|
||||||
if c.autoplay():
|
if c.autoplay():
|
||||||
|
self.web.setPlaybackRequiresGesture(False)
|
||||||
sounds = c.question_av_tags()
|
sounds = c.question_av_tags()
|
||||||
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
||||||
av_player.play_tags(sounds)
|
av_player.play_tags(sounds)
|
||||||
else:
|
else:
|
||||||
|
self.web.setPlaybackRequiresGesture(True)
|
||||||
av_player.clear_queue_and_maybe_interrupt()
|
av_player.clear_queue_and_maybe_interrupt()
|
||||||
sounds = []
|
sounds = []
|
||||||
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
gui_hooks.reviewer_will_play_question_sounds(c, sounds)
|
||||||
|
|
|
@ -369,6 +369,11 @@ class AnkiWebView(QWebEngineView):
|
||||||
return factor
|
return factor
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def setPlaybackRequiresGesture(self, value: bool) -> None:
|
||||||
|
self.settings().setAttribute(
|
||||||
|
QWebEngineSettings.WebAttribute.PlaybackRequiresUserGesture, value
|
||||||
|
)
|
||||||
|
|
||||||
def _getQtIntScale(self, screen: QWidget) -> int:
|
def _getQtIntScale(self, screen: QWidget) -> int:
|
||||||
# try to detect if Qt has scaled the screen
|
# try to detect if Qt has scaled the screen
|
||||||
# - qt will round the scale factor to a whole number, so a dpi of 125% = 1x,
|
# - qt will round the scale factor to a whole number, so a dpi of 125% = 1x,
|
||||||
|
|
Loading…
Reference in a new issue