通用评论

index.js.map 8.4KB

1
  1. {"version":3,"sources":["../../../src/components/AudioPlayer/index.js"],"names":["dayjs","extend","durationPlugin","utcPlugin","AudioPlayer","props","state","duration","currentDuration","isPlaying","isLoading","player","src","oncanplay","setState","event","target","onended","onpause","onplay","onplaying","ontimeupdate","currentTime","prevProps","pause","playerList","document","getElementsByTagName","Array","from","forEach","paused","play","playIconElem","iconLoading","btnAudioPlay","ref","display","clickPlayOrPause","getPlayIcon","value","utc","asMilliseconds","format","React","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;;;;AACA;;AACA;;;;AACA;;;;;;;;;;;;AAEAA,gBAAMC,MAAN,CAAaC,kBAAb;AACAF,gBAAMC,MAAN,CAAaE,aAAb;;IAEMC,W;;;AACJ,uBAAYC,KAAZ,EAAmB;AAAA;;AAAA,0HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,gBAAU,CADC;AAEXC,uBAAiB,CAFN;AAGXC,iBAAW,KAHA;AAIXC,iBAAW;AAJA,KAAb;AAFiB;AAQlB;;;;wCAEmB;AAAA;;AAClB,UAAI,KAAKC,MAAT,EAAiB;AAAA,YACPC,GADO,GACC,KAAKP,KADN,CACPO,GADO;;AAEf,aAAKD,MAAL,CAAYE,SAAZ,GAAwB;AAAA,iBACtB,OAAKC,QAAL,CAAc,EAAEP,UAAUQ,MAAMC,MAAN,CAAaT,QAAzB,EAAd,CADsB;AAAA,SAAxB;AAEA,aAAKI,MAAL,CAAYM,OAAZ,GAAsB;AAAA,iBACpB,OAAKH,QAAL,CAAc,EAAEL,WAAW,KAAb,EAAoBD,iBAAiB,CAArC,EAAd,CADoB;AAAA,SAAtB;AAEA,aAAKG,MAAL,CAAYO,OAAZ,GAAsB;AAAA,iBACpB,OAAKJ,QAAL,CAAc,EAAEL,WAAW,KAAb,EAAoBC,WAAW,KAA/B,EAAd,CADoB;AAAA,SAAtB;AAEA,aAAKC,MAAL,CAAYQ,MAAZ,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,UAC6BF,QAD7B,WAC6BA,QAD7B;;AAEP,aACE;AAAA;AAAA,UAAK,WAAU,oCAAf;AAEE;AACE,eAAK,mBAAO;AACV,mBAAKI,MAAL,GAAcyB,IAAd;AACD,WAHH;AAIE,iBAAO,EAAEC,SAAS,MAAX;AAJT,UAFF;AAQE;AAAA;AAAA;AACE,uBAAU,MADZ;AAEE,qBAAS,mBAAM;AACb,qBAAKC,gBAAL,CAAsB7B,SAAtB;AACD;AAJH;AAMG,eAAK8B,WAAL;AANH,SARF;AAgBE;AACE,gBAAM,KADR;AAEE,qBAAU,QAFZ;AAGE,0BAAgB,KAHlB;AAIE,iBAAO/B,eAJT;AAKE,eAAKD,QALP;AAME,oBAAU,yBAAS;AACjB,gBAAI,OAAKI,MAAT,EAAiB;AACf,qBAAKA,MAAL,CAAYW,WAAZ,GAA0BkB,KAA1B;AACD;AACF;AAVH,UAhBF;AA4BE;AAAA;AAAA,YAAM,WAAU,MAAhB;AACGxC,0BACEyC,GADF,CACMzC,gBAAMO,QAAN,CAAeC,eAAf,EAAgC,SAAhC,EAA2CkC,cAA3C,EADN,EAEEC,MAFF,CAES,OAFT,CADH;AAAA;AAKG3C,0BACEyC,GADF,CACMzC,gBAAMO,QAAN,CAAeA,QAAf,EAAyB,SAAzB,EAAoCmC,cAApC,EADN,EAEEC,MAFF,CAES,OAFT;AALH;AA5BF,OADF;AAwCD;;;;EA9HuBC,gBAAMC,S;;kBAiIjBzC,W","file":"index.js","sourcesContent":["import React from \"react\";\nimport { Slider, Icon } from \"antd\";\nimport dayjs from \"dayjs\";\nimport durationPlugin from \"dayjs/plugin/duration\";\nimport utcPlugin from \"dayjs/plugin/utc\";\nimport \"./index.less\";\nimport iconLoading from \"../../assert/loading.gif\";\nimport btnAudioPlay from \"../../assert/btn_audio_play.png\";\n\ndayjs.extend(durationPlugin);\ndayjs.extend(utcPlugin);\n\nclass AudioPlayer extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n duration: 0,\n currentDuration: 0,\n isPlaying: false,\n isLoading: false\n };\n }\n\n componentDidMount() {\n if (this.player) {\n const { src } = this.props;\n this.player.oncanplay = event =>\n this.setState({ duration: event.target.duration });\n this.player.onended = () =>\n this.setState({ isPlaying: false, currentDuration: 0 });\n this.player.onpause = () =>\n this.setState({ isPlaying: false, isLoading: false });\n this.player.onplay = () =>\n this.setState({ isPlaying: false, isLoading: true });\n this.player.onplaying = () =>\n this.setState({ isPlaying: true, isLoading: false });\n this.player.ontimeupdate = event =>\n this.setState({ currentDuration: event.target.currentTime });\n this.player.src = src;\n }\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.src !== prevProps.src) {\n this.player.oncanplay = event =>\n this.setState({ duration: event.target.duration });\n this.player.onended = () =>\n this.setState({ isPlaying: false, currentDuration: 0 });\n this.player.onpause = () =>\n this.setState({ isPlaying: false, isLoading: false });\n this.player.onplay = () =>\n this.setState({ isPlaying: false, isLoading: true });\n this.player.onplaying = () =>\n this.setState({ isPlaying: true, isLoading: false });\n this.player.ontimeupdate = event =>\n this.setState({ currentDuration: event.target.currentTime });\n this.player.src = this.props.src;\n }\n }\n\n clickPlayOrPause(isPlaying) {\n if (!this.player) {\n return;\n }\n if (isPlaying) {\n this.player.pause();\n } else {\n // 如果是播放,先暂停其他的播放\n const playerList = document.getElementsByTagName(\"audio\");\n if (playerList) {\n Array.from(playerList).forEach(player => {\n if (!player.paused) {\n player.pause();\n }\n });\n }\n this.player.play();\n }\n }\n\n getPlayIcon() {\n const { isPlaying, isLoading } = this.state;\n let playIconElem;\n\n if (isLoading) {\n playIconElem = (\n <img className=\"icon-loading\" src={iconLoading} alt=\"iconLoading\" />\n );\n } else if (isPlaying) {\n playIconElem = <Icon className=\"pause\" type=\"pause\" />;\n } else {\n playIconElem = <img className=\"icon-loading\" src={btnAudioPlay} alt=\"iconPlaying\" />\n }\n return playIconElem;\n }\n\n render() {\n const { currentDuration, isPlaying, duration } = this.state;\n return (\n <div className=\"comment-item-speak-audio-container\">\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio\n ref={ref => {\n this.player = ref;\n }}\n style={{ display: \"none\" }}\n />\n <span\n className=\"icon\"\n onClick={() => {\n this.clickPlayOrPause(isPlaying);\n }}\n >\n {this.getPlayIcon()}\n </span>\n <Slider\n step={0.001}\n className=\"slider\"\n tooltipVisible={false}\n value={currentDuration}\n max={duration}\n onChange={value => {\n if (this.player) {\n this.player.currentTime = value;\n }\n }}\n />\n <span className=\"time\">\n {dayjs\n .utc(dayjs.duration(currentDuration, \"seconds\").asMilliseconds())\n .format(\"mm:ss\")}\n /\n {dayjs\n .utc(dayjs.duration(duration, \"seconds\").asMilliseconds())\n .format(\"mm:ss\")}\n </span>\n </div>\n );\n }\n}\n\nexport default AudioPlayer;\n"]}