-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepeater.html
233 lines (200 loc) · 6.02 KB
/
repeater.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<title>复读机(HTML5)</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.fancybox-1.3.4.css" media="screen" />
<style type="text/css">
* {margin: 0;padding:0;}
body {font-size:14px;color:#777;background:url(bg.png) repeat-x;}
#container div {margin:2px 0;}
#filename {color:#666;font-weight:bold;text-align:center;}
#container {width:333px;margin:100px auto;
border:1px solid #88c4e7;padding:5px;
-webkit-box-shadow: 1px 1px 5px 4px #b6d9ed;
-webkit-border-radius: 5px;border-radius: 5px;
box-shadow: 1px 1px 5px 4px #b6d9ed;}
.dragover {background:#94c3e4;}
#files {visibility: hidden;position: absolute;}
#repeatControl button {width: 66px;padding:0 6px;
border:1px solid #b6d9ed;background:#fff;
line-height:25px;cursor: pointer;
}
#repeatControl button:hover {background:#339ad6;color:white;}
#favorlist_ul {border:1px solid #f0f0f0;padding:5px 5px;
min-height:50px;}
#favorlist_ul li {list-style:decimal;cursor: pointer;}
#tips {
float: right;
}
#tips li { font-size:0.8em;}
#tips li a {color:#888;text-decoration:none;}
</style>
<body>
<input type="file" id="files" name="files[]" />
<div id="container">
<div id="filename">拖拽文件或者选择增加文件</div>
<div>
<audio id="audioPlayer" controls="controls">
Your browser does not support the audio element.
</audio>
<img width="29px" height="32px" style="cursor:pointer" onclick="$('#files').click()" src="add.png" />
</div>
<div id="repeatControl">
<img src="pre.png" onclick="preA()" />
<button onclick="setA()" id="btnAtime">A</button>
<img src="next.png" onclick="nextA()" />
<img src="pre.png" onclick="preB()" />
<button onclick="setB()" id="btnBtime">B</button>
<img src="next.png" onclick="nextB()" />
<button onclick="clearAb()">清除</button>
<button onclick="addFavor()" id="favor"><img src="star_add.png" height="13px" /> 收藏</button>
</div>
<div>
<div id="tips">
<dl>
<li><a href="how.png" class="how">如何使用?</a></li>
<li><a href="http://t.qq.com/holinhe" target="_blank">@holinhe</a></li>
</dl>
</div>
<dl id="favorlist_ul">
<span style="color:#ccc;font-size:0.8em">收藏内容列表</span>
</dl>
</div>
</div>
<script>
$(function(){
$("a.how").fancybox();
});
function handleFileSelect1(evt) {
var files = evt.target.files; // FileList object
var file = files[0];
console.log(file);
openFile(file)
}
$('#files').bind('change', handleFileSelect1);
</script>
<script type="text/javascript">
var aTime = 0;
var bTime = 0;
var favorList = new Array();
function clearAb() {
aTime = 0;
bTime = 0;
$("#btnAtime").html("A");
$("#btnBtime").html("B");
}
function preA() {
if (aTime < 1) {return};
aTime -= 1;
$("#btnAtime").html("A[" + aTime + "]");
}
function preB() {
if (bTime < 1) {return};
bTime -= 1;
$("#btnBtime").html("B[" + bTime + "]");
}
function nextA() {
aTime += 1;
$("#btnAtime").html("B[" + aTime + "]");
}
function nextB() {
if (bTime < 1) {return};
bTime += 1;
$("#btnBtime").html("B[" + bTime + "]");
}
function addFavor() {
if (bTime < 1) {return;}
var arr = new Array();
arr.push(aTime);
arr.push(bTime);
favorList.push(arr.join(","));
renderFavorList();
}
function playFavor(i) {
var item = favorList[i];
var arr_ = item.split(",");
aTime = arr_[0];
bTime = arr_[1];
$("#btnAtime").html("A[" + aTime + "]");
$("#btnBtime").html("B[" + bTime + "]");
repeatAb();
}
function renderFavorList() {
var arr = [];
for (var i = 0; i < favorList.length; i++) {
var item = favorList[i];
// console.log(item);
var arr_ = item.split(",");
arr.push("<li onclick='playFavor(" + i + ")'>" + arr_[0] + " - " + arr_[1] + "</li>");
}
$("#favorlist_ul").html(arr.join(""));
}
if (window.webkitURL) window.URL = window.webkitURL;
function openFile(file) {
favorList = new Array();
renderFavorList();
$("#repeatControl *").attr("disabled", true);
clearAb();
$("#filename").html("" + file.fileName);
// console.log(file);
var objectURL = window.URL.createObjectURL(file);
console.log(objectURL);
myAudio.src = objectURL;
myAudio.play();
}
function setA() {
aTime = parseInt(myAudio.currentTime);
$("#btnAtime").html("A[" + aTime + "]");
}
function setB() {
bTime = parseInt(myAudio.currentTime);
$("#btnBtime").html("B[" + bTime + "]");
repeatAb();
}
function repeatAb() {
myAudio.pause();
myAudio.currentTime = aTime;
myAudio.play();
}
function checkRepeat() {
if (bTime > 1 && myAudio.currentTime > bTime) {
repeatAb();
}
}
</script>
<script>
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
$("body").removeClass("dragover");
var files = evt.dataTransfer.files; // FileList object.
var file = files[0];
openFile(file);
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
$("body").addClass("dragover");
}
// Setup the dnd listeners.
var dropZone = document.body;
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
</script>
<script type="text/javascript">
var myAudio = $("#audioPlayer").get(0);
myAudio.addEventListener('canplay', function() {
$("#repeatControl *").attr("disabled", false);
});
myAudio.addEventListener('timeupdate', function() {
checkRepeat();
}, false);
$("#repeatControl *").attr("disabled", true);
</script>
<span style="display:none">
<script src="http://s16.cnzz.com/stat.php?id=4218331&web_id=4218331&show=pic" language="JavaScript"></script>
</span>
</body>
</html>