Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

88 рядки
1.8 KiB

  1. import {
  2. mapState,
  3. mapActions,
  4. mapMutations
  5. } from 'vuex'
  6. export const audios = {
  7. data() {
  8. return {
  9. isBgPlay: false, // 是否禁止拖拽进度条
  10. }
  11. },
  12. computed: {
  13. ...mapState(['bgAudioMannager']),
  14. },
  15. methods: {
  16. setAudio(obj) {
  17. this.bgAudioMannager.title = '录音音频';
  18. this.bgAudioMannager.src = obj.src
  19. this.bgAudioMannager.startTime = obj.currentTime
  20. },
  21. setAudioFunc() {
  22. this.bgAudioMannager.onCanplay(() => {
  23. console.log('可以播放');
  24. });
  25. this.bgAudioMannager.onStop(() => {
  26. console.log('停止播放');
  27. this.isBgPlay = false
  28. });
  29. this.bgAudioMannager.onPause(() => {
  30. console.log('暂停播放');
  31. this.isBgPlay = false
  32. // 设置当前暂停的视频播放位置
  33. // this.seek(this.bgAudioMannager.currentTime)
  34. // this.play()
  35. });
  36. this.bgAudioMannager.onEnded(() => {
  37. console.log('自然播放结束事件');
  38. this.isBgPlay = false
  39. });
  40. this.bgAudioMannager.onError((res) => {
  41. console.log(res.errMsg);
  42. console.log(res.errCode);
  43. });
  44. this.bgAudioMannager.onTimeUpdate(() => {
  45. this.isBgPlay = true
  46. this.duration = this.bgAudioMannager.duration;
  47. this.currentTime = this.bgAudioMannager.currentTime;
  48. this.$emit('timeUpdate', {
  49. duration: this.bgAudioMannager.duration,
  50. currentTime: this.bgAudioMannager.currentTime
  51. })
  52. });
  53. },
  54. // 背景音频暂停
  55. audioPause() {
  56. this.bgAudioMannager.pause()
  57. },
  58. // 背景音频播放
  59. audioPlay() {
  60. this.pause()
  61. this.bgAudioMannager.play()
  62. },
  63. //背景音频指定秒数播放
  64. audioSeek(t) {
  65. this.bgAudioMannager.seek(t)
  66. },
  67. // 停止背景音频播放
  68. stopAduio() {
  69. console.log(this.bgAudioMannager)
  70. this.bgAudioMannager.pause()
  71. if (this.bgAudioMannager && this.bgAudioMannager.src) {
  72. this.bgAudioMannager.src = ''
  73. }
  74. }
  75. }
  76. }