GoEasyAudioPlayer.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="goeasy-audio-player" @click="playAudio">
  3. <div class="audio-facade" :style="{width:Math.ceil(duration)*7 + 50 + 'px'}">
  4. <div class="audio-facade-bg" :class="{'play-icon':play}"> </div>
  5. <div>{{Math.ceil(duration) || 1}}</div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. const innerAudioContext = uni.createInnerAudioContext();
  11. export default {
  12. name: "GoEasyAudioPlayer",
  13. props: ['src', 'duration'],
  14. data() {
  15. return {
  16. play: false
  17. }
  18. },
  19. methods: {
  20. playAudio() {
  21. wx.setInnerAudioOption({
  22. obeyMuteSwitch: false
  23. })
  24. this.play = true;
  25. innerAudioContext.src = this.src;
  26. innerAudioContext.play();
  27. setTimeout(() => {
  28. this.play = false;
  29. }, this.duration * 1000)
  30. }
  31. }
  32. }
  33. </script>
  34. <style scoped>
  35. .goeasy-audio-player {
  36. margin-top: 12rpx;
  37. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  38. }
  39. .audio-facade {
  40. min-width: 20rpx;
  41. padding: 6rpx 10rpx;
  42. height: 72rpx;
  43. background: #618DFF;
  44. font-size: 24rpx;
  45. border-radius: 14rpx;
  46. color: #ffffff;
  47. display: flex;
  48. align-items: center;
  49. }
  50. .audio-facade-bg {
  51. background: url("./images/voice.png") no-repeat center;
  52. background-size: 30rpx;
  53. width: 40rpx;
  54. height: 100%;
  55. }
  56. .audio-facade-bg.play-icon {
  57. background: url("./images/play.gif") no-repeat center;
  58. background-size: 30rpx;
  59. -moz-transform: rotate(180deg);
  60. -webkit-transform: rotate(180deg);
  61. -o-transform: rotate(180deg);
  62. transform: rotate(180deg);
  63. }
  64. </style>