Javascript for Video?

3 replies
I would like to embed a youtube video on dozens of different sites and then be able to update the video later to a newer version without changing the embed code on all the sites.

Is is possible to create a line of javascript that does not change but I can change the video it "points" to? Or is there a better method?
#javascript #video
  • Profile picture of the author Big Squid
    I already have something like this for some of my sites.

    It's PHP based and works of a database.

    But here's a way to do it even without a database, using a txt file instead.

    FILE 1: youtube.txt
    Code:
    http://www.youtube.com/watch?v=EumsRxVPLGU
    END FILE




    FILE 2: video.php
    // generate the youtube video to display
    $video = file_get_contents('youtube.txt');
    $start = strpos($video, '=');
    $video = substr($video, $start + 1);

    END FILE


    FILE 3: display.php
    //include at top of the page
    <?php require('video.php'); ?>
    // Youtube video embed code - include <?php $video; ?> where video Id would be.
    <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo $video; ?>" frameborder="0" allowfullscreen></iframe>


    END FILE
    Here's a rundown.

    File 1 contains the youtube url of the video you want to embed. Nothing more, nothing less.

    File 2 is the code that parses the youtube.txt file and finds the exact information needed to input into the youtube embed code. The variable is stored as $video (but could be changed to anything you want provided you change all references to it).

    File 3 is the code that runs the program (file 1 and file 2) and then places it into the youtube embed code. All you need to do is insert the <?php echo $video; ?> code snippet into the embed src url.

    Now all you need to do would be to change the youtube.txt file with a new youtube link each time you want to change the video.

    Of course, the files that are displaying the video would have to be PHP. So wordpress would work perfectly with this.

    If you need any clarification, I'd be glad to help...
    {{ DiscussionBoard.errors[5992361].message }}
    • Profile picture of the author coults79
      Originally Posted by Big Squid View Post

      I already have something like this for some of my sites.

      It's PHP based and works of a database.

      But here's a way to do it even without a database, using a txt file instead.

      FILE 1: youtube.txt
      Code:
      http://www.youtube.com/watch?v=EumsRxVPLGU
      END FILE




      FILE 2: video.php
      // generate the youtube video to display
      = file_get_contents('youtube.txt');
      = strpos(, '=');
      = substr(, + 1);

      END FILE


      FILE 3: display.php
      //include at top of the page
      <?php require('video.php'); ?>
      // Youtube video embed code - include <?php ; ?> where video Id would be.
      <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo ; ?>" frameborder="0" allowfullscreen></iframe>


      END FILE
      Here's a rundown.

      File 1 contains the youtube url of the video you want to embed. Nothing more, nothing less.

      File 2 is the code that parses the youtube.txt file and finds the exact information needed to input into the youtube embed code. The variable is stored as (but could be changed to anything you want provided you change all references to it).

      File 3 is the code that runs the program (file 1 and file 2) and then places it into the youtube embed code. All you need to do is insert the <?php echo ; ?> code snippet into the embed src url.

      Now all you need to do would be to change the youtube.txt file with a new youtube link each time you want to change the video.

      Of course, the files that are displaying the video would have to be PHP. So wordpress would work perfectly with this.

      If you need any clarification, I'd be glad to help...
      Would this type of script work for mini event type pages to rotate the gifts to get each link the same exposure at the top?

      Thanks
      {{ DiscussionBoard.errors[7616983].message }}
  • Profile picture of the author FirstSocialApps
    You could put the youtube code in a file on one of your hosts. Then on the other domains you pull in the file, parse out the text, and insert it into the youtube sting.

    You could not do this with JS though. Would need a server side language like PHP
    {{ DiscussionBoard.errors[7617068].message }}

Trending Topics