HTML5可视化mp3音乐播放器代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 HTML5可视化mp3音乐播放器代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

HTML5可视化mp3音乐播放器代码

HTML代码(index.html):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
	*{
		margin:0;
		padding:0;
	}
	.img{
		animation:rotatez 7s;
		animation-timing-function:linear;
		animation-iteration-count:infinite;
	}
	@keyframes rotatez{
		0%{transform:rotateZ(0deg);}
        100%{transform:rotateZ(360deg);}
	}
	table td{
       border:1px solid #fff;
       text-align:center;
       font-size:30px;
       color:#fff;
	}
</style>
<title>HTML5可视化mp3音乐播放器代码</title>
</head>
<body style="background-color:#fff;">
    <script type="text/javascript" src="index.js">
	</script>
	<canvas id="canvas" style="border:0px solid #f00">
	</canvas>
	<div id='crt' style="width:100%; height:150px; border:0px solid #fff; background-color:#099; text-align:center;">
    
	  <table cellspacing="0" style="width:100%;  height:100%; border:1px solid #fff;">
        <td style="width:25%;">
         <table id="msclist" class="msclist" style="width:100%; height:100%; background-color:#000;">
           
         </table>
        </td>
        <td style="width:50%;">
          <div onClick="last()" style="width:30%; cursor:pointer; line-height:130px; background-color:#63F; margin-left:3%; height:100%; float:left;">
          上一曲
          
          </div>
          <div onClick="run()" style="width:30%; cursor:pointer; background-color:#63F; margin-left:2%; height:100%; float:left;">
            <img id="img" src="img/friend.jpg" style=" margin-top:10px; height:120px; width:auto; border-radius:100%;" />
            
          </div>
          <div onClick="next()" style="width:30%; cursor:pointer; line-height:130px; background-color:#63F; margin-left:2%; height:100%; float:left;">
          下一曲
          </div>
        </td>
        <td style="width:25%;">
         <form oninput="cgcolor()">
          <table style="width:100%; height:100%; ">
           <tr>
            <td style="cursor:pointer;  background-color:#09C;" onClick="canvascg(1)">球状</td>
            <td style="cursor:pointer; background-color:#09C;" onClick="canvascg(2)">柱形</td>
            <td style="cursor:pointer; background-color:#09C;" onClick="canvascg(3)">线条</td>
           </tr>
           <!--<tr>
           
            <td id="td1" style="cursor:pointer; font-size:18px; background-color:#09C;">开始<br /><input type="color" id='startc' /></td>
            
            <td style="cursor:pointer; font-size:18px; background-color:#09C;">中点<br /><input type="color" id='contentc' /></td>
            <td style="cursor:pointer; font-size:18px; background-color:#09C;">末端<br /><input type="color" id='endc' /></td>
            
           </tr>-->
          </table>
           </form>
        </td>
      </table>
     
	</div>
    <audio id="audio"  style=" ">
	</audio>
</body>
</html>







JS代码(index.js):

 window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext;
	var msc=['朋友-谭咏麟','红日-李克勤','解放-羽泉'];
	var mscsrc=['msc/friend.mp3','msc/红日.mp3','msc/解放.mp3'];
	var mscid=0;
	function playa(id){
	mscid=id;
	document.getElementById('audio').src=mscsrc[mscid];
	run();
	cgcss();
}
function next(){
	if(mscid>(msc.length-2))mscid=0;
	else mscid++;
	document.getElementById('audio').src=mscsrc[mscid];
	run();
	cgcss();
}
function last(){
	if(mscid<1) mscid=msc.length-1;
	else mscid--;
	document.getElementById('audio').src=mscsrc[mscid];
	run();
	cgcss();
}
function cgcss(){
	document.getElementById("1").style.backgroundColor="#000";
	document.getElementById("2").style.backgroundColor="#000";
	document.getElementById("0").style.backgroundColor="#000";
	document.getElementById(mscid).style.backgroundColor="#f00";
}
var cssn=2;
	var voicec1=["#0f0","#f00","#f0f"];
	function cgcolor(){
	voicec1[0]=document.getElementById('startc').value;
	voicec1[1]=document.getElementById('startc').value;
	voicec1[2]=document.getElementById('startc').value;
}
window.onload=function play(){
	var $=function(id){
	return document.getElementById(id);
}
var canvas=$('canvas');
	var audio=$('audio');
	for(var a=0;
	a<msc.length;
	a++){
	var msclist=$('msclist').innerHTML;
	$('msclist').innerHTML=msclist+"<tr><td id='"+a+"' onclick='playa(this.id)' style='cursor:pointer;
	'>"+msc[a]+"</td></tr>";
}
cgcss();
	audio.src=mscsrc[mscid];
	var ctr=$('ctr');
	var ctx=canvas.getContext('2d');
	var actx=new AudioContext();
	color=ctx.createLinearGradient(canvas.width*.5,0,canvas.width*.5,300);
	color.addColorStop(0,voicec1[0]);
	color.addColorStop(.5,voicec1[1]);
	color.addColorStop(1,voicec1[2]);
	colort=ctx.createLinearGradient(canvas.width*.5,300,canvas.width*.5,600);
	colort.addColorStop(0,"rgba(125,225,133,0.7)");
	colort.addColorStop(.5,"rgba(225,225,0,0.1)");
	colort.addColorStop(1,"rgba(125,0,133,0)");
	canvas.width=window.innerWidth;
	canvas.height=window.innerHeight*.7;
	var analyser=actx.createAnalyser();
	var audioSrc=actx.createMediaElementSource(audio);
	audioSrc.connect(analyser);
	analyser.connect(actx.destination);
	var num=80;
	function draw(){
	var voicehigh=new Uint8Array(analyser.frequencyBinCount);
	analyser.getByteFrequencyData(voicehigh);
	var step=Math.round(voicehigh.length/num);
	ctx.clearRect(0,0,canvas.width,canvas.height);
	ctx.beginPath();
	for(var i=1;
	i<num;
	i++){
	var value=voicehigh[step*i];
	switch(cssn){
	case 1:ctx.fillStyle=color;
	ctx.beginPath();
	ctx.arc(i*50,canvas.height*.5,value*.3,0,Math.PI*2,true);
	ctx.fill();
	break;
	case 2:ctx.fillStyle=color;
	ctx.fillRect(i*10+canvas.width*.5,250,7,-value+1);
	ctx.fillRect(canvas.width*.5-(i-1)*10,250,7,-value+1);
	ctx.fill();
	ctx.fillStyle=colort;
	ctx.fillRect(i*10+canvas.width*.5,250,7,value+1);
	ctx.fillRect(canvas.width*.5-(i-1)*10,250,7,value+1);
	break;
	case 3:moveTo(0,canvas.height*.5);
	ctx.lineTo(i*7+canvas.width*.5,-value+canvas.height*.5);
	ctx.strokeStyle="#f00";
	ctx.stroke();
	break;
}
//ctx.stroke();
}
requestAnimationFrame(draw);
}
draw();
}
function canvascg(n){
	cssn=n;
}
function run(){
	var audio=document.getElementById('audio');
	var imgcss=document.getElementById('img');
	if(audio.paused)audio.play(),imgcss.className='img';
	elseaudio.pause(),imgcss.className='';
}
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
13.41 MB
Html Js 播放器
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章