|
21 | 21 | (defonce progress-timer (atom nil))
|
22 | 22 | (defonce current-player-key (reagent/atom nil))
|
23 | 23 |
|
24 |
| -(defn- get-player-key |
| 24 | +(defn get-player-key |
25 | 25 | [message-id in-pinned-view?]
|
26 | 26 | (str in-pinned-view? message-id))
|
27 | 27 |
|
28 |
| -(defn- destroy-player |
| 28 | +(defn destroy-player |
29 | 29 | [player-key]
|
30 | 30 | (when-let [player (@active-players player-key)]
|
31 | 31 | (audio/destroy-player player)
|
32 | 32 | (swap! active-players dissoc player-key)))
|
33 | 33 |
|
34 |
| -(defn- update-state |
| 34 | +(defn update-state |
35 | 35 | [state new-state]
|
36 | 36 | (when-not (= @state new-state)
|
37 | 37 | (reset! state new-state)))
|
38 | 38 |
|
39 |
| -(defn- seek-player |
| 39 | +(defn seek-player |
40 | 40 | [player-key player-state value on-success]
|
41 | 41 | (when-let [player (@active-players player-key)]
|
42 | 42 | (audio/seek-player
|
|
46 | 46 | #(update-state player-state :error))
|
47 | 47 | (update-state player-state :seeking)))
|
48 | 48 |
|
49 |
| -(defn- download-audio-http |
| 49 | +(defn download-audio-http |
50 | 50 | [base64-uri on-success]
|
51 | 51 | (-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?}))
|
52 | 52 | (.fetch "GET" (str base64-uri))
|
53 | 53 | (.then #(on-success (.base64 ^js %)))
|
54 | 54 | (.catch #(log/error "could not fetch audio " base64-uri))))
|
55 | 55 |
|
56 |
| -(defn- create-player |
| 56 | +(defn create-player |
57 | 57 | [{:keys [progress-ref player-state player-key]} audio-url on-success]
|
58 | 58 | (download-audio-http
|
59 | 59 | audio-url
|
|
75 | 75 | #(update-state player-state :error)))))
|
76 | 76 | (update-state player-state :preparing))
|
77 | 77 |
|
78 |
| -(defn- play-pause-player |
| 78 | +(defn play-pause-player |
79 | 79 | [{:keys [player-key player-state progress-ref message-id audio-duration-ms seeking-audio?
|
80 | 80 | user-interaction?]
|
81 | 81 | :as params}]
|
|
113 | 113 | (reset! progress-timer nil)))
|
114 | 114 | #(update-state player-state :error))
|
115 | 115 | (do
|
| 116 | + (swap! audio-uris assoc player-key audio-uri) |
116 | 117 | (destroy-player player-key)
|
117 | 118 | (create-player params
|
118 | 119 | audio-uri
|
|
126 | 127 | player-state
|
127 | 128 | checked-seek-time
|
128 | 129 | #(play-pause-player params)))
|
129 |
| - (play-pause-player params)))))) |
130 |
| - (swap! audio-uris assoc player-key audio-uri))) |
| 130 | + (play-pause-player params)))))))) |
131 | 131 |
|
132 | 132 | (defn audio-message
|
133 | 133 | [{:keys [audio-duration-ms message-id]}
|
|
168 | 168 | :weight :medium
|
169 | 169 | :size :paragraph-2}
|
170 | 170 | (i18n/label :error-loading-audio)]
|
171 |
| - [rn/view {:style (style/container)} |
| 171 | + [rn/view |
| 172 | + {:accessibility-label :audio-message-container |
| 173 | + :style (style/container)} |
172 | 174 | [rn/touchable-opacity
|
173 |
| - {:on-press #(play-pause-player {:player-key player-key |
174 |
| - :player-state player-state |
175 |
| - :progress-ref progress |
176 |
| - :message-id message-id |
177 |
| - :audio-duration-ms duration |
178 |
| - :seeking-audio? seeking-audio? |
179 |
| - :user-interaction? true}) |
180 |
| - :style (style/play-pause-container)} |
| 175 | + {:accessibility-label :play-pause-audio-message-button |
| 176 | + :on-press #(play-pause-player {:player-key player-key |
| 177 | + :player-state player-state |
| 178 | + :progress-ref progress |
| 179 | + :message-id message-id |
| 180 | + :audio-duration-ms duration |
| 181 | + :seeking-audio? seeking-audio? |
| 182 | + :user-interaction? true}) |
| 183 | + :style (style/play-pause-container)} |
181 | 184 | [quo/icon
|
182 | 185 | (case @player-state
|
183 | 186 | :preparing :i/loading
|
184 | 187 | :playing :i/pause-audio
|
185 | 188 | :i/play-audio)
|
186 |
| - {:size 20 |
187 |
| - :accessibility-label :play-pause-audio-message-button |
188 |
| - :color colors/white}]] |
| 189 | + {:size 20 |
| 190 | + :color colors/white}]] |
189 | 191 | [quo/soundtrack
|
190 | 192 | {:style style/slider-container
|
191 | 193 | :audio-current-time-ms progress
|
|
0 commit comments