[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9a67efa: Optionally use use xwidgets to display <video> elements
From: |
Lars Ingebrigtsen |
Subject: |
master 9a67efa: Optionally use use xwidgets to display <video> elements in shr |
Date: |
Tue, 9 Nov 2021 00:19:22 -0500 (EST) |
branch: master
commit 9a67efa11b0fb9add6325cf68f8c0f8c7fcff861
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Optionally use use xwidgets to display <video> elements in shr
* doc/misc/eww.texi (Advanced): Document it.
* lisp/net/shr.el (shr-use-xwidgets-for-media): New user option.
(shr-tag-video): Use xwidgets to display <video> elements.
---
doc/misc/eww.texi | 9 +++++++++
etc/NEWS | 9 ++++++++-
lisp/net/shr.el | 42 ++++++++++++++++++++++++++++++++++++++----
3 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index 5d308ef..95e59d9 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -397,6 +397,15 @@ transformed URL. By default, this variable contains
@code{eww-remove-tracking}, which removes the common @samp{utm_}
trackers from links.
+@cindex video
+@vindex shr-use-xwidgets-for-media
+ If Emacs has been built with xwidget support, EWW can use that to
+display @samp{<video>} elements. However, this support is still
+experimental, and on some systems doesn't work (and even worse) may
+crash your Emacs, so this feature is off by default. If you wish to
+switch it on, set @code{shr-use-xwidgets-for-media} to a
+non-@code{nil} value.
+
@node Command Line
@chapter Command Line Usage
diff --git a/etc/NEWS b/etc/NEWS
index bb25365..c9144a5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -228,7 +228,14 @@ If non-nil, 'C-c C-a' will put attached files at the end
of the message.
*** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition.
It narrows to the current node.
-** eww
+** eww/shr
+
++++
+*** New user option 'shr-use-xwidgets-for-media'.
+If non-nil (and Emacs has been built with support for xwidgets),
+display <video> elements with an xwidget. Note that this is
+experimental, and is known to crash Emacs on some systems, and just
+doesn't work on other systems. Also see etc/PROBLEMS.
+++
*** New user option 'eww-url-transformers'.
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index cb8ee73..295ffdd 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1626,6 +1626,14 @@ url if no type is specified. The value should be a
float in the range 0.0 to
:version "24.4"
:type '(alist :key-type regexp :value-type float))
+(defcustom shr-use-xwidgets-for-media nil
+ "If non-nil, use xwidgets to display video and audio elements.
+This also depends on Emacs being built with xwidgets capability.
+Note that this is experimental, and may lead to instability on
+some platforms."
+ :type 'boolean
+ :version "29.1")
+
(defun shr--get-media-pref (elem)
"Determine the preference for ELEM.
The preference is a float determined from `shr-prefer-media-type'."
@@ -1668,10 +1676,36 @@ The preference is a float determined from
`shr-prefer-media-type'."
(start (point)))
(unless url
(setq url (car (shr--extract-best-source dom))))
- (if (> (length image) 0)
- (shr-indirect-call 'img nil image)
- (shr-insert " [video] "))
- (shr-urlify start (shr-expand-url url))))
+ (if (and shr-use-xwidgets-for-media
+ (fboundp 'make-xwidget))
+ ;; Play the video.
+ (progn
+ (let ((widget (make-xwidget
+ 'webkit
+ "Video"
+ (truncate (* (window-pixel-width) 0.8))
+ (truncate (* (window-pixel-width) 0.8 0.75))))
+ (file (make-temp-file "shr" nil ".html")))
+ (run-at-time 1 nil (lambda ()
+ (ignore-errors
+ (delete-file file))))
+ (insert
+ (propertize
+ " [video] "
+ 'display (list 'xwidget :xwidget widget)))
+ (with-temp-buffer
+ (insert
+ (format
+ "<video autoplay loop muted><source src=%S
type=\"video/mp4\"></source></video>"
+ url))
+ (write-region (point-min) (point-max) file nil 'silent))
+ (xwidget-webkit-goto-uri widget
+ (concat "file://" file))))
+ ;; No xwidgets.
+ (if (> (length image) 0)
+ (shr-indirect-call 'img nil image)
+ (shr-insert " [video] "))
+ (shr-urlify start (shr-expand-url url)))))
(defun shr-tag-audio (dom)
(let ((url (dom-attr dom 'src))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 9a67efa: Optionally use use xwidgets to display <video> elements in shr,
Lars Ingebrigtsen <=