Skip to content

Commit

Permalink
fix: set aspect ratio for youtube video player
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 15, 2024
1 parent 277096d commit 4477dcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/frontend/components/block.css
Original file line number Diff line number Diff line change
Expand Up @@ -1062,3 +1062,8 @@ html.is-mac {
transition: background-color 0.2s cubic-bezier(0, 1, 0, 1);
background-color: var(--ls-secondary-background-color, var(--rx-gray-03));
}

.aspect-video {
width: auto;
aspect-ratio: 16 / 9;
}
16 changes: 7 additions & 9 deletions src/main/frontend/extensions/video/youtube.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
url (if start
(str url "&start=" start)
url)]
[:iframe
[:iframe.aspect-video
{:id (str "youtube-player-" id)
:allow-full-screen "allowfullscreen"
:allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"
Expand Down Expand Up @@ -99,7 +99,6 @@
id (str/replace-first id #"youtube-player-" "")]
(get (get @state/state :youtube/players) id))))


(rum/defc timestamp
[seconds]
[:a.svg-small.youtube-timestamp
Expand All @@ -121,7 +120,6 @@ Remember: You can paste a raw YouTube url as embedded video on mobile."
false)
nil)))


(defn parse-timestamp [timestamp']
(let [reg #"^(?:(\d+):)?([0-5]?\d):([0-5]?\d)$"
reg-number #"^\d+$"
Expand All @@ -145,13 +143,13 @@ Remember: You can paste a raw YouTube url as embedded video on mobile."
(re-matches #"^(?:(\d+):)?([0-5]?\d):([0-5]?\d)$" "123:22:23") ;; => ["123:22:23" "123" "22" "23"]
(re-matches #"^(?:(\d+):)?([0-5]?\d):([0-5]?\d)$" "30:23") ;; => ["30:23" nil "30" "23"]

(parse-timestamp "01:23") ;; => 83
(parse-timestamp "01:23") ;; => 83

(parse-timestamp "01:01:23") ;; => 3683
(parse-timestamp "01:01:23") ;; => 3683

;; seconds->display
;; https://stackoverflow.com/questions/1322732/convert-seconds-to-hh-mm-ss-with-javascript
(seconds->display 129600) ;; => "36:00:00"
(seconds->display 13545) ;; => "03:45:45"
(seconds->display 18) ;; => "00:18"
)
(seconds->display 129600) ;; => "36:00:00"
(seconds->display 13545) ;; => "03:45:45"
(seconds->display 18) ;; => "00:18"
)

0 comments on commit 4477dcf

Please sign in to comment.