Comments (2)
时序控制上有些问题,在onPlay中又调用了一次play方法导致,创建了两个定时器。组件销毁时,只清除了一个。调整代码后,问题解决。
from vue-audio-player.
我是在组件中封装了 AudioPlayer,在退出时,确认音频播放已暂停,且在onReturn中尝试直接调用 clearTimer(),都无法销毁定时器。
<script>
import AudioPlayer from '@liripeng/vue-audio-player'
import '@liripeng/vue-audio-player/lib/vue-audio-player.css'
import { MusicService } from '../../services/music'
import { Global } from '../../techmask/utils/global'
let _ = require('lodash')
export default {
name: 'Music',
components: {
AudioPlayer
},
props: {
musics: {
type: Array,
required: true
},
user: {
type: Object,
required: true
}
},
created () {
this.currentMusic = this.musics[0]
this.bgImg = Global.STATIC_CDN_URL + '/images/music/' + this.currentMusic.imgPath
this.audioList.push({
url: Global.STATIC_CDN_URL + '/media/music/' + this.currentMusic.musicCode + '.mp3'
})
},
data () {
return {
currentMusic: null,
useTime: 0,
audioList: [
],
requestData: {
},
controls: {
showConfirmStopInd: false,
startedInd: false
}
}
},
timers: {
updateUseTime: { time: 1000, autostart: false, repeat: true }
},
methods: {
startTreat () {
this.useTime = 0
this.controls.startedInd = true
this.$timer.start('updateUseTime')
this.$refs.audioPlayer.play()
},
stopTreat () {
this.$refs.audioPlayer.pause()
this.$timer.stop('updateUseTime')
let requestData = this.requestData
_.assign(requestData, _.pick(this.currentMusic, ['musicCode', 'musicName']))
requestData.duration = this.useTime
requestData.userId = this.user.userId
MusicService.addMusicRecord(requestData).then(response => {
if (Global.handleErrors(response, this)) {
this.controls.startedInd = false
this.onReturn()
}
})
},
updateUseTime () {
this.useTime++
},
onReturn () {
this.$refs.audioPlayer.pause()
this.$refs.audioPlayer.clearTimer()
alert(1)
this.$refs.audioPlayer.isPlaying = false
this.$emit('onReturn', {})
},
submit () {
},
onPlay () {
if (!this.controls.startedInd) {
this.startTreat()
}
},
onEnded () {
if (this.useTime > 60) {
this.$refs.audioPlayer.pause()
this.$timer.stop('updateUseTime')
this.controls.showConfirmStopInd = true
}
},
continueTimer () {
this.$timer.start('updateUseTime')
}
}
}
</script>
from vue-audio-player.
Related Issues (20)
- 部分情况下,ios playing不触发 HOT 2
- 安装上插件后显示样式有问题 HOT 2
- 自动播放 HOT 13
- 问题求解 HOT 4
- vue里,需要控制暂停,不生效 HOT 1
- 怎么使用插槽更改样式 HOT 3
- Cannot read properties of null (reading 'duration') HOT 1
- 如何播放列表中指定歌曲 HOT 1
- 小米手机兼容 HOT 1
- 拖拽进度条后,会出现多个声音叠加 HOT 4
- Changing currentTime turns back to original position. HOT 2
- vue3中用refs控制如何播放 HOT 1
- Struggling creating standalone play/pause button: "Cannot read properties of undefined (reading 'isPlaying')" HOT 1
- Is it possible to hide the loading spinner? HOT 2
- Since upgrading to 1.5.3: Sourcemap pointing to missing source files HOT 1
- iPhone: Operation not supported HOT 2
- Add "stop()" method HOT 1
- Mouse-over shows hand icon despite :disabled-progress-drag and :disabled-progress-click HOT 1
- Could you please share an example how to use the "ended"-event? HOT 4
- Next song does not automatically play on iPhone when screen is locked HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-audio-player.