给我设置一下uniapp的audio的样式,让他和酷狗的播放一样,有进度条的代码

时间: 2023-06-27 15:04:53 浏览: 56
好的,可以参考以下代码: ```html <template> <view> <audio :src="audioSrc" ref="audio" class="audio"></audio> <view class="audio-controls"> <view class="audio-progress" :style="{ width: progressWidth }"></view> <view class="audio-play-btn" @tap="togglePlay"> <image :src="isPlaying ? pauseIcon : playIcon" class="icon"></image> </view> <view class="audio-time">{{ currentTime }} / {{ duration }}</view> </view> </view> </template> <script> export default { data() { return { audioSrc: 'https://example.com/audio.mp3', isPlaying: false, progressWidth: '0%', duration: '00:00', currentTime: '00:00', playIcon: 'path/to/play.png', pauseIcon: 'path/to/pause.png' } }, mounted() { this.$refs.audio.addEventListener('timeupdate', this.updateProgress) this.$refs.audio.addEventListener('loadedmetadata', this.setDuration) }, methods: { togglePlay() { const audio = this.$refs.audio if (this.isPlaying) { audio.pause() } else { audio.play() } this.isPlaying = !this.isPlaying }, setDuration() { const audio = this.$refs.audio const duration = Math.floor(audio.duration) this.duration = this.formatTime(duration) }, updateProgress() { const audio = this.$refs.audio const currentTime = Math.floor(audio.currentTime) const duration = Math.floor(audio.duration) this.progressWidth = `${(currentTime / duration) * 100}%` this.currentTime = this.formatTime(currentTime) }, formatTime(time) { const minutes = Math.floor(time / 60) const seconds = time % 60 return `${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}` } }, beforeDestroy() { this.$refs.audio.removeEventListener('timeupdate', this.updateProgress) this.$refs.audio.removeEventListener('loadedmetadata', this.setDuration) } } </script> <style> .audio { display: none; } .audio-controls { display: flex; align-items: center; height: 40px; background-color: #f2f2f2; padding: 0 10px; border-radius: 20px; overflow: hidden; } .audio-progress { height: 4px; background-color: #ff5000; } .audio-play-btn { width: 28px; height: 28px; background-color: #fff; border-radius: 50%; display: flex; justify-content: center; align-items: center; margin-right: 10px; } .icon { width: 16px; height: 16px; } .audio-time { font-size: 12px; } </style> ``` 你需要将 `audioSrc` 改为你自己的音频链接,`playIcon` 和 `pauseIcon` 为播放和暂停图标的路径。 这个组件会渲染一个 `audio` 标签和一个类似酷狗的进度条,以及播放/暂停按钮和时间显示。当你点击播放/暂停按钮时,它会切换音频的播放状态。进度条和时间显示会根据当前播放时间和音频时长来更新。

相关推荐

最新推荐

recommend-type

解决ios audio无法播放问题

主要介绍了解决ios audio无法播放问题,并给大家分享了解决方法,需要的朋友参考一下。
recommend-type

js实现音频控制进度条功能

本文主要介绍了js实现音频控制进度条功能的示例代码。具有很好的参考价值。下面跟着小编一起来看下吧
recommend-type

vue中解决chrome浏览器自动播放音频和MP3语音打包到线上的实现方法

主要介绍了vue中解决chrome浏览器自动播放音频和MP3语音打包到线上的实现方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

使用HTML5在网页中嵌入音频和视频播放的基本方法

我们只需要设置 src 属性来识别媒体资源,包含 controls 属性让用户可以播放和暂停媒体。 嵌入视频下面是在 Web 页面中嵌入视频文件最简单的形式: XML/HTML Code复制内容到剪贴板 &lt;video src="foo.mp4" width...
recommend-type

Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能

主要介绍了Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能的相关资料,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

list根据id查询pid 然后依次获取到所有的子节点数据

可以使用递归的方式来实现根据id查询pid并获取所有子节点数据。具体实现可以参考以下代码: ``` def get_children_nodes(nodes, parent_id): children = [] for node in nodes: if node['pid'] == parent_id: node['children'] = get_children_nodes(nodes, node['id']) children.append(node) return children # 测试数
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。