Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created January 16, 2016 03:17
Show Gist options
  • Save chikoski/b527f4eb09a09f1f794d to your computer and use it in GitHub Desktop.
Save chikoski/b527f4eb09a09f1f794d to your computer and use it in GitHub Desktop.
var player = document.querySelector("audio");
var fileNameElement = document.querySelector("#fileName");
var changeButton = document.querySelector("#change");
changeButton.addEventListener("click", changeMusic);
function changeMusic(){
var fileName = fileNameElement.value;
if(fileName.length > 0){
doChangeMusic(fileName);
}
}
function doChangeMusic(fileName){
player.src = fileName;
}
<!doctype html>
<html>
<head>
<title>音楽</title>
<meta charset="utf-8">
</head>
<body>
<audio src="09.mp3" preload controls>
</audio>
<h3>再生するファイル</h3>
<input type="text" id="fileName">
<button id="change">変更</button>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment