Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Autoplay false in oembed audio/video? #97

Open
GuilleArg opened this issue Nov 28, 2013 · 1 comment
Open

Autoplay false in oembed audio/video? #97

GuilleArg opened this issue Nov 28, 2013 · 1 comment

Comments

@GuilleArg
Copy link

Hello!
Is there any way to pause the oEmbed audio/video that play automatically? audioboo.fm eg. I tried autoplay:false but it does not work.
Thank you very much!

@0x0ece
Copy link

0x0ece commented Dec 14, 2013

In my experience, you need to deal with the players case by case.

A friend did some hack for some of them, he basically modified the queryString after a video/audio is returned.
The code looks something like this:

function parseQueryAttrAutoplay(url) 
{
    if (url.indexOf("Start=true")>=0 && settings.autoplay==0) { new_url = url.replace("Start=true", "Start=false"); }
    else if (url.indexOf("autoplay=1")>=0 && settings.autoplay==0) { new_url = url.replace("autoplay=1", "autoplay=0"); }
    else if (url.indexOf("autoPlay=1")>=0 && settings.autoplay==0) { new_url = url.replace("autoPlay=1", "autoPlay=0"); }
    else if (url.indexOf("autoPlay=yes")>=0 && settings.autoplay==0) { new_url = url.replace("autoPlay=yes", "autoPlay=no"); }
    else if (url.indexOf("auto=1")>=0 && settings.autoplay==0) { new_url = url.replace("auto=1", "auto=0"); }
    else if (url.indexOf("autoStart=true")>=0 && settings.autoplay==0) { new_url = url.replace("autoStart=true", "autoStart=false"); }
    else if (url.indexOf("auto_play=true")>=0 && settings.autoplay==0) { new_url = url.replace("auto_play=true", "auto_play=false"); }
    else
    {
        var n = url.split(" ");
        for (i=0; i<n.length; i++)
        {
            //src="http://www.youtube.com/embed/iy4mXZN1Zzk?feature=oembed"
            if (n[i].indexOf("src=")>=0)
            {
                var src = n[i].split("src=");
                if (src[1].length)
                { 
                    var url_len = src[1].length;
                    //if (src[0]=="\"" && src[url_len-1]=="\"") src[1] = src[1].substring(1, src[1].length-1); // http://www.youtube.com/embed/iy4mXZN1Zzk?feature=oembed
                    //else src[1] = src[1].substring(0, src[1].length);
                    tmp_src = src[1];
                    src[1] = src[1].substring(1, src[1].length-1);
                    //if (DEBUG) console.log("parseQueryAttrAutoplay: " + src[1]);

                    /*
                    * YouTube
                    * <iframe width="459" height="344" src="http://www.youtube.com/embed/iy4mXZN1Zzk?feature=oembed" frameborder="0" allowfullscreen></iframe>
                    */
                    if (src[1].match(/youtube.*/) && (src[1].indexOf("autoplay=1")<0) && settings.autoplay==1)
                    {
                        if (src[1].indexOf("?")>=0) src[1] = src[1]+"&autoplay="+1;
                        else src[1] = src[1]+"?autoplay="+1;

                        n[i] = "src=\""+src[1]+"\"";
                        new_url = n.join(" ");
                        break;                              
                    }
                    else if ((src[1].match(/vimeo.*/) || src[1].match(/dailymotion.*/))
                    && (src[1].indexOf("autoplay=1")<0) && settings.autoplay==1)
                    {
                        if (src[1].indexOf("?")>=0) src[1] = src[1]+"&autoplay="+1;
                        else src[1] = src[1]+"?autoplay="+1;

                        n[i] = "src=\""+src[1]+"\"";
                        new_url = n.join(" ");
                        break;
                    }
                    else if ((src[1].match(/mixcloud.*/) || src[1].match(/rd.io.*/))
                    && (src[1].indexOf("autoplay=1")<0) && settings.autoplay==1)
                    {
                        if (src[1].indexOf("?")>=0) src[1] = src[1]+"&autoplay="+1;
                        else src[1] = src[1]+"?autoplay="+1;

                        n[i] = "src=\""+src[1]+"\"";
                        new_url = n.join(" ");
                        break;                              
                    }
                    else if (src[1].match(/soundcloud.*/) && (src[1].indexOf("auto_play=true")<0) && settings.autoplay==1)
                    {
                        if (src[1].indexOf("callback")>=0)
                        {
                            var tmp_url = src[1].split("callback");
                            src[1] = tmp_url[0]+"auto_play=true&callback=" + tmp_url[1];
                            n[i] = "src="+src[1];
                        }
                        else
                        {                   
                            if (src[1].indexOf("?")>=0) src[1] = src[1]+"&auto_play=true";
                            else src[1] = src[1]+"?auto_play=true";
                            n[i] = "src=\""+src[1]+"\"";
                        }

                        new_url = n.join(" ");
                        break;                              
                    }

                }
            }
        }
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants