Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Artificial Intelligence (1)
  • Automobiles (12)
    • Cars (7)
  • Blog (104)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (56)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

JavaScriptPHP

Create Custom YouTube Playlist using PHP and JavaScript

By Admin
February 1, 2021 2 Min Read
0

The following source code enables us to create a custom playlist with just the videos that we want to play.

 

Full Source Code :

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.4/css/bootstrap.min.css"/>

<style type="text/css">
  body{
    background: #ddd;
  }
  .head{
    margin-top:20px;
    margin-bottom: 20px;
    font-weight: bold;
    text-align: center;
  }
  .container{
    margin-top:40px;
  }
  .thumb{
    width:100%;
    min-height: 90px;
  }
  .list{
    list-style-type: none;
    padding:0px;
  }
  .list li{
    cursor: pointer;
      background: #eee;
      margin-bottom: 10px;
      padding-left: 10px;
      padding-top: 5px;
      padding-bottom: 1px;
      font-weight: bold;
      font-size:15px;
  }
  .list li:hover{
    transform: translateX(10px);
  }
  .wrapper .col{
    height: 325px;
    overflow: auto;
    padding:5px;
  }
  .wrapper{
    background: #444;
  }
  .list-wrapper{
    overflow-x: hidden!important;
    background: #888;
  }
  .title{
    padding-top:20px;
  }
  .item.active{
    background: #444;
    color:#ddd;
  }
  ::-webkit-scrollbar {
    width: 8px;
  }

  ::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px grey;
    border-radius: 10px;
  }

  ::-webkit-scrollbar-thumb {
    background: #000;
    border-radius: 10px;
  }
</style>

<?php
  $videos = array(
    array(
      'id'=>'5Unq-1ky4-g',
      'title'=>"Enrique Iglesias Somebody's Me",
    ),
    array(
      'id'=>'253gydVXZrQ',
      'title'=>'Titanic - My heart will go on',
    ),
    array(
      'id'=>'Y0pdQU87dc8',
      'title'=>'Everything I Do, I Do It For You',
    ),
    array(
      'id'=>'fV4DiAyExN0',
      'title'=>'Hoobastank - The Reason',
    ),
    array(
      'id'=>'yKNxeF4KMsY',
      'title'=>'Coldplay - Yellow',
    ),
    array(
      'id'=>'vUSzL2leaFM',
      'title'=>'Wonderful Tonight - Eric Clapton',
    ),
    array(
      'id'=>'6hzrDeceEKc',
      'title'=>'Oasis - Wonderwall',
    ),
    array(
      'id'=>'EqPtz5qN7HM',
      'title'=>'Eagles - Hotel California',
    ),
    array(
      'id'=>'m_uWS6K-VF8',
      'title'=>'I will be right here waiting for you',
    )
  );
?>

<h1 class="head">
  <p>Create Custom YouTube Playlist</p>
  <p> using PHP and JavaScript</p>
</h1>
<hr>
<div class="container">
  <div class="row wrapper">
    <div class="col col-md-7">
      <iframe id="video-embed" width="100%" height="315" src="https://www.youtube.com/embed/<?php echo $videos[0]['id'];?>" frameborder="0"></iframe>
    </div>
    <div class="col col-md-5 list-wrapper">
      <ol class="list">
        <?php foreach($videos as $v){?>
          <li class="item" id="<?php echo $v['id'];?>" onclick="playVideo('<?php echo $v['id'];?>')">
            <p><?php echo $v['title'];?></p>
          </li>
        <?php } ?>
      </ul>
    </div>
  </div>
</div>

<script type="text/javascript">
  document.getElementsByClassName('item')[0].classList.add('active');
  function playVideo(id){
    items = document.getElementsByClassName('item');
    for(i=0;i<items.length;i++){
      items[i].classList.remove("active");
    }
    document.getElementById(id).classList.add('active');
    src = 'https://www.youtube.com/embed/'+id;
    document.getElementById('video-embed').setAttribute('src',src);
  }
</script>

Follow this video for complete guidance :

 

Tags:

youtube
Author

Admin

Follow Me
Other Articles
Previous

Animated Card Slider using jQuery

Next

Random Quotes Generator using PHP API

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Over 10,000 Nepali Students to Join First-Ever National Innovation League
  • AI Journalism Workshop Held in Kathmandu by CAN Federation and TBAN
  • ChatGPT vs Gemini vs Claude AI: 7 Crucial Differences Revealed
  • CAN Federation Partners with FEJA to Host Exclusive ‘AI in Journalism’ Workshop
  • Shramik Shanti Campus Hosts Workshop on AI in Cybersecurity and Sovereign AI

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Over 10,000 Nepali Students to Join First-Ever National Innovation League Admin
  • AI Journalism Workshop Held in Kathmandu by CAN Federation and TBAN Admin
  • ChatGPT vs Gemini vs Claude AI: 7 Crucial Differences Revealed Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme