Skip to content

Commit

Permalink
daily commit 不知道干了啥
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchengz committed Dec 2, 2017
1 parent 412cc39 commit 7aad386
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
Binary file added src/assets/music.mp3
Binary file not shown.
3 changes: 1 addition & 2 deletions src/components/Music.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@
width: 94%;
height: 20px;
padding: 8px 3%;
/*padding-bottom: 5px;*/
margin-bottom: 5px;
border-bottom: 1px solid #EEE;
overflow: hidden;
text-overflow:ellipsis;
text-overflow: ellipsis;
white-space: nowrap;
}
.result span:last-child{
Expand Down
6 changes: 6 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import index from '@/components/Index'
import music from '@/components/Music'
import form from '@/components/Form'
import detail from '@/components/Detail'
import map from '@/components/Map'

Vue.use(Router)

Expand All @@ -28,6 +29,11 @@ export default new Router({
path: '/detail/:hash',
name: 'Detail',
component: detail
},
{
path: '/map',
name: 'Map',
component: map
}

]
Expand Down
2 changes: 2 additions & 0 deletions src/utils/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ http.jsonp = function(url,data){

var funcName = callBack + ++couter;


data.callback = funcName;

var fullUrl = url + '?' + queryString(data);
console.log(fullUrl);

return new Promise((res,rej) => {
window[funcName] = res;
Expand Down
76 changes: 76 additions & 0 deletions src/utils/music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// music.js


let music = {}


var canvas = null;
var data = null;
var g = null;
var analyser = null;

function draw(){
// g.clearRect(0,0,1024,300);

g.fillStyle = 'rgba(255,255,255,.8)'

g.fillRect(0,0,1024,300)

// analyser.getByteTimeDomainData(data);
analyser.getByteFrequencyData(data);
// window.requestAnimationFrame(draw);


g.beginPath();
g.moveTo(0,128);
g.strokeStyle = '#BBB';
g.fillStyle = '#BBB';
g.lineWidth = 2;

// data.forEach((y,x) => {
// g.lineTo(x,y);
// })
for (var i = 0; i < data.length; i+=11) {
var x = i,y = data[i];
g.fillRect(x,300 - y,10,300);
}
g.stroke();


}


music.init = function(audio,_canvas){

canvas = _canvas;
canvas.width = 1024;
canvas.height = 300;
g = canvas.getContext('2d');

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioCtx.createAnalyser();

var source = audioCtx.createMediaElementSource(audio);
source.connect(analyser);
analyser.connect(audioCtx.destination);

analyser.fftSize = 2048;
var bufferLength = analyser.frequencyBinCount;
data = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(data);


draw();

setInterval(draw,36);

// setInterval(function(){
// analyser.getByteTimeDomainData(data);
// console.log(data);
// },1000)
}



export default music

Binary file added static/music.mp3
Binary file not shown.

0 comments on commit 7aad386

Please sign in to comment.