2016-01-18 32 views
0

我目前正在編寫腳本在本地服務器上播放隨機mp3文件,並在屏幕頂​​部顯示標題。但是,它似乎根本不起作用。加載隨機背景音樂和顯示標題

下面的一些代碼已被刪除,但這些是我用來隨機選擇歌曲,然後顯示標題,任何建議的腳本?

<?php 
 

 
// A Steam API Key is required so as to be able to contact steam and get a users profile image and name 
 
// You can get a Steam API Key by visiting http://steamcommunity.com/dev/apikey 
 
// Don't worry about the web address, it won't have any effect so just type in any web site 
 
// Once you have your steam API Key simply paste the key below. (Make sure the quotation marks are still there or else it won't work) 
 
$SteamAPIKey = "removed"; 
 

 

 
// Don't edit any of the PHP stuff here or else you may break the script 
 
// If you website isn't displaying correctly then please make sure you have configured your loading url correctly 
 
if (!isset($_GET["steamid"])) { 
 
\t die("Woops, you don't seem to be using the correct loading URL format, please make sure it has the correct extension it should look like this: www.yourdomain.com/loading/index.php?steamid=%s"); 
 
} 
 

 
$steamid64 = $_GET["steamid"]; 
 

 
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $SteamAPIKey . "&steamids=" . $steamid64; 
 
$json = file_get_contents($url); 
 
$table2 = json_decode($json, true); 
 
$table = $table2["response"]["players"]; 
 

 
?> 
 

 
<!DOCTYPE HTML> 
 
<html> 
 
\t <head> 
 
    <!-- Hello, your reading the source code for the server load page --> 
 
\t <!-- Created by CaptainMcMarcus for CoderHire --> 
 
    <!-- This is the HTML code below and is safe to edit to your needs --> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 

 
\t <meta name="description" content="Welcome to Crystal Load - Crystal Blue Persuassion!" /> <!-- Webpage Description --> 
 
\t <title>Crystal Load</title> <!-- Webpage Title --> 
 
\t <link href="style.css" rel="stylesheet" type="text/css" /> <!-- Links to the Stylesheet --> 
 
    <link href="colour.css" rel="stylesheet" type="text/css" /> <!-- Links to the Stylesheet for main colours --> 
 
\t 
 
    <script type="text/javascript" src="scripts/jquery.js"></script><!-- Link to jquery so we can do cool stuff --> 
 
    <script type="text/javascript" src="scripts/cycle.js"></script><!-- For Rotating Backgrounds --> 
 
    
 
    <script type="text/javascript"><!-- Script to center content --> 
 
\t $(document).ready(function() { 
 
\t \t //Changes volume of song. 0.5=50% volume 
 
\t \t $('.audio').prop("volume", 0.5); 
 
\t \t \t 
 
\t \t //Perfectly centres content to the middle of the screen both vertically and horizontally 
 
\t \t $(window).resize(function(){ 
 
\t \t \t $('.core-wrapper').css({ 
 
\t \t \t position:'absolute', 
 
\t \t \t left: ($(window).width() 
 
\t \t \t \t - $('.core-wrapper').outerWidth())/2, 
 
\t \t \t top: ($(window).height() 
 
\t \t \t \t - $('.core-wrapper').outerHeight())/2 
 
\t \t \t }); \t 
 
\t \t }); 
 
\t \t // Initiate centre function 
 
\t \t $(window).resize(); 
 
\t \t 
 
\t \t //Lets get thos backgrounds moving 
 
\t \t $('#background-scroll').cycle({ 
 
\t \t \t fx: 'fade', 
 
\t \t \t pause: 0, 
 
\t \t \t speed: 1800, //Time to fade into the next image [in milliseconds] 
 
\t \t \t timeout: 3500 //Time spent on image [in milliseconds] 
 
\t \t }); 
 
\t }); 
 
    </script> 
 
    
 

 
\t </head> 
 
\t 
 
\t <body> 
 
    
 
    <div id="background-scroll"><!-- Add Backgrounds so we can have multiple ones --> 
 
    \t <!-- IF YOU NEED LESS BACKGROUNDS JUST REMOVE THEM OUT OF THE LIST --> 
 
     <!-- TO ADD EXTRA BACKGROUNDS YOU NEED TO MODIFY THE STYLESHEET [ADVANCED USERS ONLY] --> 
 
    \t <div id="bg1"></div><!-- BG 1 --> 
 
     <div id="bg2"></div><!-- BG 2 --> 
 
     <div id="bg3"></div><!-- BG 3 --> 
 
     <div id="bg4"></div><!-- BG 4 --> 
 
     <div id="bg5"></div><!-- BG 5 --> 
 
     <div id="bg6"></div><!-- BG 6 --> 
 
    \t </div> 
 
