21,882
社区成员
发帖
与我相关
我的任务
分享
<?php
header("Content-Type:text/html;charset=utf-8");
$a = "http://www.abc.com/";
$b = file_get_contents($a);
echo $b;
?>
<html>
<body>
<script type="text/javascript">
$(function() {
getSong();
});
//获取歌曲链接并插入dom中
function getSong() {
var audio = document.getElementById("audio");
var list = ["http://www.efg.com/mp3/Beyond-Buzaiyouyu.mp3", "http://www.efg.com/mp3/MKJ-Time.mp3"];
audio.src = list[Math.floor(Math.random() * list.length)];
audio.loop = false; //歌曲循环
playCotrol(); //播放控制函数
}
//点击播放/暂停
function clicks() {
var audio = document.getElementById("audio");
$("#control").click(function() {
if($(this).find("div").length>0){
$(this).html('<img class="mico" src="iclone/images/mico.png">');
audio.pause();
}else{
$(this).html('<div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div>');
audio.play();//开始播放
dragMove();//并且滚动条开始滑动
}
})
}
//播放时间
function timeChange(time, timePlace) {//默认获取的时间是时间戳改成我们常见的时间格式
var timePlace = document.getElementById(timePlace);
//分钟
var minute = time / 60;
var minutes = parseInt(minute);
if (minutes < 10) {
minutes = "0" + minutes;
}
//秒
var second = time % 60;
seconds = parseInt(second);
if (seconds < 10) {
seconds = "0" + seconds;
}
var allTime = "" + minutes + "" + ":" + "" + seconds + ""
timePlace.innerHTML = allTime;
}
//播放事件监听
function playCotrol() {
audio.addEventListener("loadeddata", //歌曲一经完整的加载完毕
function() {
addListenTouch(); //歌曲加载之后才可以拖动进度条
var allTime = audio.duration;
timeChange(allTime, "allTime");
setInterval(function() {
var currentTime = audio.currentTime;
$("#time .currentTime").html(timeChange(currentTime, "currentTime"));
}, 1000);
clicks();
}, false);
audio.addEventListener("pause",
function() { //监听暂停
$("#control").html('<img class="mico" src="iclone/images/mico.png">');
if (audio.currentTime == audio.duration) {
audio.pause();
audio.currentTime = 0;
}
}, false);
audio.addEventListener("play",
function() { //监听播放
$("#control").html('<div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div><div class="bar"></div>');
dragMove();
}, false);
audio.addEventListener("ended", function() {
getSong();
}, false)
}
//进度条 这里我用的是事件实现进度拖动
var startX, x, aboveX = 0; //触摸时的坐标 //滑动的距离 //设一个全局变量记录上一次内部块滑动的位置
//1拖动监听touch事件
function addListenTouch() {
document.getElementById("drag").addEventListener("touchstart", touchStart, false);
document.getElementById("drag").addEventListener("touchmove", touchMove, false);
document.getElementById("drag").addEventListener("touchend", touchEnd, false);
var drag = document.getElementById("drag");
var speed = document.getElementById("speed");
}
//touchstart,touchmove,touchend事件函数
function touchStart(e) {
e.preventDefault();
var touch = e.touches[0];
startX = touch.pageX;
}
function touchMove(e) { //滑动
e.preventDefault();
var touch = e.touches[0];
x = touch.pageX - startX; //滑动的距离
//drag.style.webkitTransform = 'translate(' + 0+ 'px, ' + y + 'px)'; //也可以用css3的方式
drag.style.left = aboveX + x + "px"; //
speed.style.left = -((window.innerWidth) - (aboveX + x)) + "px";
}
function touchEnd(e) { //手指离开屏幕
e.preventDefault();
aboveX = parseInt(drag.style.left);
var touch = e.touches[0];
var dragPaddingLeft = drag.style.left;
var change = dragPaddingLeft.replace("px", "");
numDragpaddingLeft = parseInt(change);
var currentTime = (numDragpaddingLeft / (window.innerWidth - 30)) * audio.duration;//30是拖动圆圈的长度,减掉是为了让歌曲结束的时候不会跑到window以外
audio.currentTime = currentTime;
}
//3拖动的滑动条前进
function dragMove() {
setInterval(function() {
drag.style.left = (audio.currentTime / audio.duration) * (window.innerWidth - 30) + "px";
speed.style.left = -((window.innerWidth) - (audio.currentTime / audio.duration) * (window.innerWidth - 30)) + "px";
}, 500);
}
</script>
<!--audiostart-->
<audio id="audio" src="" loop="loop" autoplay="autoplay" ></audio>
<!--audio End-->
<!--播放控制按钮start-->
<div id="control">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
<!--播放控制按钮end-->
<!--时间进度条块儿start-->
<section class="progressBar">
<div class="progressBac"></div>
<div class="speed" id="speed"></div>
<div class="drag" id="drag"></div>
</section>
<!--时间进度条块儿end-->
<!--播放时间start-->
<div id="time"><div class="tiemDetail"><span class="currentTime" id="currentTime">00:00</span><span class="allTime" id="allTime">00:00</span></div></div>
<!--播放时间end-->
<!--歌曲信息start-->
<div id="songInfo"></div>
<!--歌曲信息end-->
</body>
</html>