2011-12-03 34 views
1

我有這個代碼即時通訊使用在我的網頁上播放音樂即時通訊開發,但我有問題如何嵌入或播放更多的一首歌..我想當人們訪問我的網站他們可以播放music.anyone與我如何修改此代碼的想法?在我的網頁上嵌入多首歌曲

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title> Welcome to Groundswell </title> 
    <link href="css/main.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 

<script> 
    $(document).ready(function(){ 
     $("#play-bt").click(function(){ 
      $("#audio-player")[0].play(); 
      $("#message").text("Music started"); 
     }) 

     $("#pause-bt").click(function(){ 
      $("#audio-player")[0].pause(); 
      $("#message").text("Music paused"); 
     }) 

     $("#stop-bt").click(function(){ 
      $("#audio-player")[0].pause(); 
      $("#audio-player")[0].currentTime = 0; 
      $("#message").text("Music Stopped"); 
     }) 
    }) 
</script> 
</head> 

<body> 

<audio id="audio-player" name="audio-player" src="02 - Hillsong - Run.mp3"></audio> 
<div id="message"></div> 
<a id="play-bt" href="#">Play music</a> | <a id="pause-bt" href="#">Pause music</a> | <a id="stop-bt" href="#">Stop music</a> 

</body> 
</html> 
+0

你使用什麼庫? – Headshota

+1

難道你不能複製代碼但使用不同的ID嗎? – sooper

回答

0

在腳本部分,添加所有的歌曲文件的數組,然後進行,將動態設置音頻元素的src函數(或兩個)。

<script> 
var songlist=['02 - Hillsong - Run.mp3','song2.mp3','song_n.mp3']; 
var whichsong=0; 
var playing=false; 
$(document).ready(function(){ 
    $("#play-bt").click(function(){ 
     $("#audio-player")[0].play(); 
     playing=true; 
     $("#message").text("Music started"); 
    }) 

    $("#pause-bt").click(function(){ 
     $("#audio-player")[0].pause(); 
     playing=false; 
     $("#message").text("Music paused"); 
    }) 

    $("#stop-bt").click(function(){ 
     $("#audio-player")[0].pause(); 
     $("#audio-player")[0].currentTime = 0; 
     playing=false; 
     $("#message").text("Music Stopped"); 
    }) 

    $("#next-bt").click(function(){ 
     $("#audio-player")[0].pause(); 
     $("#audio-player")[0].src=''; 
     whichsong++; 
     if(whichsong==songlist.length){whichsong=0;} 
     $("#audio-player")[0].src=songlist[whichsong]; 
     if(playing){$("#audio-player")[0].play();} 
    }) 
}) 
</script> 

,然後添加其他鏈接,「下一步」用id="next-bt"(你也許可以從這裏找出如何使以前按鈕)

+0

怎麼樣?我有點困惑 – thequantumtheories

+0

增加了一些樣本 –

+0

那麼我該怎麼做音頻標籤刪除?或什麼? – thequantumtheories

相關問題