首页 > 其他分享 >音频播放

音频播放

时间:2024-08-12 17:20:35浏览次数:6  
标签:scale val 音频 width background 播放 refs audio

<template>
  <div class="audio-play">
    <audio
        ref="audio"
        preload
        @pause="handlePause"
        @play="handleTimeProgress"
        @canplay="computedFullTime"
        :src="audioUrl"
    ></audio>
    <div class="control-btn" @click="playStatusChange">
      <div :class="playStatus ? 'play' : 'stop'"></div>
    </div>
    <div class="control-line">
      <div ref="fullLine" class="bottom-line">
        <div class="played-line" :style="scaleProgress"></div>
        <div ref="point" class="play-point" @mousedown="handleMouseDown">
          <div class="point"></div>
        </div>
<!--        <div class="played-time">{{ playTime }}</div>-->
      </div>
<!--      <div class="al-time">{{ fullTime }}</div>-->
    </div>
  </div>
</template>

<script>
export default {
  name: "audio-play",
  props:{
    audioUrl:{
      type:String,
      default:''
    },
    playStatus:{
      type:Boolean,
      default:false
    }
  },
  data(){
    return{
      playTime:'',
      fullTime:'',
      scale:0,
    }
  },
  computed: {
    scaleProgress() {
      if (this.scale) {
        return 'width:' + this.scale * 100 + '%';
      } else {
        return 'width:0';
      }
    }
  },
  methods:{
    //播放按钮点击切换事件
    playStatusChange() {
      this.playStatus = !this.playStatus;
      if (this.playStatus) {
        this.$refs.audio.play();
      } else {
        this.$refs.audio.pause();
      }
    },
    handleTimeProgress() {
      this.timer = setInterval(this.playing, 1000);
    },
    playing() {
      // 正在播放中
      this.scale = this.$refs.audio.currentTime / this.$refs.audio.duration;
      this.playTime = this.formatTime(this.$refs.audio.currentTime);
    },
    handlePause() {
      this.playStatus = false;
      clearInterval(this.timer);
    },
    computedFullTime() {
      this.fullTime = this.formatTime(this.$refs.audio.duration);
    },
    formatTime(val) {
      val = Math.round(val);
      const min = Math.floor(val / 60);
      const sec = val % 60;
      return this.setZero(min) + ':' + this.setZero(sec);
    },
    setZero(val) {
      if (val < 10) {
        return '0' + val;
      } else {
        return '' + val;
      }
    },
    //鼠标按下事件触发
    handleMouseDown(ev) {
      const that = this;
      const downX = ev.pageX;
      const downL = this.$refs.point.offsetLeft;
      //鼠标移动事件
      document.onmousemove = ev => {
        let scale =
            (ev.pageX - downX + downL + 8) / that.$refs.fullLine.offsetWidth;
        if (scale < 0) {
          scale = 0;
        } else if (scale > 1) {
          scale = 1;
        }
        that.scale = scale;
        that.$refs.audio.currentTime = scale * that.$refs.audio.duration;
        that.playTime = that.formatTime(that.$refs.audio.currentTime);
      };
      document.onmouseup = () => {
        document.onmousemove = document.onmouseup = null;
      };
      ev.preventDefault();
    }
  }
}
</script>

<style scoped lang="scss">
.audio-play {
  height: 18px;
  width: 95%;
  margin-left: 8px;
  display: flex;
  position: relative;
  top: -12px;
.control-btn {
  height: 18px;
  width: 18px;
  cursor: pointer;
.play {
  height: 18px;
  width: 18px;
  background: url('@/assets/image/stop.png');
  background-size: 100% 100%;
}
.stop {
  height: 18px;
  width: 18px;
  background: url('@/assets/image/play.png');
  background-size: 100% 100%;
}
}
.control-line {
  width: 80%;
  margin-left: 6px;
.al-time {
  float: right;
  opacity: 0.6;
  font-family: PingFangSC-Semibold;
  font-size: 12px;
  color: #64e59e;
  margin-top: 4px;
}
.bottom-line {
  display: flex;
  position: relative;
  margin-top: 8px;
  height: 4px;
  background: rgba(44,116,79,0.25);
  border-radius: 2px;
.played-line {
  background: linear-gradient(90deg,rgba(149,255,225,0.75), rgba(100,229,158,0.95));
  border-radius: 2px;
  height: 4px;
// width: 20%;
}
.played-time {
  position: absolute;
  opacity: 0.6;
  font-family: PingFangSC-Semibold;
  font-size: 12px;
  color: #64e59e;
  left: -18px;
  top: 10px;
}
.play-point {
  position: relative;
  height: 10px;
  width: 10px;
  background: #ffffff;
  border: 1px solid #64e59e;
  border-radius: 5px;
  margin-left: -5px;
  margin-top: -4px;
.point {
  background: #64e59e;
  height: 4px;
  width: 4px;
  margin: 3px;
  border-radius: 2px;
}
}
}
}
}
</style>


