HTML 5のaudio:キーボード制御音楽再生

1465 ワード

今日の午后audioを勉强して游んで、机能はとても简単で、主にキーボードを通じて音楽の放送をコントロールします.
 
HTML:


 HTML5 







JavaScript:
var audio = document.getElementById('audio');
audio.play();
document.body.onkeyup = function(e){  //     audio,      audio        
	var event = e || window.event;
	console.log('keyCode : ' + event.keyCode);
	console.log('volume : ' + audio.volume);
	if(!arguments.callee.pause){
		arguments.callee.pause = false;
	}
	if(event.keyCode == 40){  // 
		try {
			audio.volume -= 0.1;
		}catch(e){
			console.log('audio.volume is already the smallest : ' + audio.volume);
		}
	}else if(event.keyCode == 38){  // 
		try {
			audio.volume += 0.1;
		}catch(e){
			console.log('audio.volume is already the largest : ' + audio.volume);
		}
	}else if(event.keyCode == 39){  // 
		audio.currentTime += 10;
	}else if(event.keyCode == 37){  // 
		audio.currentTime -= 10;
	}else if(event.keyCode == 32){
		if(!arguments.callee.pause){
			arguments.callee.pause = true;
			audio.pause();
		}else{
			arguments.callee.pause = false;
			audio.play();
		}
	}
	console.log('currentTime : ' + audio.currentTime);
};

  
  
:https://www.cnblogs.com/realwall/archive/2012/06/24/2560213.html