\t 
 
\t <script type="text/javascript"> 
 
\t 
 
\t var s; 
 
\t s = this.number; 
 
\t \t function Name(){ 
 
\t \t \t 
 
\t \t \t \t if (number == (1)){ 
 
\t \t \t \t \t 
 
\t \t \t \t \t s = "Tobu - Candyland" 
 
\t \t \t \t } 
 
\t \t \t \t if (number == (2)){ 
 
\t \t \t \t \t 
 
\t \t \t \t \t s = "Tobu - Colors" 
 
\t \t \t \t } 
 
\t \t \t \t if (number == (3)){ 
 
\t \t \t \t \t 
 
\t \t \t \t \t s = "Tobu - Dreams" 
 
\t \t \t \t } 
 
\t \t \t \t if (number == (4)){ 
 
\t \t \t \t \t 
 
\t \t \t \t \t s = "Tobu - Seven" 
 
\t \t \t \t } 
 
\t \t \t \t if (number == (5)){ 
 
\t \t \t \t \t 
 
\t \t \t \t \t s = "Tobu - Such Fun" 
 
\t \t \t \t } 
 
\t \t } 
 
\t 
 
\t 
 
\t </script> 
 
\t 
 
\t <script> 
 
document.write('<div id="'+s+'" ></div>'); 
 
</script> 
 
    
 
    <div class="core-wrapper"><!-- Opens the wrapper so we can contain and center everything --> 
 
    \t 
 
     <img src="images/logo.png" width="960" height="120" alt="Your Logo" /><!-- This adds in the logo, simply change logo.png to make this look different --> 
 
\t \t 
 
\t \t 
 
    
 
    \t <div id="left-items"><!-- Opens the wrapper for the left content, there isn't really much to change on the left side as it's dynamic --> 
 
    
 
\t \t \t <?php 
 
\t \t \t \t //PHP Code for the avatar display, it's probably best to leave this section alone 
 
\t \t \t \t echo "<div id=\"profile-wrap\">"; 
 
\t \t \t \t \t 
 
\t \t \t \t \t //Add in the players avatar 
 
\t \t \t \t \t echo "<div id=\"profile-top\">"; 
 
\t \t \t \t \t \t echo "<div id=\"avatarimg\">"; 
 
\t \t // \t \t \t \t \t echo "<img src=\"" . $table["avatarfull"] . "\" />"; 
 
\t \t \t \t \t \t echo "</div>"; 
 
\t \t \t \t \t echo "</div>"; 
 
\t \t \t \t \t 
 
\t \t \t \t \t //Adds in the players name 
 
\t \t \t \t \t echo "<div id=\"profile-bottom\">"; 
 
\t \t \t // \t \t \t echo "<p>" . $table["personaname"] . "</p>"; 
 
\t \t \t \t \t echo "</div>"; 
 
\t \t \t \t \t 
 
