###前提・実現したいこと
JavaScriptで選択された音声ストリームの再生とHTMLの書き換えを行っています。
音声ストリームにはURLと配信元の名前が入っているのですが、名前の表示がうまく行きません。
###ソースコード
html
1<!DOCTYPE html> 2 3<html lang="ja"> 4 5 <head> 6 <meta charset="utf-8"> 7 <title>HTMLで作るネットラジオ</title> 8 <style type="text/css" media="all"> 9 h1 { 10 border-bottom : 1px dotted #ffffff; 11 font-size : 14pt; 12 font-weight: bold; 13 font-family: Tahoma; 14 width : 484px; 15 height: 25px; 16 } 17 ul { 18 list-style : none; 19 margin: 0px; 20 padding: 0px; 21 transform: rotate(0.028deg); 22 } 23 li { 24 width : 200px; 25 background-color:#eeeeee; 26 padding: 2px; 27 border:1px solid #dfdfdf; 28 } 29 li:hover { 30 background-color:#dddddd; 31 border:1px solid #bfbfbf; 32 } 33 #playListArea { 34 width : 223px; 35 height: auto; 36 background-color: #f8f8f8; 37 border:2px solid #707070; 38 overflow: scroll; 39 margin-top:10px; 40 margin-left:auto; 41 margin-right:auto; 42 } 43 #controller { 44 width : 227px; 45 height: 36px; 46 background-color: #505050; 47 margin-left:auto; 48 margin-right:auto; 49 } 50 #ctime { 51 position: relative; 52 left: 40px; 53 top: -30px; 54 color: white; 55 font-size: 10px; 56 font-family: Tahoma; 57 font-weight: bold; 58 transform: rotate(0.028deg); 59 } 60 #playButton { 61 margin-left:2px; 62 margin-top:1px; 63 width:34px; 64 } 65 #music_title { 66 font-weight: bold; 67 color : #0000000; 68 text-shadow: 1px 1px 1px #ffffff, 69 -1px 1px 1px #ffffff, 70 1px -1px 1px #ffffff, 71 -1px -1px 1px #ffffff; 72 transform: rotate(0.028deg); 73 } 74 </style> 75 </head> 76 <body> 77 <div id="playListArea"></div> 78 <div id="controller"> 79 <img src="images/on.png" id="playButton"> 80 <div id="ctime">00:00</div> 81 <div id="music_title">No Play</div> 82 <div> 83 <script type="text/javascript"> 84 var fileList = [ 85 { name : 'Radio Nintendo', url : 'http://play.radionintendo.com/stream' }, 86 { name : 'smooth JAZZ 247', url : 'http://pub6.jazzradio.com:80/jr_smoothjazz247' }, 87 { name : 'Hard House UK', url : 'http://hhuk.netmindz.net:8000/;' }, 88 { name : 'Game-Streams Radio', url : 'http://69.175.94.98:8015/;'}, 89 { name : 'Radio Danz', url :'http://server1.radiodanz.com:8000/;'}, 90 ]; 91 var audioObj = new Audio(); 92 var playFlag = false; 93 var playList = '<ul>'; 94 var crtTime = document.getElementById('ctime'); 95 var pButton = document.getElementById('playButton'); 96 var broadcast = document.getElementById('music_title'); 97 98 for(var i=0; i<fileList.length; i++){ 99 playList += '<li onclick=start_music("'+fileList[i].url+'")>'; //恐らくここで「fileList[i].name」が入っていない? 100 playList += fileList[i].name + '</li>'; 101 } 102 playList += '</ul>'; 103 document.getElementById('playListArea').innerHTML = playList; 104 function start_music(url,name){ 105 audioObj.pause(); 106 audioObj = new Audio(url); 107 broadcast.innerHTML = name; //ここで書き換えたいが、「undefined」と表示される。 108 audioObj.play(); 109 audioObj.addEventListener('timeupdate', function(){ 110 var sec = '0' + Math.floor(audioObj.currentTime % 60); 111 var min = '0' + Math.floor(audioObj.currentTime / 60); 112 sec = sec.substr(sec.length-2, 2); 113 min = min.substr(min.length-2, 2); 114 crtTime.innerHTML = +min+":"+sec; 115 }, true); 116 playFlag = true; 117 pButton.src = 'images/off.png'; 118 } 119 pButton.addEventListener('click', function(){ 120 if (playFlag == false){ 121 playFlag = true; 122 audioObj.play(); 123 pButton.src = 'images/off.png'; 124 }else{ 125 playFlag = false; 126 audioObj.pause(); 127 pButton.src = 'images/on.png'; 128 } 129 }, true); 130 </script> 131 </body> 132 133</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。