123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <template>
- <div class="Audio">
- <audio id="audioTag" :src="audioSrc"></audio>
- <div class="audiocon">
- <!-- 按钮 -->
- <div class="leftBtn">
- <div class="play">
- <img @click="bofang" :src="require(`@/assets/img/goods/${isPlay ? 'audio2' : 'audio1'}.png`)" alt="" />
- </div>
- </div>
- <div class="adcon">
- <div class="bar">
- <div class="activeLine" @click="seekTime">
- <div :style="{ width: currentPosi + '%' }" class="dot"></div>
- </div>
- </div>
- <div class="time">
- <span>{{ time }}</span><span> / {{ allTime }}</span>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "Audio",
- props: {
- audioSrc: {
- type: String,
- },
- },
- data() {
- return {
- active: 0,
- time: 0,
- _audio: "",
- isPlay: this.isMobile,
- currentPosi: 0,
- allTime: 0,
- };
- },
- methods: {
- bofang() {
- if (this._audio.paused) {
- this._audio.play();
- this.isPlay = true;
- } else {
- this._audio.pause();
- this.isPlay = false;
- }
- },
- transTime(time) {
- var duration = parseInt(time);
- var minute = parseInt(duration / 60);
- var sec = (duration % 60) + "";
- var isM0 = ":";
- if (minute == 0) {
- minute = "00";
- } else if (minute < 10) {
- minute = "0" + minute;
- }
- if (sec.length == 1) {
- sec = "0" + sec;
- }
- return minute + isM0 + sec;
- },
- updateProgress() {
- this.currentPosi = (this._audio.currentTime / this._audio.duration) * 100;
- this.time = this.transTime(this._audio.currentTime);
- },
- audioEnded() {
- this._audio.currentTime = 0;
- this._audio.pause();
- this.isPlay = false;
- },
- seekTime(e) {
- var rate = e.offsetX / e.target.clientWidth;
- this._audio.currentTime = this._audio.duration * rate;
- this.updateProgress();
- },
- },
- mounted() {
- this.$nextTick(() => {
- this._audio = $(`#audioTag`)[0];
- $(`#audioTag`).on("loadedmetadata", (e) => {
- this.time = this.isMobile
- ? "00:00"
- : this.transTime(e.currentTarget.duration);
- this.allTime = this.transTime(e.currentTarget.duration);
- this._audio.play();
- this.isPlay = true;
- });
- document.addEventListener(
- "WeixinJSBridgeReady",
- function () {
- this._audio.play();
- },
- false
- );
- $(`#audioTag`).on("timeupdate", () => {
- this.updateProgress();
- });
- $(`#audioTag`).on("timeupdate", () => {
- this.updateProgress();
- });
- $(`#audioTag`).on("ended", () => {
- this.audioEnded();
- });
- });
- },
- activated() {
- this.isPlay = this.isMobile;
- },
- };
- </script>
- <style lang="less" scoped>
- .Audio {
- width: 100%;
- height: 100%;
- padding: 0 15px;
- .audiocon {
- display: flex;
- align-items: center;
- width: 100%;
- height: 100%;
- justify-content: space-between;
- }
- .leftBtn {
- width: 30px;
- height: 30px;
- img {
- width: 100%;
- }
- }
- .adcon {
- position: relative;
- z-index: 10;
- width: calc(100% - 46px);
- height: 100%;
- display: flex;
- align-items: center;
- .bar {
- width: calc(100% - 80px);
- position: relative;
- height: 100%;
- display: flex;
- align-items: center;
- .activeLine {
- position: absolute;
- top: 0;
- left: 0px;
- z-index: 10;
- width: 96%;
- height: 100%;
- cursor: pointer;
- &::before {
- content: "";
- position: absolute;
- width: 100%;
- height: 4px;
- top: 50%;
- left: 0;
- transform: translateY(-50%);
- border-radius: 4px;
- background-color: #FFB199;
- }
- }
- .dot {
- border-radius: 4px;
- z-index: 11;
- pointer-events: none;
- position: absolute;
- height: 4px;
- top: 50%;
- left: 0px;
- transform: translateY(-50%);
- background-color: #FF615C;
- &::before {
- content: "";
- position: absolute;
- top: -3px;
- right: -3px;
- width: 10px;
- height: 10px;
- border-radius: 50%;
- background-color: #FF615C;
- }
- }
- }
- .time {
- width: 80px;
- font-size: 14px;
- color: #999999;
- display: flex;
- }
- }
- }
- </style>
|