Search code examples
javascripthtmlflashsdksoundmanager2

How to prevent flash audio mode for chrome with javascript


There is a Chrome bug from the version 49

This is affecting my application which is based on this api http://soundcloud.lrdiv.co/ ( github repo https://github.com/lrdiv/ember-soundcloud )

Basically the problem is that Soundcloud Api uses soundmanager2 as a base to handle audio stream that itself have 2 modes flash and html5. The issue is that if the flash player is available it will try to use it and fail while if it's not available it will just use html5 and work right away.

Proof is that if you go here chrome://plugins/ and deactivate the flash player the audio stream will work again in Chrome.

In this discussion https://github.com/soundcloud/soundcloud-javascript/issues/39#issuecomment-206726301 , one possible temporary hack is to detect chrome and return false for playing in flash mode.

    function d() {
        var t, e, n, i;
        if ("undefined" != typeof window.ActiveXObject)
            try {
                i = new window.ActiveXObject("ShockwaveFlash.ShockwaveFlash"),
                i && (t = i.GetVariable("$version"))
            } catch (r) {}
        else
            window.navigator && window.navigator.plugins && window.navigator.plugins.length > 0 && (n = "application/x-shockwave-flash",
            e = window.navigator.mimeTypes,
            e && e[n] && e[n].enabledPlugin && e[n].enabledPlugin.description && (t = e[n].enabledPlugin.description));
        // @todo, chrome flash player bug, if under chrome, dont return true here, more info:
        // https://github.com/soundcloud/soundcloud-javascript/issues/39
        **if (!!window.chrome) {
          return false
        }**
        return t

    }

I would like to do the same in my sdk.js but not very clear in which line i have i have to prevent the flash streaming for chrome


Solution

  • In my sdk.js i had to add

    soundManager.preferFlash = false;
    

    to not use Flash Plugin as Audio Player