aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2024-06-05 01:46:28 +0200
committerMiguel Ángel Moreno <mail@migalmoreno.com>2024-06-05 01:46:28 +0200
commit0a258fce3d55bedec8b3fc981f17559e30b1cbe3 (patch)
tree879f092f579559497d98f3b57ede7b0e85d29eca
parentc7f5e6faad2f2f8c22ad4a04f79c54bf10fe324f (diff)
fix: fix player sources application
-rw-r--r--src/frontend/tubo/components/player.cljs32
-rw-r--r--src/frontend/tubo/player/events.cljs1
-rw-r--r--src/frontend/tubo/stream/views.cljs1
3 files changed, 26 insertions, 8 deletions
diff --git a/src/frontend/tubo/components/player.cljs b/src/frontend/tubo/components/player.cljs
index 11c0674..54aed0d 100644
--- a/src/frontend/tubo/components/player.cljs
+++ b/src/frontend/tubo/components/player.cljs
@@ -7,9 +7,20 @@
["@vidstack/react" :refer (MediaPlayer MediaProvider Poster)]
["@vidstack/react/player/layouts/default" :refer (defaultLayoutIcons DefaultVideoLayout DefaultAudioLayout)]))
-(defn get-player-sources
- [available-streams]
- (map (fn [{:keys [content]}] {:src content :type "video/mp4"}) (reverse available-streams)))
+(defn get-video-player-sources
+ [available-streams service-id]
+ (if available-streams
+ (if (= service-id 3)
+ (map (fn [{:keys [content]}] {:src content :type "video/mp4"}) (reverse available-streams))
+ (->> available-streams
+ (filter #(and (not= (:format %) "WEBMA_OPUS") (not= (:format %) "OPUS") (not= (:format %) "M4A")))
+ (sort-by :bitrate)
+ (#(if (empty? (filter (fn [x] (= (:format x) "MP3")) %))
+ (reverse %)
+ %))
+ (map (fn [{:keys [content]}] {:src content :type "video/mp4"}))
+ first))
+ []))
(defn video-player
[stream !player]
@@ -18,11 +29,11 @@
(r/create-class
{:component-will-unmount #(rf/dispatch [:main-player/ready false])
:reagent-render
- (fn [{:keys [name video-streams audio-streams thumbnail-url]} !player]
+ (fn [{:keys [name video-streams audio-streams thumbnail-url service-id]} !player]
(let [show-main-player? @(rf/subscribe [:main-player/show])]
[:> MediaPlayer
{:title name
- :src (get-player-sources (into video-streams audio-streams))
+ :src (get-video-player-sources (into video-streams audio-streams) service-id)
:poster thumbnail-url
:class "w-full xl:w-3/5 overflow-hidden"
:playsInline true
@@ -50,6 +61,15 @@
:class :vds-poster}]]
[:> DefaultVideoLayout {:icons defaultLayoutIcons}]]))})))
+(defn get-audio-player-sources
+ [available-streams]
+ (if available-streams
+ (->> available-streams
+ (filter #(not= (:format %) "OPUS"))
+ (map (fn [{:keys [content]}] {:src content :type "video/mp4"}))
+ (sort-by :bitrate))
+ []))
+
(defn audio-player
[stream !player]
(let [!elapsed-time @(rf/subscribe [:elapsed-time])
@@ -62,7 +82,7 @@
{:title name
:class "invisible fixed"
:controls []
- :src (get-player-sources audio-streams)
+ :src (get-audio-player-sources audio-streams)
:viewType "audio"
:ref #(reset! !player %)
:loop (= @(rf/subscribe [:loop-playback]) :stream)
diff --git a/src/frontend/tubo/player/events.cljs b/src/frontend/tubo/player/events.cljs
index c41c290..e32b4aa 100644
--- a/src/frontend/tubo/player/events.cljs
+++ b/src/frontend/tubo/player/events.cljs
@@ -1,6 +1,5 @@
(ns tubo.player.events
(:require
- [tubo.components.player :as player :refer [get-player-sources]]
[tubo.stream.views :as stream]
[tubo.utils :as utils]
[goog.object :as gobj]
diff --git a/src/frontend/tubo/stream/views.cljs b/src/frontend/tubo/stream/views.cljs
index 574fc34..5c855e4 100644
--- a/src/frontend/tubo/stream/views.cljs
+++ b/src/frontend/tubo/stream/views.cljs
@@ -3,7 +3,6 @@
[reagent.core :as r]
[re-frame.core :as rf]
[reitit.frontend.easy :as rfe]
- [tubo.components.player :refer [get-player-sources]]
[tubo.bookmarks.modals :as modals]
[tubo.comments.views :as comments]
[tubo.components.items :as items]