• jjon

    (@jjon)


    Very tyro, rookie with php and wordpress. I wanted a sort of category page that the twentyseventeen theme didn’t offer, and I didn’t find a straightforward plugin that would give me what I want, so, learning as I go, I thought I’d hack on it myself.

    Starting with the twentyseventeen archive.php template as a base, I’ve been building a tentative custom category page (at the linked address). It displays a lot of video posts. It is possible now to set more than one of these videos going at once, and the bandwidth will not effectively support simultaneous streams. Is there any php I could embed in my template that would kill all other video players when a video is ‘played’?

    Failing that, does anybody know a DOM event I might hijack in javascript that would serve this purpose?

    • This topic was modified 5 years ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    PHP?? No. You’re making a classic rookie mistake of thinking PHP can manage anything on a page after it has been output. It can’t because it runs on the server. The page now resides in the browser. Only JavaScript or its many variants like jQuery can run on a browser. (Well, there are extensions for other languages, but you cannot expect users to have them installed)

    It’s actually impossible to access the YT play button and disable it with JS because the button lies within an externally sourced iframe. Being able to access it is seen as cross-site scripting, which is blocked for security reasons.

    Just having many embedded YT players on a page really drags down page load speeds even if they are not playing. One scheme you could implement is to merely have static images representing embedded players. When any one is clicked, your script puts up a modal that contains the actual player clicked, having been dynamically loaded by the click event on the static image. Any click outside the player kills the modal and the embed it contained. Thus users can only play one vid at a time.

    If you ask me, it’s not worth doing anything to protect user’s bandwidth. It’s not like these all auto-play. If someone starts multiple streams, it’s their own fault that they took up all available bandwidth.

    Thread Starter jjon

    (@jjon)

    Thanks @bcworkz, that was quite helpful. Rookie mistake, yes. I can remember making the same mistake when I first built something in PHP decades ago.

    It’s actually impossible to access the YT play button and disable it with JS because the button lies within an externally sourced iframe. Being able to access it is seen as cross-site scripting, which is blocked for security reasons.

    In a different context, and without all this PHP, I embeded a vimeo player in a page and found it had an easily accessible API so that I could do this:

    <script>
      function unloadVimeo(player) {
        var p = new Vimeo.Player(document.getElementById(player));
        p.unload();
      }
    </script>

    where player is the ID of a dom element. YouTube has no similar API?

    I like your static images with modal player idea, but I’m trying to keep the extra code to a minimum

    As to user’s bandwidth; yeah, you’re right.

    j

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘kill multiple youtube players’ is closed to new replies.