Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Crunker.js to ClojureScript Interop Example
;; this is a ClojureScript interop example I put together for a student in
;; the Professional ClojureScript course (
(defn fetch-and-merge-files
"Fetches two mp3 files and merges them using the Crunker.js library.
Returns a JavaScript Promise object."
[file1 file2]
(let [js-crunker (new Crunker)]
(-> js-crunker
(.fetchAudio file1 file2)
(.then (fn [js-buffers]
(.mergeAudio js-crunker js-buffers)))
(.then (fn [js-merged]
(.export js-crunker js-merged "audio/mp3")))
(.then (fn [js-output]
(.download js-crunker (oget js-output "blob"))))
(.catch (fn [js-err]
(.error js/console "Something went wrong:" js-err))))))
;; usage:
(-> (fetch-and-merge-files "/voice.mp3" "/background.mp3")
(.then (fn [result-from-download])))
;; do something with result-from-download here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment