SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    youtube chromeless player underscore problem

    I am using the youtube chromeless player and embeding videos with loadVideoById() method
    problem is that videos with an id that contains an underscore or dash dont play although they play in the normal player.

    I also tried replacing with a hex value in querystring i.e (%5f) but that did not work


    I also tried loadVideoByUrl() method with several urls but still they don't load.


    here is my code

    function switchToPlayer(ytid){

    var params = { allowScriptAccess: "always"};
    var atts = { id: ytid,onmouseover: "this.playVideo()",onmouseout: "this.pauseVideo()"};
    swfobject.embedSWF("http://www.youtube.com/apiplayer?border=0&enablejsapi=1&playerapiid="+ytid, 'cell'+ytid, "150", "120", "8", "scripts/expressInstall.swf",null,params,atts);

    }

    function onYouTubePlayerReady(playerapiid) {
    ytplayer = document.getElementById(playerapiid);
    ytplayer.loadVideoById(playerapiid);
    }

  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you post an ID that you're having trouble with? I'm looking for a video to test with, but they all have IDs that are totally alphanumeric (4lsCA2eQMog, HfamHCd6dXE, etc).
    I'm the web overlord for Graphic Business Systems

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by sdleihssirhc View Post
    Can you post an ID that you're having trouble with? I'm looking for a video to test with, but they all have IDs that are totally alphanumeric (4lsCA2eQMog, HfamHCd6dXE, etc).
    Here's some recent ones with underscores and dashes

    Underscores
    http://www.youtube.com/watch?v=_uPIpJCdgxg
    http://www.youtube.com/watch?v=LADS9_Cd1IY

    Dashes
    http://www.youtube.com/watch?v=zs2t-xCVHBo
    http://www.youtube.com/watch?v=PTgh-QwvyVo

    Both
    http://www.youtube.com/watch?v=bQ_szBgX-gE
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, paul_wilkins

    Now that we got that squared away, there were two different mistakes I made that prevented the hyphenated one from working:

    1. I needed to decode the playerapiid. When it wouldn't work, the first thing I did was make sure the onYouTubePlayerReady function was getting the correct id. I used "bQ_szBgX-gE" for my test, but what the function got was "bQ%5FszBgX%2DgE". So I had to run playerapiid through the decodeURIComponent function before I was able to do anything with it.
    2. I forgot to tell YouTube which version I was using. This seems pretty stupid, but the results kept pointing to the same conclusion. The URL I was using for the swf looked something like this: "http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=VIDEO". In order to make it work, I had to add "&version=3"


    Does it work if you make those changes?
    I'm the web overlord for Graphic Business Systems

  5. #5
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    that did it

    terrific! that worked like a charm.

    thank you very much


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •