Skip to content

Commit

Permalink
fix: not being able to seek videos
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Dec 23, 2023
1 parent 55c43ac commit fec657a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,36 @@ class TemplateManager {
* because of old webview codecs in python, and to allow extending the video player.
* To simplify things and deliver a better result,
* we use the webview player, like AnkiMobile does
*
* `file:///` is used to enable seeking the video
*/
fun parseVideos(text: String): String {
fun parseVideos(text: String, mediaDir: String): String {
return SOUND_RE.replace(text) { match ->
val fileName = match.groupValues[1]
val extension = fileName.substringAfterLast(".", "")
if (extension in VIDEO_EXTENSIONS) {
@Suppress("HtmlUnknownAttribute") // controlsList is valid, but marked as invalid in the IDE
@Language("HTML")
val result =
"""<video src="$fileName" controls controlsList="nodownload"></video>"""
"""<video src="file:///$mediaDir/$fileName" controls controlsList="nodownload"></video>"""
result
} else {
match.value
}
}
}

val qtext = parseVideos(applyCustomFilters(partial.qnodes, this, front_side = null))
val mediaDir = col().media.dir
val qtext = parseVideos(
text = applyCustomFilters(partial.qnodes, this, front_side = null),
mediaDir = mediaDir
)
val qout = col().backend.extractAvTags(text = qtext, questionSide = true)
var qoutText = qout.text

val atext = parseVideos(applyCustomFilters(partial.anodes, this, front_side = qout.text))
val atext = parseVideos(
text = applyCustomFilters(partial.anodes, this, front_side = qout.text),
mediaDir = mediaDir
)
val aout = col().backend.extractAvTags(text = atext, questionSide = false)
var aoutText = aout.text

Expand Down

0 comments on commit fec657a

Please sign in to comment.