자작 - audio 태그를 이용한 mp3 리스트 플레이어
마스터욱
0
25
0
0
2017-05-30 22:12:46
소스코드
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 | <?php $dbDatas = array(); if(!$_GET['idx']){ exit("고유번호가 없습니다."); } //print_r2($_GET['idx']);exit; if(sizeof($_GET['idx']) == 1){ $dbDatas[0] = $core['databank']->getInfoMp3($_GET['idx']); } else{ $dbDatas = $core['databank']->getInfoMp3List($_GET['idx']); } if(!$dbDatas[0]['idx']){ exit("존재하지 않는 자료입니다."); } ?> <script type="text/javascript"> var mp3Play = function(param){ var _self = this; this.json = param.json; this.jKey = 0; this.oldKey = null; this.audioId = param.audioId; this.audioSoId = param.audioSoId; this.audioList = param.audioList; this.ready = function(){ document.getElementById(_self.audioId).onended = function(){ _self.listChange(); }; $(document).off("click", "#mp3ListRow"); $(document).on ("click", "#mp3ListRow", function(){ var json = $.parseJSON($(this).attr("json")); _self.listChange(json.key); }); _self.listChange(); } this.listChange = function(clickKey){ if(clickKey != undefined){ _self.jKey = clickKey; } if(_self.oldKey != null){ $("#" + _self.audioList + _self.oldKey).css("background-color", "#FFFFFF"); } $("#" + _self.audioList + _self.jKey).css("background-color", "#e1e1e1"); document.getElementById(_self.audioSoId).src = _self.json[_self.jKey]['file']; document.getElementById(_self.audioId).load(); document.getElementById(_self.audioId).play(); _self.oldKey = _self.jKey; _self.jKey++; if(_self.json[_self.jKey] == undefined){ _self.jKey = 0; } } } $(document).ready(function(){ var mp3Play_1 = new mp3Play({ "json" : $.parseJSON('<?=json_encode($dbDatas);?>'), "audioId" : "myAudio", "audioSoId" : "audioSrc", "audioList" : "audioList_" }); mp3Play_1.ready(); }); </script> <div class="modal-dialog" style="border:1px solid #e1e1e1;"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="databankMp3CloseBtn">×</button> <h4 class="modal-title"> <i class="fa fa-music" aria-hidden="true"></i> <?=$dbDatas[0]['file_name']?> <?php $cnt = sizeof($dbDatas); if($cnt > 1){ echo "외 " . ($cnt - 1) . "개"; } ?> </h4> </div> <div class="modal-body"> <div class="row"> <div class="col-md-12"> <audio controls xloop autoplay xpreload="none" controls="controls" xloop="loop" autoplay="autoplay" style="width:100%;" id="myAudio"> <source src="" type="audio/mp3" id="audioSrc" /> </audio> </div> <div class="col-md-12"> <ul class="list-group"> <?php foreach($dbDatas as $key => $row){ ?> <li class="list-group-item text-left" id="audioList_<?=$key?>" json='{"key":"<?=$key?>","src":"<?=$row['file']?>"}'> <a class="btn btn-primary btn-sm" style="float:right;" id="mp3ListRow" json='{"key":"<?=$key?>"}'><i class="fa fa-play" aria-hidden="true"></i> PLAY</a> <?=$row['file_name']?> </li> <?php } ?> </ul> </div> </div> </div> <div class="modal-footer"> <div class="btn btn-group"> <button type="button" class="btn btn-danger" id="databankMp3CloseBtn" data-dismiss="modal">닫기</button> </div> </div> </div> </div> |