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","ref","display","clickPlayOrPause","getPlayIcon","value","utc","asMilliseconds","format","React","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;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,iBAAM,OAAKJ,QAAL,CAAc,EAAEL,WAAW,KAAb,EAAoBC,WAAW,KAA/B,EAAd,CAAN;AAAA,SAAtB;AACA,aAAKC,MAAL,CAAYQ,MAAZ,GAAqB;AAAA,iBAAM,OAAKL,QAAL,CAAc,E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AAK,mBAAO;AACV,mBAAKI,MAAL,GAAcwB,IAAd;AACD,WAHH;AAIE,iBAAO,EAAEC,SAAS,MAAX;AAJT,UAFF;AAQE;AAAA;AAAA;AACE,uBAAU,MADZ;AAEE,qBAAS,mBAAM;AACb,qBAAKC,gBAAL,CAAsB5B,SAAtB;AACD;AAJH;AAME,eAAK6B,WAAL;AANF,SARF;AAgBE;AACE,gBAAM,KADR;AAEE,qBAAU,QAFZ;AAGE,0BAAgB,KAHlB;AAIE,iBAAO9B,eAJT;AAKE,eAAKD,QALP;AAME,oBAAU,yBAAS;AACjB,gBAAI,OAAKI,MAAT,EAAiB;AACf,qBAAKA,MAAL,CAAYW,WAAZ,GAA0BiB,KAA1B;AACD;AACF;AAVH,UAhBF;AA4BE;AAAA;AAAA,YAAM,WAAU,MAAhB;AACGvC,0BACEwC,GADF,CACMxC,gBAAMO,QAAN,CAAeC,eAAf,EAAgC,SAAhC,EAA2CiC,cAA3C,EADN,EAEEC,MAFF,CAES,OAFT,CADH;AAAA;AAKG1C,0BACEwC,GADF,CACMxC,gBAAMO,QAAN,CAAeA,QAAf,EAAyB,SAAzB,EAAoCkC,cAApC,EADN,EAEEC,MAFF,CAES,OAFT;AALH;AA5BF,OADF;AAwCD;;;;EAxHuBC,gBAAMC,S;;kBA2HjBxC,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\";\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 = () => this.setState({ isPlaying: false, isLoading: false });\n this.player.onplay = () => this.setState({ isPlaying: false, isLoading: true });\n this.player.onplaying = () => 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 = () => this.setState({ isPlaying: false, isLoading: false });\n this.player.onplay = () => this.setState({ isPlaying: false, isLoading: true });\n this.player.onplaying = () => 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 = <i className=\"schedule schedule-icon_image_audio\" />;\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"]}
|