question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to play/decode Ogg files on Safari?

See original GitHub issue

We are loading our audio from a url like this:

let audio = new Audio(url); self.wavesurfer.load(audio, peaks);

However, this does not work on Safari because they dont have any native decoders built-in like Chrome and Firefox.

How can I add a special JavaScript decoder such as https://github.com/chris-rudmin/opus-recorder or https://github.com/brion/ogv.js/ to WebAudio? We only have ogg files to stream right now…

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
qwertycoptercommented, Jan 1, 2021

I had some success with ogv.js and wavesurfer.

I needed to change https://github.com/katspaugh/wavesurfer.js/blob/374e1b0aad7f66aab6a9477e836924a9dc568835/src/mediaelement.js#L177-L184 to

 _load(media, peaks, preload) { 
     // verify media element is valid 
     if ( 
         !((media instanceof HTMLMediaElement) && !(media instanceof OGVPlayer)) || 
         typeof media.addEventListener === 'undefined' 
     ) { 
         throw new Error('media parameter is not a valid media element'); 
     } 

and also https://github.com/katspaugh/wavesurfer.js/blob/1a8fea79055d3b3179c62e1dcf6d5f5867a79ca3/src/mediaelement-webaudio.js#L45-L48 to

_load(media, peaks, preload) { 
     super._load(media, peaks, preload); 
     if (!(media instanceof OGVPlayer))
     {
         this.createMediaElementSource(media);
     }
 } 

Then you can load in the OGVPlayer as if it was an Audio element

        var audio = new OGVPlayer({
            audioContext: wavesurfer.backend.getAudioContext(),
            audioDestination: wavesurfer.backend.analyser,
            wasm: false
        });

        audio.controls = false;
        audio.autoplay = false;
        var wave = document.querySelector('wave');
        wave.appendChild(audio);

        audio.src = "yourfile.ogg";
        wavesurfer.load(audio, peaks);
2reactions
thijstriemstracommented, Aug 19, 2018

Also found this neat utility that might be useful here; https://github.com/jackedgson/crunker

“Simple way to merge, concatenate, play, export and download audio files with the Web Audio API.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to play/decode Ogg Opus Audio in Safari? - Stack Overflow
Okay, finally I found the opus-recorder module. Here is a nice example of how to decode Opus -> PCM -> WAV and play...
Read more >
Safari and OGG - Apple Community
Chrome works fine, so do Opera, FireFox, and on PC Opera and Konqueror... On iPad Mercury, Terra, 360 and Opera open Safari when...
Read more >
Developers - How to play/decode Ogg files on Safari? - - Bountysource
How to play/decode Ogg files on Safari ? ... We are loading our audio from a url like this: let audio = new...
Read more >
How to play .ogg files in Safari? - Reddit
Hi guys,. For some reason, Safari does not allow me to play .ogg files (such as the sound clips on Wikipedia, like here.)...
Read more >
Browser Compatibility of Ogg Vorbis audio format on Safari 15
Ogg Vorbis audio format is Partially Supported on Safari 15. Checkout overall cross browser compatibility of Ogg Vorbis audio format on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found