标签:scale,val,音频,width,background,播放,refs,audio
From: https://www.cnblogs.com/baozhengrui/p/18355371

相关文章

  • linux笔记(1):ubuntu环境下,基于SDL2运行lvgl+ffmpeg播放mp4
    文章目录1.ubuntu安装ffmpeg1.1源码安装1.1克隆ffmpeg源码1.2配置编译条件,编译,安装1.2直接安装依赖包2.下载lvgl源码2.1测试原始代码2.2运行lv_example_ffmpeg_2()例程2.2.1配置LV_USE_FFMPEG为12.2.2lv_example_ffmpeg_2()替换lv_demo_widgets()2.2.3链接......
  • 基于Java Springboot音乐播放器系统
    一、作品包含源码+数据库+设计文档万字+PPT+全套环境和工具资源+部署教程二、项目技术前端技术:Html、Css、Js、Vue、Element-ui数据库:MySQL后端技术:Java、SpringBoot、MyBatis三、运行环境开发工具:IDEA/eclipse数据库:MySQL5.7数据库管理工具:Navicat10以上版本环境......
  • 数字音频接口之I2S总线协议详解
    数字音频接口之I2S总线协议详解应用场景I2S(Inter-ICSound)是一种广泛应用于数字音频传输的串行接口标准。它最初由飞利浦(Philips)公司开发,用于解决在集成电路之间传输音频数据的问题。I2S协议定义了音频数据的传输格式、时序和控制信号。在工作中音频采集和输出,AD和主芯片之间的......
  • Android14音频进阶调试之命令播放mp3/aac非裸流音频(八十)
    简介:CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!新书发布:《Android系统多媒体进阶实战》......
  • VS2010旗舰版VB.NET版本音频剪辑代码2024-8-10
    ImportsSystem.ComponentModelImportsSystem.IOImportsSystem.DiagnosticsImportsSystem.DrawingImportsSystem.Windows.FormsPublicClassForm1PrivateWithEventsbgWorkerAsNewBackgroundWorkerPrivateffmpegPathAsString=“C:\ffmpeg-master-lates......
  • 佰泰盛世—HT5169内置BOOST升压的11WI2S输入D类音频功放
    1特性电源供电• 升压输入VBAT:2.5V-5.5V;• 升压输出PVDD可调,最高7.5V• DVDD/AVDD:3.3V音频性能•9.0W(VBAT=3.7V,PVDD=7.5V,RL=3Ω,THD+N=10%)•11.0W(VBAT=3.7V,PVDD=7.5V,RL=2Ω,THD+N=10%•5.5W(VBAT=3.7V,PVDD=6.5V,RL=4Ω,THD+N=10%)灵......
  • 一个简单的录音软件(利用QT录音,ffmpeg进行音频重采样,fdk-aac编码)
             录音软件是一种非常有用的工具,可以帮助我们记录和存储语音信息。在本文中,我们将介绍一个简单的录音软件,该软件利用QT进行录音,使用ffmpeg进行音频重采样,并使用fdk-aac编码。一、 环境介绍  1、QT版本:QT5.12.62、编译器: MSVC2017643、ffmpeg版......
  • 利用QT和FFmpeg实现一个简单的视频播放器
              在当今的多媒体世界中,视频播放已成为不可或缺的一部分。从简单的媒体播放器到复杂的视频编辑软件,视频解码和显示技术无处不在。本示例使用Qt和FFmpeg构建一个简单的视频播放器。利用ffmpeg解码视频,通过QWidget渲染解码后的图像,支持进度条跳转、进度条显示,......
  • 使用Python+moviepy做音频的淡入淡出效果
    一、音频的淡入效果frommoviepy.editorimport*au=AudioFileclip("/home/Download/test.mp3")au=au.fx(afx.audiofadein,duration=1)#一秒钟的淡入效果au.write_audiofile("/home/Download/fade.mp3")二、音频的淡出效果frommoviepy.editorimport*au=Audio......
  • vue3(nuxt3)+Aliplayer播放器进行直播播流
    前言:    上一篇讲到使用自定义的一个播放器去进行播流进行观看直播,由于之前都是自己研发的,服务器不是特别好,所以决定使用阿里的推流以及阿里的播放器去进行拉流也更加的适配吧,至少后面出现问题可以有文档看比较完善实践    1.这里的话先把官方文档的地......