1(function (root, factory) { 2 if (typeof define === 'function' && define.amd) { 3 define([], factory); 4 } else if (typeof module === 'object' && module.exports) { 5 module.exports = factory(); 6 } else { 7 root.ttsPlay2 = factory(); 8 } 9})(this, function () { 10 'use strict'; 11 class ttsPlay2 { 12 constructor(option){ 13 this.option = $.extend({ 14 element:"", 15 }, option); 16 console.log(this.option) 17 this.element = $(this.option.element) 18 if(this.element.length==0){ 19 return 20 } 21 let ele = this.element.closest("[class^='e_']") 22 this.eid = ele.attr("class").split(/\s+/)[0] 23 let comp = this.element.closest("[id^='c_']") 24 this.cid = comp.attr("id") 25 this.textList = [] 26 this.audioList = [] 27 this.cText = [] 28 this.player = null 29 this.nowId = "" 30 this.ttsAudio = null 31 this.token = "" 32 this.env = this.getBrowserEnv() 33 if(this.env.isAndroidWeixin){ 34 window.sourcePlayer = {} 35 $require(['/npublic/commonjs/nouglify/audioPlay/webPlayer.js','pl_util'],()=>{ 36 this.sourcePlayer = new webPlayer({ 37 cid:this.cid, 38 eid:this.eid, 39 element:this.option.element, 40 }); 41 window.sourcePlayer[`${this.cid}_${this.eid}`] = this.sourcePlayer; 42 this.init() 43 }) 44 }else{ 45 $require(['css!/npublic/commonjs/nouglify/plyr/plyr.css','/npublic/commonjs/nouglify/plyr/plyr.js','pl_util'],()=>{ 46 this.init() 47 }) 48 } 49 } 50 getBrowserEnv() { 51 const ua = navigator.userAgent.toLowerCase(); 52 return { 53 isWeixin: /micromessenger/.test(ua), 54 isAndroid: /android/.test(ua), 55 isIOS: /(iphone|ipad|ipod|ios)/.test(ua), 56 isX5: /tbs/.test(ua) || /mqqbrowser/.test(ua), 57 isAndroidWeixin: /micromessenger/.test(ua) && /android/.test(ua) 58 }; 59 } 60 //åå§åéåææpådivï¼æ·»å ææ¾æé® 61 init(){ 62 if(this.option.aid && this.option.tid && this.option.cid && this.option.code){ 63 this.getAudioUrl(()=>{ 64 if(this.audioList.length>0){ 65 let ttsReadBtn = this.element.find(".ttsRead") 66 if(ttsReadBtn.length>0){ 67 ttsReadBtn.attr("id",`readBtn_${this.cid}_${this.eid}`) 68 }else{ 69 this.element.prepend(`<a href="javascript:;" class="ttsRead" id="readBtn_${this.cid}_${this.eid}"><svg t="1710380018673" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="https://www.w3.org/2000/svg" p-id="10306" width="200" height="200"><path d="M527.616 121.7024L289.9456 274.3296H171.3664a118.784 118.784 0 0 0-119.296 118.8352v238.08a118.5792 118.5792 0 0 0 119.296 118.784h118.5792l237.6704 152.5248c33.5872 14.592 59.5968-1.024 59.5968-34.048V155.7504c0-32.8704-26.6752-48.2304-59.5968-34.048z m200.2432 191.8464a29.7472 29.7472 0 1 0-43.4176 40.6016 173.1584 173.1584 0 0 1 24.7296 38.912 267.0592 267.0592 0 0 1 26.7264 118.9376 266.8032 266.8032 0 0 1-26.7264 119.0912 174.08 174.08 0 0 1-24.7296 38.9632 29.7472 29.7472 0 1 0 43.4688 40.6016 225.28 225.28 0 0 0 34.6624-53.3504 326.3488 326.3488 0 0 0 32.768-145.408 326.2976 326.2976 0 0 0-32.768-145.3568 226.9184 226.9184 0 0 0-34.7136-53.1968z m182.3232-36.8128c-24.0128-40.704-48.2816-68.864-65.3824-84.0192a29.7472 29.7472 0 0 0-39.5776 44.3904 192.1536 192.1536 0 0 1 15.872 16.7936 363.0592 363.0592 0 0 1 37.888 53.2992 398.6944 398.6944 0 0 1 55.296 204.8 398.6944 398.6944 0 0 1-55.3472 205.312 372.736 372.736 0 0 1-37.7856 53.0432 196.9152 196.9152 0 0 1-15.872 16.7424 29.7472 29.7472 0 0 0 39.5264 44.4416c17.0496-15.36 41.2672-43.3152 65.3312-84.0192a458.24 458.24 0 0 0 63.5392-235.52 456.9088 456.9088 0 0 0-63.488-235.52z" p-id="10307"></path></svg><span></span></a>`) 70 } 71 this.element.find(".ttsRead").show() 72 this.renderAudioClick() 73 this.renderCss() 74 }else{ 75 this.element.find(".ttsRead").remove() 76 } 77 }) 78 } 79 } 80 renderCss(){ 81 if($('#audioCss').length>0){ 82 return 83 } 84 let css = `.ttsRead{color:#105850}` 85 let style = document.createElement('style'); 86 style.type = 'text/css'; 87 style.id = 'audioCss' 88 style.innerHTML = css; 89 document.getElementsByTagName('head')[0].appendChild(style); 90 } 91 // 请æ±å端Url 92 getAudioUrl(callback){ 93 $require(['cmsAjax'],(c)=>{ 94 let url = "/fwebapi/visitor/lowcode/audio/getContentAudios" 95 let p = { 96 appCode:this.option.aid, 97 sourceCode:this.option.tid, 98 contentId:this.option.cid, 99 code:this.option.code 100 } 101 c.cmsAjax.get(url,p).then((res)=>{ 102 console.log(res) 103 try{ 104 this.audioList = res.data[this.option.code].list 105 this.audioList = this.audioList.map(e=>{ 106 return e=$.handleDataFile(e) 107 }) 108 callback() 109 }catch(e){ 110 callback() 111 } 112 }) 113 }) 114 } 115 renderAudioClick(){
116 this.element.on("click",".ttsRead",(e)=>{ 117 let btn = $(e.currentTarget) 118 let id = btn.attr("id") 119 if(id == this.nowId){ 120 if(btn.hasClass('isPaused')){ 121 if(this.env.isAndroidWeixin){ 122 this.sourcePlayer.play() 123 }else{ 124 this.audioPlay() 125 } 126 btn.removeClass('isPaused') 127 }else{ 128 if(this.env.isAndroidWeixin){ 129 this.sourcePlayer.pause() 130 }else{ 131 this.audioStop() 132 } 133 btn.addClass('isPaused') 134 } 135 return 136 } 137 this.playList = JSON.parse(JSON.stringify(this.audioList)) 138 this.nowId = id 139 this.element.find(".plyr").remove() 140 this.element.find(".ttsAudio").remove() 141 this.element.find(".ttsRead").removeClass('isPaused') 142 if(this.env.isAndroidWeixin){ 143 this.sourcePlayer.stop(); 144 this.sourcePlayer.setPlaylist(this.playList); 145 this.sourcePlayer.onTrackEnd = (trackUrl) => { 146 // console.log(`å·²å®æææ¾: ${trackUrl}`); 147 }; 148 this.sourcePlayer.onPlaylistEnd = () => { 149 console.log('ææ¾åè¡¨å ¨é¨ææ¾å®æ¯'); 150 this.nowId = "" 151 }; 152 this.sourcePlayer.startPlaylist(); 153 return 154 }else{ 155 this.processAudioQueue(true) 156 } 157 }) 158 } 159 // é忏²æ 160 processAudioQueue(k){ 161 if(this.playList.length==0){ 162 this.playFirst(()=>{ 163 console.log('éå宿') 164 this.nowId = "" 165 }) 166 return 167 } 168 let item = this.playList.shift() 169 let item2 = null 170 if(k){ 171 item2 = this.playList.shift() 172 } 173 this.readAudio(item,item2).then(()=>{ 174 this.processAudioQueue() 175 }) 176 } 177 // 弿¥æå ¥é³é¢ï¼å¹¶æ§å¶ææ¾ 178 readAudio(url1,url2){ 179 return new Promise((resolve, reject) => { 180 this.appendAudio(url1) 181 if(url2){ 182 this.appendAudio(url2) 183 } 184 setTimeout(()=>{ 185 this.playFirst(resolve) 186 },500) 187 }); 188 } 189 playFirst(resolve){ 190 this.ttsAudio = this.element.find('.ttsAudio')[0]; 191 if (this.ttsAudio) {
192 let id = this.ttsAudio.id 193 this.audioPlay() 194 this.ttsAudio.addEventListener('ended',()=>{ 195 $(this.ttsAudio).parent(".plyr").remove(); 196 $(this.ttsAudio).remove(); 197 if(resolve){ 198 resolve() 199 } 200 }); 201 const player = new Plyr('#'+ id, {}); 202 // $("#"+ id).parent(".plyr").show() 203 }else{ 204 if(resolve){ 205 resolve() 206 } 207 } 208 } 209 // æå ¥é³é¢ 210 appendAudio(url){ 211 url = $.handleDataFile(url) 212 let id = 'ttsAudio'+ +new Date(); 213 const audio = document.createElement('audio'); 214 audio.className = 'ttsAudio'; 215 audio.id = id; 216 audio.preload = 'auto'; 217 audio.src = url; 218 this.element.append(audio) 219 } 220 // ææ¾é³é¢ 221 audioPlay(){ 222 if(this.ttsAudio){ 223 this.stopOther() 224 this.ttsAudio.play(); 225 } 226 } 227 // æåé³é¢ 228 audioStop(){ 229 if(this.ttsAudio){ 230 this.ttsAudio.pause() 231 } 232 } 233 stopOther(){ 234 let otherAudio = $('.ttsAudio').not(this.ttsAudio) 235 otherAudio.each((i,item)=>{ 236 item.pause() 237 $(item).parents("[ttsplay]").find(".ttsRead").addClass("isPaused") 238 }) 239 } 240 stopOtherSourcePlayer(){ 241 for (let key in window.sourcePlayer) { 242 if (key != `${this.cid}_${this.eid}`) { 243 window.sourcePlayer[key].pause(); 244 } 245 } 246 } 247 } 248 return ttsPlay2; 249});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.