通用评论

index.js.map 6.9KB

1
  1. {"version":3,"sources":["../../../src/components/AudioPlayer/index.js"],"names":["dayjs","extend","durationPlugin","utcPlugin","AudioPlayer","props","state","duration","currentDuration","isPlaying","player","src","oncanplay","setState","event","target","onended","onpause","onplay","ontimeupdate","currentTime","prevProps","pause","playerList","document","getElementsByTagName","Array","from","forEach","paused","play","ref","display","clickPlayOrPause","value","utc","asMilliseconds","format","React","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;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;AAHA,KAAb;AAFiB;AAOlB;;;;wCAEmB;AAAA;;AAClB,UAAI,KAAKC,MAAT,EAAiB;AAAA,YACPC,GADO,GACC,KAAKN,KADN,CACPM,GADO;;AAEf,aAAKD,MAAL,CAAYE,SAAZ,GAAwB;AAAA,iBACtB,OAAKC,QAAL,CAAc,EAAEN,UAAUO,MAAMC,MAAN,CAAaR,QAAzB,EAAd,CADsB;AAAA,SAAxB;AAEA,aAAKG,MAAL,CAAYM,OAAZ,GAAsB;AAAA,iBACpB,OAAKH,QAAL,CAAc,EAAEJ,WAAW,KAAb,EAAoBD,iBAAiB,CAArC,EAAd,CADoB;AAAA,SAAtB;AAEA,aAAKE,MAAL,CAAYO,OAAZ,GAAsB;AAAA,iBAAM,OAAKJ,QAAL,CAAc,EAAEJ,WAAW,KAAb,EAAd,CAAN;AAAA,SAAtB;AACA,aAAKC,MAAL,CAAYQ,MAAZ,GAAqB;AAAA,iBAAM,OAAKL,QAAL,CAAc,EAAEJ,WAAW,IAAb,EAAd,CAAN;AAAA,SAArB;AACA,aAAKC,MAAL,CAA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AAhCF,OADF;AA4CD;;;;EAzGuBC,gBAAMC,S;;kBA4GjBnC,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\";\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 };\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 });\n this.player.onplay = () => this.setState({ isPlaying: true });\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 });\n this.player.onplay = () => this.setState({ isPlaying: true });\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 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 {isPlaying ? (\n <Icon className=\"pause\" type=\"pause\" />\n ) : (\n <i className=\"schedule schedule-icon_image_audio\" />\n )}\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"]}