469,282 Members | 1,708 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Playlist with PHP, HTML5, JavaScript

computerfox
276 100+
Hello everyone,

I am working on a new project and I need some help. I am trying to create an HTML5 player with a looping playlist. This will be a system where there will be many playlists and the files will be in .m3u. Later on I would actually run this with a database, but I only know how to manipulate it with PHP, which is not static, which is why I'm having so much issues with this initial part.

My present code is this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <!DOCTYPE html>
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title></title>
  7.  
  8. <link href="main.css" rel="stylesheet" type="text/css"/>
  9.  
  10. </head>
  11. <body>
  12. <?php
  13. $station="all";
  14.  
  15. if($_GET['station']!=NULL){
  16. $station=$_GET['station'];
  17. }
  18.  
  19. ?>
  20.  
  21. <br/>
  22. <br/>
  23. <li>
  24.  
  25. <br/>
  26.  
  27. <?php
  28.  
  29.  
  30. //Read in file
  31. $getFile="playlists/".$station.".m3u";
  32. $handle = fopen($getFile,"r");
  33.  
  34. $i=0;
  35. $total=1;
  36.     while (($buffer = fgets($handle)) !== false) {
  37.      $song[$i]=$buffer;
  38.      $i++;
  39. $total++;   
  40.     }
  41.  
  42. //Increment audio
  43.  
  44. //echo "<font color=blue>".$i."<BR>".$song[$i]."</font><BR>";
  45.  
  46.  
  47. ?>
  48.  
  49. <script type="text/javascript">
  50. /*
  51. var nextVideo = "playlists/<?$song[$i];?>";
  52. var videoPlayer = document.getElementById('videoPlayer');
  53. videoPlayer.onend = function(){
  54.     videoPlayer.src = nextVideo;
  55. }
  56.  
  57. */
  58. </script>
  59.  
  60. <?$i=0;$np=str_replace("music/","",$song[$i]);?>
  61.  
  62. Now playing: <?echo $np;?>
  63.  
  64. <br/>
  65. <?
  66. if($song[$i+1]==NULL){
  67. echo 'Next: '.str_replace("music/","",$song[$i]);
  68. }
  69. else{
  70. echo 'Next:  '.str_replace("music/","",$song[$i+1]);
  71. }
  72. ?>
  73. <BR>
  74. <BR><BR>
  75. <audio id="player" controls="controls" autoplay="autoplay" preload="auto" loop autoplay autobuffer controls>
  76.  
  77.     <?php
  78.     for ($i=0;$i<$total;$i++){?>
  79.  
  80.     <source src="playlists/<?echo $song[$i];?>" type="audio/mp3" />
  81.  
  82.  <?}?>
  83. </audio>
  84. <li>
  85. <br/>
  86. <br/>
  87. <br/>
  88. <br/>
  89. <br/>
  90. <br/>
  91. </li>
  92. </div>
  93. </ul>
  94.  
  95. <br/>
  96. <br/>
  97. <br/>
  98.  
  99.  
  100. </p>
  101. </body>
  102. </html>
  103.  
Any ideas? Your help would be greatly appreciated.
Oct 14 '11 #1
2 4075
Dormilich
8,651 Expert Mod 8TB
some comments:
- way too many <br/>. use CSS for formatting.
- fgets() in a loop can be replaced by file()
- way too often broken out of PHP. best is you have a template and replace placeholders therein with the precomputed HTML code. if you donít like that, at least compute all the HTML first and then have one HTML section where you place the content.
Oct 19 '11 #2
computerfox
276 100+
i got it to work :-)
Oct 28 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by varunk | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.