\t \t \t \t echo "</div>"; 
 
      ?> 
 
      <div class="clear"></div> 
 
      
 
      
 
      <div class="title server"> 
 
      \t <h2>Server</h2><!-- Adds in the server title, you can change the text to be whatever you would like --> 
 
      \t </div> 
 
      
 
      <!-- Lets get the server Details in here --> 
 
      <ul id="server-list"> 
 
      \t <li><img src="images/server-name.png" alt="Server Name" /> <span id="s-name">Server Name</span></li><!-- Dynamically adds the server name --> 
 
       <li><img src="images/server-mode.png" alt="Game Mode" /> <span id="s-mode">Server Game Mode</span></li><!-- Dynamically adds game mode name --> 
 
       <li><img src="images/server-map.png" alt="Map Name" /> <span id="s-map">Server Map Name</span></li><!-- Dynamically adds map name --> 
 
      \t </ul> 
 
      
 
     \t </div><!-- Close The Wrapper for the Left Items --> 
 
     
 
     <div id="right-items"><!-- Open wrapper for the items on the right --> 
 
     \t 
 
      <div class="title"> 
 
      \t <h2>Staff</h2><!-- Adds in the rules title, you can change the text to be whatever you would like --> 
 
      \t </div> 
 
      
 
      <!-- Let's add in all the rules, the number inside the <span></span> tags will appear in a brighter coloured box --> 
 
      <ul id="rules"> 
 
      \t <li>Owner: Kaydax</li> 
 
       <li>Owner: Name</li> 
 
       <li>Co-Owner: Oilysgtjohnson</li> 
 
       <li>Staff Director: UnknownKury</li> 
 
      </ul> 
 
      
 
     \t </div><!-- This close the right content wrapper --> 
 
     
 
     <div class="clear"></div><!-- This clears things up so that we can vertically align things correctly --> 
 
     
 
     <!-- This adds in the progress bar --> 
 
     <div id="bar"> 
 
     \t <div id="bar-width" style="width: 0%;"></div> 
 
     \t </div> 
 
     
 
     <!-- This adds in the progress percentage bar --> 
 
     <div id="percentage"> 
 
     \t <p></p> 
 
     \t </div> 
 
     
 
     <!-- This adds the current item being downloaded, we use the word connecting by default because if we don't download anything then it won't change --> 
 
     <div id="download-item"> 
 
     \t <p>Connecting...</p> 
 
     \t </div> 
 
    
 
    </div><!-- now we close the core wrapper to keep everything nicely contained and in the middle --> 
 
    
 
    <!-- MUSIC SCRIPT --> 
 
    <!-- To activate simply delete the comment tags and replace music.mp3 with the path to your sound file. --> 
 
    <!-- Adding copyrighted music is illegal as you will be redistributing from the server this is hosted from, this means that you will be held liable --> 
 
    
 
<script type="text/javascript"> 
 

 
var number; 
 

 
function PlayIt(mp3){ 
 
\t nummp3 = 5 
 
\t day = new Date() 
 
\t z = day.getTime() 
 
\t y = (z - (parseInt(z/1000,10) * 1000))/10 
 
\t x = parseInt(y/100*nummp3,10) + 1 
 
\t if (x == (1)){ 
 
\t \t mp3=("Candyland.mp3") \t } 
 
\t if (x == (2)){ 
 
\t \t mp3=("Colors.mp3") 
 
\t } 
 
\t if (x == (3)){ 
 
\t \t mp3=("Dreams.mp3") 
 
\t } 
 
\t if (x == (4)){ 
 
\t \t mp3=("Seven.mp3") 
 
\t } 
 
\t if (x == (5)){ 
 
\t \t mp3=("SuchFun.mp3") 
 
\t } 
 
\t document.getElementById('music').innerHTML='<object width="300" height="44" ' 
 
    \t +'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' 
 
     \t +'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ' 
 
     \t +'<param name="url" value="'+mp3+'">' 
 
     \t +'<param name="uiMode" value="full">' 
 
     \t +'<param name="autoStart" value="true">' 
 
     \t +'<param name="loop" value="true">' 
 
\t \t +'<param name="volume" value="100">' 
 
     \t +'<embed type="application/x-mplayer2" ' 
 
     \t +'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" ' 
 
     \t +'showcontrols="true" uimode="full" width="300" height="44" ' 
 
     \t +'src="'+mp3+'" autostart="1" loop="true">' 
 
\t \t +'<\/object>'; 
 
\t alert(mp3); 
 
\t number = x; 
 
} 
 
window.onload=PlayIt; 
 
</script> 
 
</head> 
 
    
 
    <script type="text/javascript" src="scripts/main.js"></script><!-- Script to get downloads, map, players, game mode and sort out the loading bar --> 
 

 
\t </body><!-- Closes off the HTML Document --> 
 
</html>

+0

開始通過打開控制檯(F12),看看有什麼錯誤有,和解決這些問題一個接一個(有幾個語法錯誤。) – adeneo

回答

0

你已經證明沒有做任何事情的代碼,使我們很難調試。你應該避免的一件事是使用關鍵字Number作爲變量名稱。這裏有一個簡單的隨機SONGNAME選擇器:

var songlist = ["Tobu - Candyland", "Tobu - Colors", "Tobu - Dreams", "Tobu - Seven", "Tobu - Such Fun"]; 
 

 
alert(songlist[Math.floor(Math.random() * songlist.length)]);

+0

代碼已編輯 –

+0

您可以在第一個塊中使用'number',但您可以在第二個塊中定義它。您應該重寫該代碼的幾個部分。我給你如何從數組中挑選一個隨機項目,用它來開始播放歌曲並顯示其標題。 – Shomz