GoEasyAudioPlayer.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. this.play = true;
  22. innerAudioContext.src = this.src;
  23. innerAudioContext.play();
  24. setTimeout(() => {
  25. this.play = false;
  26. }, this.duration*1000)
  27. }
  28. }
  29. }
  30. </script>
  31. <style scoped>
  32. .goeasy-audio-player{
  33. margin-top: 12rpx;
  34. -webkit-tap-highlight-color:rgba(0,0,0,0);
  35. }
  36. .audio-facade{
  37. min-width: 20rpx;
  38. padding: 6rpx 10rpx;
  39. height: 72rpx;
  40. line-height: 72rpx;
  41. background: #618DFF;
  42. font-size: 24rpx;
  43. border-radius: 14rpx;
  44. color: #ffffff;
  45. display: flex;
  46. }
  47. .audio-facade-bg{
  48. background: url("./images/voice.png") no-repeat center;
  49. background-size: 30rpx;
  50. width: 40rpx;
  51. }
  52. .audio-facade-bg.play-icon{
  53. background: url("./images/play.gif") no-repeat center;
  54. background-size: 30rpx;
  55. -moz-transform:rotate(180deg);
  56. -webkit-transform:rotate(180deg);
  57. -o-transform:rotate(180deg);
  58. transform:rotate(180deg);
  59. }
  60. </style>