mirror of
https://github.com/ankitects/anki.git
synced 2026-09-10 06:20:47 -04:00
## Linked issue (required)
Closes #5321
## Summary / motivation (required)
In the old Qt-based editor, attaching an audio file (paperclip button or
the mic recording button) played the file immediately, before the card
was saved. This was handled by `Editor.fnameToLink()` in
`qt/aqt/editor.py`, which called `av_player.play_file_with_caller()`
right after building the `[sound:...]` tag.
That method was removed in 4dd402334 ("Remove legacy editor code") once
the editor moved to the Svelte/TS implementation. Its replacement,
`filenameToLink()` in
`ts/routes/editor/rich-text-input/data-transfer.ts`, only builds the
`[sound:...]` string and never carried the playback call forward. So
today, attaching audio inserts the tag silently and you only hear it
after saving and reopening the card (or opening the Cards preview).
This restores the immediate playback, using the same `av_player`
mechanism the rest of the app uses (so it respects the configured audio
backend/volume), by:
- Adding a `PlayFile` RPC to `FrontendService` in `frontend.proto`,
following the same pattern as the existing Python-only
`RecordAudio`/`OpenMedia` RPCs (no Rust implementation needed,
`FrontendService` is filtered out of Rust codegen in
`rslib/rust_interface.rs`).
- Implementing `play_file()` in `qt/aqt/mediasrv.py`. It resolves the
path relative to the media folder the same way
`open_media`/`show_in_media_folder` do, then plays it on the main
thread. When the active window is the editor, it uses
`av_player.play_file_with_caller(path, window.editor.editorMode)`
instead of a plain `play_file()`, the same pattern already used by
`open_cards_dialog`/`open_fields_dialog` in the same file. This ties
playback to `Editor.cleanup()`'s existing
`av_player.stop_and_clear_queue_if_caller(self.editorMode)` call, so the
sound is stopped if the editor closes mid-playback.
- Calling the new `playFile()` binding from `attachPath()` in
`TemplateButtons.svelte` right after the media is inserted, only when
the attached file is audio (added an `isAudio()` helper next to
`filenameToLink()`, reusing the existing `audioSuffixes` list).
## Steps to reproduce (required, use N/A if not applicable)
1. Open the Add or Edit dialog for a note.
2. Click the paperclip (attach) button in the field toolbar.
3. Pick an audio file.
4. Notice nothing plays. The `[sound:...]` tag is inserted silently, and
you only hear the audio after saving/reviewing or opening the Cards
preview.
## How to test (required)
### Checklist (minimum)
- [x] I ran `./ninja check` or an equivalent relevant check locally.
- [x] I added or updated tests when the change is non-trivial or
behavior changed.
### Details
Ran `just check` locally, everything passed, including a new vitest
covering `isAudio()` in `data-transfer.test.ts`. Manually verified in
`just run`: opened Add dialog, attached an audio file via the paperclip
button and it plays as soon as it's inserted into the field, before
saving. Also tested the mic recording button (F5), which goes through
the same `attachPath()` function; recording and playback both work as
expected.
## Before / after behavior (optional)
Before: attaching audio via the paperclip inserts the `[sound:...]` tag
silently.
After: the audio plays immediately after being inserted, matching the
old Qt editor's behavior.
## Risk / compatibility / migration (optional)
Low risk. New RPC is additive (no changes to existing `FrontendService`
methods), and playback only triggers for files already classified as
audio/video by the existing suffix list used elsewhere in the same file.
## UI evidence (required for visual changes; otherwise N/A)
N/A, behavior-only change (audio playback), nothing visual to show.
## Scope
- [x] This PR is focused on one change (no unrelated edits).
332 lines
14 KiB
Plaintext
332 lines
14 KiB
Plaintext
If you have made changes to Anki's AGPL code, you are welcome to distribute
|
|
the changed code under the AGPL license.
|
|
|
|
If you would like to contribute your code back to the official release, we ask
|
|
that you license your contributions under the BSD 3 clause license. Portions
|
|
of the code are also used in AnkiWeb and AnkiMobile, and accepting
|
|
contributions under an AGPL license would mean we could no longer use the code
|
|
we have written in those projects.
|
|
|
|
In your first pull request, please add your name below. By adding your name to
|
|
this file, you assert that any code you contribute to the Anki project is
|
|
licensed under the BSD 3 clause license. If any pull request you make contains
|
|
code that you don't own the copyright to, you agree to make that clear when
|
|
submitting the request.
|
|
|
|
When submitting a pull request, GitHub Actions will check that the Git email you
|
|
are submitting from matches the one you used to edit this file. A common issue
|
|
is adding yourself to this file using the username on your computer, but then
|
|
using GitHub to rebase or edit a pull request online. This will result in your
|
|
Git email becoming something like user@noreply.github.com. To prevent the
|
|
automatic check from failing, you can edit this file again using GitHub's online
|
|
editor, making a trivial edit like adding a space after your name, and then pull
|
|
requests will work regardless of whether you create them using your computer or
|
|
GitHub's online interface.
|
|
|
|
For users who previously confirmed the license of their contributions on the
|
|
support site, it would be great if you could add your name below as well.
|
|
|
|
********************
|
|
|
|
AMBOSS MD Inc. <https://www.amboss.com/>
|
|
Aristotelis P. <https://glutanimate.com/contact>
|
|
Erez Volk <erez.volk@gmail.com>
|
|
zjosua <zjosua@hotmail.com>
|
|
Yngve Hoiseth <yngve@hoiseth.net>
|
|
Arthur Milchior <arthur@milchior.fr>
|
|
Ijgnd
|
|
Yoonchae Lee <bluegreenmagick@gmail.com>
|
|
Evandro Coan <github.com/evandrocoan>
|
|
Alan Du <alanhdu@gmail.com>
|
|
Yuchen Lei <lyc@xuming.studio>
|
|
Henry Tang <hktang@ualberta.ca>
|
|
Simone Gaiarin <simgunz@gmail.com>
|
|
Rai (Michal Pokorny) <agentydragon@gmail.com>
|
|
Zeno Gantner <zeno.gantner@gmail.com>
|
|
Henrik Giesel <hengiesel@gmail.com>
|
|
Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
|
|
Sander Santema <github.com/sandersantema/>
|
|
Thomas Brownback <https://github.com/brownbat/>
|
|
Andrew Gaul <andrew@gaul.org>
|
|
kenden
|
|
Emil Hamrin <github.com/e-hamrin>
|
|
Nickolay Yudin <kelciour@gmail.com>
|
|
neitrinoweb <github.com/neitrinoweb/>
|
|
Andreas Reis <github.com/nwwt>
|
|
Matt Krump <github.com/mkrump>
|
|
Alexander Presnyakov <flagist0@gmail.com>
|
|
Abdo <github.com/abdnh>
|
|
aplaice <plaice.adam+github@gmail.com>
|
|
phwoo <github.com/phwoo>
|
|
Soren Bjornstad <anki@sorenbjornstad.com>
|
|
Aleksa Sarai <cyphar@cyphar.com>
|
|
Jakub Kaczmarzyk <jakub.kaczmarzyk@gmail.com>
|
|
Akshara Balachandra <akshara.bala.18@gmail.com>
|
|
lukkea <github.com/lukkea/>
|
|
David Allison <davidallisongithub@gmail.com>
|
|
David Allison <62114487+david-allison@users.noreply.github.com>
|
|
Tsung-Han Yu <johan456789@gmail.com>
|
|
Piotr Kubowicz <piotr.kubowicz@gmail.com>
|
|
RumovZ <gp5glkw78@relay.firefox.com>
|
|
Cecini <github.com/cecini>
|
|
Krish Shah <github.com/k12ish>
|
|
ianki <iankigit@gmail.com>
|
|
rye761 <ryebread761@gmail.com>
|
|
Guillem Palau Salvà <guillempalausalva@gmail.com>
|
|
Meredith Derecho <meredithderecho@gmail.com>
|
|
Daniel Wallgren <github.com/wallgrenen>
|
|
Kerrick Staley <kerrick@kerrickstaley.com>
|
|
Maksim Abramchuk <maximabramchuck@gmail.com>
|
|
Benjamin Kulnik <benjamin.kulnik@student.tuwien.ac.at>
|
|
Shaun Ren <shaun.ren@linux.com>
|
|
Ryan Greenblatt <greenblattryan@gmail.com>
|
|
Matthias Metelka <github.com/kleinerpirat>
|
|
qubist-pixel-ux <github.com/qubist-pixel-ux>
|
|
cherryblossom <github.com/cherryblossom000>
|
|
Hikaru Yoshiga <github.com/hikaru-y/>
|
|
Thore Tyborski <github.com/ThoreBor>
|
|
Alexander Giorev <alex.giorev@gmail.com>
|
|
Ren Tatsumoto <tatsu@autistici.org>
|
|
lolilolicon <lolilolicon@gmail.com>
|
|
Gesa Stupperich <gesa.stupperich@gmail.com>
|
|
git9527 <github.com/git9527>
|
|
Vova Selin <vselin12@gmail.com>
|
|
qxo <49526356@qq.com>
|
|
Spooghetti420 <github.com/spooghetti420>
|
|
Danish Prakash <github.com/danishprakash>
|
|
Araceli Yanez <github.com/aracelix>
|
|
Sam Bradshaw <samjr.bradshaw@gmail.com>
|
|
gnnoh <gerongfenh@gmail.com>
|
|
Sachin Govind <sachin.govind.too@gmail.com>
|
|
Bruce Harris <github.com/bruceharris>
|
|
Patric Cunha <patricc@agap2.pt>
|
|
Brayan Oliveira <69634269+BrayanDSO@users.noreply.github.com>
|
|
Luka Warren <github.com/lukawarren>
|
|
wisherhxl <wisherhxl@gmail.com>
|
|
dobefore <1432338032@qq.com>
|
|
Bart Louwers <bart.git@emeel.net>
|
|
Sam Penny <github.com/sam1penny>
|
|
Yutsuten <mateus.etto@gmail.com>
|
|
Zoom <zoomrmc+git@gmail.com>
|
|
TRIAEIOU <github.com/TRIAEIOU>
|
|
Stefan Kangas <stefankangas@gmail.com>
|
|
Fabricio Duarte <fabricio.duarte.jr@gmail.com>
|
|
Mani <github.com/krmanik>
|
|
Kaben Nanlohy <kaben.nanlohy@gmail.com>
|
|
Tobias Predel <tobias.predel@gmail.com>
|
|
Daniel Tang <danielzgtg.opensource@gmail.com>
|
|
Jack Pearson <github.com/jrpear>
|
|
yellowjello <github.com/yellowjello>
|
|
Ingemar Berg <github.com/ingemarberg>
|
|
Ben Kerman <ben@kermanic.org>
|
|
Euan Kemp <euank@euank.com>
|
|
Kieran Black <kieranlblack@gmail.com>
|
|
XeR <github.com/XeR>
|
|
mgrottenthaler <github.com/mgrottenthaler>
|
|
Austin Siew <github.com/Aquafina-water-bottle>
|
|
Joel Koen <mail@joelkoen.com>
|
|
Christopher Woggon <christopher.woggon@gmail.com>
|
|
Kavel Rao <github.com/kavelrao>
|
|
Ben Yip <github.com/bennyyip>
|
|
mmjang <752515918@qq.com>
|
|
shunlog <github.com/shunlog>
|
|
3ter <github.com/3ter>
|
|
Derek Dang <github.com/derekdang/>
|
|
Luc Mcgrady <github.com/Luc-Mcgrady>
|
|
Kehinde Adeleke <adelekekehinde06@gmail.com>
|
|
Marko Juhanne <github.com/mjuhanne>
|
|
Gabriel Heinatz <anorot@gmail.com>
|
|
Monty Evans <montyevans@gmail.com>
|
|
Nil Admirari <https://github.com/nihil-admirari>
|
|
Michael Winkworth <github.com/SteelColossus>
|
|
Mateusz Wojewoda <kawa1.11@o2.pl>
|
|
Jarrett Ye <jarrett.ye@outlook.com>
|
|
Sam Waechter <github.com/swektr>
|
|
Michael Eliachevitch <m.eliachevitch@posteo.de>
|
|
Carlo Quick <https://github.com/CarloQuick>
|
|
Dominique Martinet <asmadeus@codewreck.org>
|
|
chandraiyengar <github.com/chandraiyengar>
|
|
user1823 <92206575+user1823@users.noreply.github.com>
|
|
Gustaf Carefall <https://github.com/Gustaf-C>
|
|
virinci <github.com/virinci>
|
|
snowtimeglass <snowtimeglass@gmail.com>
|
|
brishtibheja <136738526+brishtibheja@users.noreply.github.com>
|
|
Ben Olson <github.com/grepgrok>
|
|
Akash Reddy <akashreddy2003@gmail.com>
|
|
Lucio Sauer <watermanpaint@posteo.net>
|
|
Gustavo Sales <gustavosmendes14@gmail.com>
|
|
Shawn M Moore <https://github.com/sartak>
|
|
Marko Sisovic <msisovic13@gmail.com>
|
|
Viktor Ricci <ricci@primateer.de>
|
|
Harvey Randall <harveyrandall2001@gmail.com>
|
|
Pedro Lameiras <pedrolameiras@tecnico.ulisboa.pt>
|
|
Kai Knoblich <kai@FreeBSD.org>
|
|
Lucas Scharenbroch <lucasscharenbroch@gmail.com>
|
|
Antonio Cavallo <a.cavallo@cavallinux.eu>
|
|
Han Yeong-woo <han@yeongwoo.dev>
|
|
Jean Khawand <jk@jeankhawand.com>
|
|
Pedro Schreiber <schreiber.mmb@gmail.com>
|
|
Foxy_null <https://github.com/Foxy-null>
|
|
Arbyste <arbyste@outlook.com>
|
|
Vasll <github.com/vasll>
|
|
laalsaas <laalsaas@systemli.org>
|
|
ijqq <ijqq@protonmail.ch>
|
|
AntoineQ1 <https://github.com/AntoineQ1>
|
|
jthulhu <https://github.com/jthulhu>
|
|
Escape0707 <tothesong@gmail.com>
|
|
Loudwig <https://github.com/Loudwig>
|
|
Wu Yi-Wei <https://github.com/Ianwu0812>
|
|
RRomeroJr <117.rromero@gmail.com>
|
|
Xidorn Quan <me@upsuper.org>
|
|
Alexander Bocken <alexander@bocken.org>
|
|
James Elmore <email@jameselmore.org>
|
|
Ian Samir Yep Manzano <https://github.com/isym444>
|
|
David Culley <6276049+davidculley@users.noreply.github.com>
|
|
Rastislav Kish <rastislav.kish@protonmail.com>
|
|
jake <jake@sharnoth.com>
|
|
Expertium <https://github.com/Expertium>
|
|
Christian Donat <https://github.com/cdonat2>
|
|
Asuka Minato <https://asukaminato.eu.org>
|
|
Dillon Baldwin <https://github.com/DillBal>
|
|
Voczi <https://github.com/voczi>
|
|
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
|
|
Themis Demetriades <themis100@outlook.com>
|
|
Luke Bartholomew <lukesbart@icloud.com>
|
|
Gregory Abrasaldo <degeemon@gmail.com>
|
|
Taylor Obyen <162023405+taylorobyen@users.noreply.github.com>
|
|
Kris Cherven <krischerven@gmail.com>
|
|
twwn <github.com/twwn>
|
|
Cy Pokhrel <cy@cy7.sh>
|
|
Park Hyunwoo <phu54321@naver.com>
|
|
Tomas Fabrizio Orsi <torsi@fi.uba.ar>
|
|
Dongjin Ouyang <1113117424@qq.com>
|
|
Sawan Sunar <sawansunar24072002@gmail.com>
|
|
hideo aoyama <https://github.com/boukendesho>
|
|
Ross Brown <rbrownwsws@googlemail.com>
|
|
🦙 <gh@siid.sh>
|
|
Lukas Sommer <sommerluk@gmail.com>
|
|
Luca Auer <lolle2000.la@gmail.com>
|
|
Niclas Heinz <nheinz@hpost.net>
|
|
Omar Kohl <omarkohl@posteo.net>
|
|
David Elizalde <david.elizalde.r.a@gmail.com>
|
|
beyondcompute <beyondcompute@gmail.com>
|
|
Yuki <https://github.com/YukiNagat0>
|
|
wackbyte <wackbyte@protonmail.com>
|
|
GithubAnon0000 <GithubAnon0000@users.noreply.github.com>
|
|
Mike Hardy <github@mikehardy.net>
|
|
Danika_Dakika <https://github.com/Danika-Dakika>
|
|
Mumtaz Hajjo Alrifai <mumtazrifai@protonmail.com>
|
|
Thomas Graves <fate@hey.com>
|
|
Jakub Fidler <jakub.fidler@protonmail.com>
|
|
Valerie Enfys <val@unidentified.systems>
|
|
Julien Chol <https://github.com/chel-ou>
|
|
ikkz <ylei.mk@gmail.com>
|
|
derivativeoflog7 <https://github.com/derivativeoflog7>
|
|
rreemmii-dev <https://github.com/rreemmii-dev>
|
|
babofitos <https://github.com/babofitos>
|
|
Jonathan Schoreels <https://github.com/JSchoreels>
|
|
JL710
|
|
Matt Brubeck <mbrubeck@limpet.net>
|
|
Yaoliang Chen <yaoliang.ch@gmail.com>
|
|
KolbyML <https://github.com/KolbyML>
|
|
Adnane Taghi <dev@soleuniverse.me>
|
|
Spiritual Father <https://github.com/spiritualfather>
|
|
Emmanuel Ferdman <https://github.com/emmanuel-ferdman>
|
|
Sunong2008 <https://github.com/Sunrongguo2008>
|
|
Marvin Kopf <marvinkopf@outlook.com>
|
|
Kevin Nakamura <grinkers@grinkers.net>
|
|
Bradley Szoke <bradleyszoke@gmail.com>
|
|
jcznk <https://github.com/jcznk>
|
|
Thomas Rixen <thomas.rixen@student.uclouvain.be>
|
|
Siyuan Mattuwu Yan <syan4@ualberta.ca>
|
|
Lee Doughty <32392044+leedoughty@users.noreply.github.com>
|
|
memchr <memchr@proton.me>
|
|
Max Romanowski <maxr777@proton.me>
|
|
Aldlss <ayaldlss@gmail.com>
|
|
Hanna Nilsén <hanni614@student.liu.se>
|
|
Elias Johansson Lara <elias.johanssonlara@gmail.com>
|
|
Toby Penner <tobypenner01@gmail.com>
|
|
Danilo Spillebeen <spillebeendanilo@gmail.com>
|
|
Matbe766 <matildabergstrom01@gmail.com>
|
|
Amanda Sternberg <mandis.sternberg@gmail.com>
|
|
arold0 <arold0@icloud.com>
|
|
nav1s <nav1s@proton.me>
|
|
Ranjit Odedra <ranjitodedra.dev@gmail.com>
|
|
Eltaurus <https://github.com/Eltaurus-Lt>
|
|
jariji
|
|
Francisco Esteva <fr.esteva@duocuc.cl>
|
|
Daniela Silva Rocha <daniela.silvarocha@outlook.com>
|
|
MoamenAbdelsattar <68331166+MoamenAbdelsattar@users.noreply.github.com>
|
|
Junia Mannervik <junia.mannervik@gmail.com>
|
|
Emma Plante <emmaplante04@gmail.com>
|
|
SelfishPig <https://github.com/SelfishPig>
|
|
Miguel Gazquez <miguel.gazquez82@gmail.com>
|
|
defkorean <https://github.com/defkorean>
|
|
Michael Lappas <https://github.com/michaellappas>
|
|
Brett Schwartz <brettschwartz871@gmail.com>
|
|
Lovro Boban <lovro.boban@hotmail.com>
|
|
Yuuki Gabriele Patriarca <yuukigpatriarca@gmail.com>
|
|
SecretX <https://github.com/SecretX33>
|
|
Tim Arnold <tim-arnold@outlook.de>
|
|
CYPHER0041 <48846390+CYPHER0041@users.noreply.github.com>
|
|
Oli <https://github.com/oliolioli>
|
|
DaedalusIndigo <260538003+DaedalusIndigo@users.noreply.github.com>
|
|
Daniel Pechersky <danny.pechersky@gmail.com>
|
|
fernandolins <1887601+fernandolins@users.noreply.github.com>
|
|
Helmut Carter <https://github.com/helmutcarter>
|
|
barisayyildiz <99ayyldzbaris99@gmail.com>
|
|
Christos Longros <chris.longros@gmail.com>
|
|
Maskady <florent.tout@gmail.com>
|
|
Jeremy Fleischman <jeremyfleischman@gmail.com>
|
|
Marcus Lo <https://github.com/marcusl07>
|
|
Jeremy Fleischman <me@jfly.fyi>
|
|
Tim Gatzke <post@tim-gatzke.de>
|
|
Chirag Jagga <chiragjagga26@gmail.com>
|
|
Tim Gatzke <post@tim-gatzke.de>
|
|
David Sauerwein <david@sauerwein.xyz>
|
|
roostwp07 <https://github.com/roostwp07>
|
|
Konstantin Tutsch <mail@konstantintutsch.com>
|
|
RedPine404 <https://github.com/RedPine404>
|
|
krMaynard <55507135+krMaynard@users.noreply.github.com>
|
|
Niko Savola <nikomsavola@gmail.com>
|
|
iDavi <odavi20527@gmail.com>
|
|
Ian E <ian@ankihub.net>
|
|
Qaisar Sulaiman <qaisarsulaiman101@gmail.com>
|
|
Ashish Yadav <48384865+criticalAY@users.noreply.github.com>
|
|
Timothy Lee <timothyl@berkeley.edu>
|
|
DespicableGoose <68354378+DespicableGoose@users.noreply.github.com>
|
|
Han Lua <72375847+xiaohan484@users.noreply.github.com>
|
|
Andreas U. Schmidhauser <github.com/schmidhauser>
|
|
Peter Szilvasi <peti.szilvasi95@gmail.com>
|
|
JaksonSouza <jaksonsouza.dev@gmail.com>
|
|
********************
|
|
|
|
The text of the 3 clause BSD license follows:
|
|
|
|
Contributions copyright the above contributors, 2010-Present.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation
|
|
and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors
|
|
may be used to endorse or promote products derived from this software without
|
|
specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|