HTML+CSS+JavaScript做的音乐播放器,就当是入门的小东西吧~

疯了,因为 有.mp3文件搞得项目太大,没法打包上传,懒的去删了,直接上代码~ 

music.html




 





这是音乐盒
1 歌名《简短铃声》--测试
歌曲名                               艺人名                                时长

style.css


/* CSS Document */



 
	
	
	.main
	
	{
	
	  margin-left:200px;
	  margin-top:100px;
	 
	  border-width: 2px;
  
      border-style: solid;
 
      border-color:#FF0066;  
  
      width:1280px;
  
      height:700px;
  
      padding:2px 5px;
  
      position:absolute;
  
      z-index:9;
	  background-color:#663366;
	  
	  box-shadow: 30px 30px 5px #888888; 
	  
	 
	
	} 
	
	.musicHead
	{
	   width:1280px;
	  padding:13px 9px;
	  height:60px;
	  
	  
	
    }
	.musicLeft
	{
	  float:left;
	  padding:3px 5px;
	  width:170px;
	  margin-top:12px;
	
	}
	
	.musicCenter
	{    float:left;
	     width:724px;
		 padding:3px 5px;
		 height:20px;
	}
	
	.musicBottom
	{
	margin-top:6px;
	
	
	}
	
	
	.title
	{
	padding:5px;
	margin-left:20px;
	
	
	}
	
	.songArray
	{
	position:absolute;
	color:#FF0066;
	padding:5px;
	left: 230px;
	top: 250px;
	z-index:10;
	text-shadow: 5px 5px 5px #FF0000;
	
	}
	
	
	.songArrayLeft
	{
	 
	  width:300px;
	  float:left;
	  text-shadow: 5px 5px 5px #FF0000;
	
	}
	.songArrayCenter
	{
	  width:300px;
	    float:left;
		text-shadow: 5px 5px 5px #FF0000;
	
	}
	.songArrayRight
	{
	  width:300px;
	    float:left;
		text-shadow: 5px 5px 5px #FF0000;
	
	}
	
	
	
	.musicPlayModel
	{
	   margin-top:22px;
	   float:left;
	   width:330px;
	   height:40px;
	}
	
	#timeshow
	{
	margin-left:8px;
	float:left;
	width:100px;
	color:#FFFFFF;
	
	}
	.modelshow
	{
	margin-left:8px;
	float:left;
	width:30px;
	height:40px;
	
	}
	
	.sound
	{
	position:absolute;
	width:200px;
	height:20px;
	z-index:10;
	left: 1082px;
	top: 35px;
	margin-left:5px;
	
	}
	
	.soundImageOpen
	{
	width:25px;
	height:25px;
	float:left;
	background:url(../photo/音量开.png) no-repeat;
	
	
	
	}
	.soundImageClose
	{
	width:25px;
	height:25px;
	float:left;
	background:url(../photo/音量关.png) no-repeat;
	
	}

 
	.VoidProcess
	{
	
	  width: 66px;

      height: 8px;
 
      cursor: pointer;
 
      background-color: #000000;     
      
	  
	  
      float:left;
	  margin-top:6px;
	  margin-left:5px;
	
	   border:2px solid;
      border-radius:25px;
	  
	
	
	}
	
	.VoidProcessYet
	
	{
	width: 0px;
	height: 8px;
	position:absolute;
	cursor: pointer;
	background-color: #FF0000;
	float:left;
	margin-top:6px;
	margin-left:10px;
	left: 19px;
	top: 0px;
	
	 border:2px solid;
      border-radius:25px;
	  
	
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	.ProcessControl
 
    {
 
       width:720px;
 
       padding: 5px 10px 10px 10px;
 
       float:left; 
 
       height:20px; 
 
       color:#ffffff;
	   
	  
 
    }
	
	 .Process
 
   {

      width: 720px;
	  float: left;
      height: 8px;
      cursor: pointer;
      background-color:#000000;
	  
	  border:2px solid;
      border-radius:25px;
	  
 
      
 
    }

   
 
   .ProcessYet

    {
 
      width: 0px;
 
      position:absolute;
 
      height: 8px;
 
      cursor: pointer;
 
      background-color: #FF0000;
	  
	   z-index:4; 
	   border:2px solid;   
       border-radius:25px;
	   
	  
 
    }
	
	.prev
	{
	height:30px;
	width:40px;
	float:left;
	
	}
	
	#singer
	{
	color:#FFFFFF;
	
	
	}
	
	.MainControl
	{
	
       width:30px;
       height:30px;
	   margin-left:20px;
       margin-right:5px;
 
        float:left; 
	    background:url(../photo/暂停.jpg) no-repeat;
	    background-size:30px;   
	
	}
	.stop
	{
	
	 width:30px;
       height:30px;
	   margin-left:20px;
       margin-right:5px;
 
        float:left; 
	   
		 background:url(../photo/开始.jpg) no-repeat;
	    background-size:30px;   
	
	}
	
	
	
	.next
	{
	height:30px;
	width:40px;
	float:left;
	
	}
	
	
	.redLine
	 {
	 height:3px;
	 background:#FF0066;
	
     }
	 
	 .songList
	 {
	 width:1024px;
	 
	 
	  }
	   开始与结束的切换
	 
	  #begin
	  {
	  width:5px;
	  height:5px;
	  background: #FF0000;
	  
	  }
	  
	  .end
	  {
	   width:5px;
	  height:5px;
	  background:  #0000FF;
	   
	  }
	  
	  a{text-decoration:none;
	  color:#FF0066;}
a:hover{text-decoration:none;
color:#6600FF;
}
	  
最后是js.js 

alert(1);
var player=document.getElementById("video1");
var mysongs=new Array("./music/简短铃声.mp3","./music/矜持.mp3","./music/很受伤.mp3","./music/爱你的最后一天.mp3","./music/三个人的时光.mp3","./music/有关爱情.mp3","./music/foryou.mp3","./music/123.mp3");
var singerName=new Array("1 简短铃声 "," 2 矜持"," 3 很受伤 "," 4 爱你的最后一天","5 三个人的时光","6 有关爱情","7 for you","8 123");
var nowSong=new Array("1 歌名《简短铃声》--测试","2 歌名《矜持》--王菲","3 歌名《很受伤》--任贤齐","4 歌名《爱你的最后一天》--任贤齐","5 歌名《三个人的时光》--三藏","6 歌名《有关爱情》--DJ","7 歌名《for you》--Byane","8 歌名《123》--神人")
var singer=new Array("测试","王菲","任贤齐","任贤齐","三藏","DJ","Byane","神人");
var time=new Array("00:04","04:38","04:31","03:52","01:30","04:04","06:33","00:09");
var songIndex=0;
document.write("
"); player.addEventListener('ended',onPlayEnd); player.οnlοadstart=Play(); //音乐load的时候就开始调用的函数 //player.οnlοadstart=totaltime(); //未封装,歌曲列表 document.write('
'); //暂时认为时间是静态存入数组的,估计也是,因为动态要等音频加载完了才能一个一个现实! for(var i=0;i'+""+singerName[i]+""+'
'); document.write('
'+singer[i]+'
'); document.write('
'+time[i]+'
'); document.write("
"); } document.write('
'); // function getSongName(num) { document.getElementById("mp4_src").src=mysongs[num]; document.getElementById("singer").innerHTML=nowSong[num]; Load(); } $(".Process").click(function (e) { var Process = $(".Process").offset(); var ProcessStart = Process.left; var ProcessLength = $(".Process").width(); var CurrentProces = e.clientX - ProcessStart; PointToWhere(CurrentProces / ProcessLength); $(".ProcessYet").css("width", CurrentProces); }); //点击已经播放过的进度条(向前点击) $(".ProcessYet").click(function (e) { //播放进度条的基准参数 var Process = $(".Process").offset(); var ProcessStart = Process.left; var ProcessLength = $(".Process").width(); var CurrentProces = e.clientX - ProcessStart; PointToWhere(CurrentProces / ProcessLength); $(".ProcessYet").css("width", CurrentProces); }); function PointToWhere(PointInTotal) { player.currentTime = PointInTotal * player.duration; Play(); } $(".VoidProcess").click(function (e) { //音量进度条的基准参数 var VoidProcess = $(".VoidProcess").offset(); var VoidProcessStart = VoidProcess.left; var VoidProcessLength = $(".VoidProcess").width(); var CurrentProces = e.clientX - VoidProcessStart; VolumeProcessRange(CurrentProces / VoidProcessLength); $(".VoidProcessYet").css("width", CurrentProces); }); //音量进度条时间(进度减少) $(".VoidProcessYet").click(function (e) { //音量进度条的基准参数 var VoidProcess = $(".VoidProcess").offset(); var VoidProcessStart = VoidProcess.left; var VoidProcessLength = $(".VoidProcess").width(); var CurrentProces = e.clientX - VoidProcessStart; VolumeProcessRange(CurrentProces / VoidProcessLength); $(".VoidProcessYet").css("width", CurrentProces); }); function VolumeProcessRange(rangeVal) { player.volume = parseFloat(rangeVal); } function TimePass() { var ProcessYet = 0; setInterval(function () { var ProcessYet = (player.currentTime / player.duration) * 720; $(".ProcessYet").css("width", ProcessYet); var currentTime = timeDispose(player.currentTime); var timeAll = timeDispose(player.duration); document.getElementById("timeshow").innerHTML=currentTime+"|"+timeAll;//时间显示 }, 1000); } //同样的代码,就是显示时间的那个,放在函数外面就不好使,而且放在一般的函数中也不好使,目测是因为音乐加载的问题,只有音乐全部加载出来才能出现时间。 //函数内的赋值不能在函数外直接调用,(这个不肯定),而且尤为不应该在音乐尚未加载的时候就调用! function TotalTime() { alert(timeDispose(player.duration)); } function currentTime() { alert(timeDispose(player.currentTime)); } function timeDispose(number) { var minute = parseInt(number / 60); var second = parseInt(number % 60); minute = minute >= 10 ? minute : "0" + minute; second = second >= 10 ? second : "0" + second; return minute + ":" + second; } function onPlayEnd() { if(modelnum==3&&songIndex==mysongs.length-1) { songIndex=-1; document.getElementById("mp4_src").src=mysongs[songIndex]; document.getElementById("singer").innerHTML=singerName[songIndex]; Load(); } if(modelnum==4) { songIndex= parseInt(mysongs.length * Math.random()); document.getElementById("mp4_src").src=mysongs[songIndex]; document.getElementById("singer").innerHTML=singerName[songIndex]; Load(); } if(modelnum==0||modelnum==3&&songIndex!=mysongs.length-1) { next(); } if(modelnum==1) { Load(); } } //点击下一曲或者上一曲要判断一下 开始和停止按钮的css状态! 应该放在next和prev中,不过放入进去后发现,每次点下一曲之后都需要点两次暂定才能暂停,试过多次修改,问题无法解决,暂未应用! function IshasCss() { if($("#MainControl").hasClass("MainControl")){} //#MainControl是id ~ else { $("#MainControl").removeClass("stop").addClass("MainControl"); } } function next() { $(".ProcessYet").css("width", 0); if(modelnum==1) { Load(); } if(modelnum==2||modelnum==0) { if(songIndex0) { songIndex=this.songIndex-1; document.getElementById("mp4_src").src=mysongs[songIndex]; document.getElementById("singer").innerHTML=nowSong[songIndex]; Load(); } else{alert("已经播放到最开始的一首");player.pause();} } if(modelnum==3) { if(songIndex>0) { songIndex=this.songIndex-1; } else {songIndex=mysongs.length-1;} document.getElementById("mp4_src").src=mysongs[songIndex]; document.getElementById("singer").innerHTML=nowSong[songIndex]; Load(); } if(modelnum==4) { songIndex= parseInt(mysongs.length * Math.random()); document.getElementById("mp4_src").src=mysongs[songIndex]; document.getElementById("singer").innerHTML=nowSong[songIndex]; Load(); } } var modelnum=0; function getModel(model) { modelnum=model; } var beginorstop=document.getElementById("begin"); var end=document.getElementById("end"); var changemodel=document.getElementById("modelshow"); //切换 $(document).ready(function () { //切换开始暂停标签 $("#MainControl").toggle( function () { $(this).removeClass("MainControl").addClass("stop"); player.pause();}, function () { $(this).removeClass("stop").addClass("MainControl"); player.play(); TimePass(); }); //模式的切换 $("#modelshow").toggle( function () { changemodel.innerHTML=""; getModel(1); }, function () { changemodel.innerHTML=""; getModel(4); }, function () { changemodel.innerHTML=""; getModel(3); }); //音量的切换 $(".soundImageOpen").toggle( function () { $(this).removeClass("soundImageOpen").addClass("soundImageClose"); player.volume = 0;}, function () { $(this).removeClass("soundImageClose").addClass("soundImageOpen"); player.volume = 1; }); }) ; function Play() { player.play(); TimePass(); } function stop() { player.pause(); } function Load() { player.load(); TimePass(); } //function quickRate() //{ // player.playbackRate=2; //} //function normalRate() //{ // player.playbackRate=1; //} //function lowerRate() //{ // player.playbackRate=0.5; //}


你可能感兴趣的:(武器安装)