自定义制作音频播放器

In the first two articles of this series I introduced the concept and code of a customized audio player. The prototype constructed to this point is “raw”, without any styling: the HTML5 and JavaScript has been written as fast as possible to prove that the basic concept works. In this article, I’ll focus on improving the look of the player and adding microdata, before introducing further functionality in part 4.

在本系列的前两篇文章中,我介绍了定制音频播放器的概念和代码。 至此构建的原型是“原始的”,没有任何样式: HTML5和JavaScript的编写速度尽可能快,以证明基本概念有效。 在本文的第4部分中,在介绍更多功能之前,我将重点关注改善播放器的外观和添加微数据 。

音频元素 (Audio Elements)

First, let’s look at the DOM we have to this point. The script in part 2 of this series added slider controls and other features via progressive JavaScript to the basic markup to create the following:

首先,让我们看一下到目前为止的DOM 。 本系列第2部分中的脚本通过渐进式JavaScript在基本标记中添加了滑块控件和其他功能,以创建以下内容:

<figure id="audioplayer"><figcaption><div>Track<span>24 Ghosts III</span></div><div id="album">Album<span>Ghosts III</span></div><div id="artist">Artist<span>Nine Inch Nails</span></div><div id="time">Time<span>00:00</span></div></figcaption><div id="fader"><input type="range" min="0" max="1" step="any" value="1" id="volumeSlider"><button type="button">volumehigh</button></div><div id="playback"><button type="button">Play</button><progress min="0" max="100" value="0" id="playhead"></progress>
</div><audio src="/assets/audio/24-ghosts-III.mp3" id="audiotrack" preload="auto"></audio>
</figure>

To this we add microdata, both for the benefit of search engines and to hook more JavaScript in later in this series. The code changes to:

为此,我们添加了微数据,既有利于搜索引擎,又在本系列的后面部分中添加了更多JavaScript。 代码更改为:

<figure id="audioplayer" itemprop="track" itemtype="http://schema.org/MusicRecording"><figcaption><div>Track<span itemprop="name">24 Ghosts III</span></div><div id="album">Album<span itemprop="inAlbum">Ghosts III</span></div><div id="artist">Artist<span itemprop="byArtist">Nine Inch Nails</span></div><div id="time">Time<span>00:00</span></div></figcaption>
<meta itemprop="duration" content="PT2M29S">
<div id="fader"><input type="range" min="0" max="1" step="any" value="1" orient="vertical" id="volumeSlider"><button type="button">volumehigh</button>
</div>
<div id="playback"><button type="button">Play</button><progress min="0" max="100" value="0" id="playhead"></progress>
</div><audio src="/assets/audio/24-ghosts-III.mp3" id="audiotrack" itemprop="audio" preload="auto"></audio>
</figure>

音频样式 (Styling Audio)

The CSS used in the player draws nicely on a number of intermediate to advanced techniques. The initial CSS resets the box-sizing model, sets the overall styling for the audio player, and hides the <audio> element completely:

播放器中使用CSS很好地借鉴了许多中级到高级技术。 初始CSS 重置框大小模型 ,设置音频播放器的整体样式,并完全隐藏<audio>元素 :

* {box-sizing: border-box;
}
figure#audioplayer {border: 1px solid #000;background: url(dark_wall.png) #333;overflow: hidden;width: 27rem;padding: .4rem;margin: 2rem auto;
}
figure#audioplayer audio {width: 0; height: 0;
}

Next, the various data elements inside the player are styled, with borders set on different sides to create dividers between them. The range input is set to vertical for Webkit and Chrome using CSS:

接下来,对播放器内部的各种数据元素进行样式设置,在不同侧面设置边框以在它们之间创建分隔线。 使用CSS将Webkit和Chrome的range输入设置为垂直:

figure#audioplayer figcaption {width: 21.5rem;font-size: 0;margin: .45rem;background: #000;float: left;border: 1px solid #555;text-align: left;
}
figure#audioplayer figcaption div {background: #000;color: #fff;padding: .8rem;font-family: Avenir, Helvetica, sans-serif;text-transform: uppercase;font-size: .8rem;display: inline-block;
}
figure#audioplayer figcaption div span {display: block;font-size: 1.3rem;text-indent: 1rem;
}
div#album {border-top: 1px solid #555;border-bottom: 1px solid #555;width: 100%;
}
div#time {width: 7.55rem;border-left: 1px solid #555;
}
input#volumeSlider{ -webkit-appearance: slider-vertical;
width: 35px;
}

The buttons use a semantic ligature icon font to turn their text into an image:

这些按钮使用语义连字图标字体将其文本转换为图像:

figure#audioplayer button {width: 3rem;height: 3rem;background: #000;color: #fff;border: none;-webkit-font-feature-settings: "liga", "dlig";font-feature-settings: "liga", "dlig";
}
#playback {clear: both;
}
div#fader {display: inline-block;
}

The <progress> element is also styled. It uses HSL to make color changes later (if needed) easier:

<progress>元素也被设置样式。 它使用HSL使以后的颜色更改(如果需要)更容易:

#playback progress {margin-left: 1rem;width: 20rem;height: 12px;-webkit-appearance: none;-moz-appearance: none;appearance: none;background-color: #888;border: none;color: hsl(44,100%,44%);
}
progress::-webkit-progress-bar,progress::-moz-progress-bar,progress::progress-bar {background: hsl(44,100%,44%);
}
progress::-webkit-progress-value { background: hsl(44,100%,44%);
}
progress::-moz-progress-bar { background-color: hsl(44,100%,44%);
}

Finally, the player is made responsive, moving elements around and decreasing the padding as the viewport narrows:

最后,使播放器具有响应能力 ,随着视口变窄,元素在周围移动并减少填充:

@media screen and (max-width:500px){div#time { display: block !important;border-top: 1px solid #555;width: 100%;
}figure#audioplayer { width: 100%;padding: .2rem;}figure#audioplayer figcaption div { padding: .4rem;}
}
@media screen and (max-width:450px){figure#audioplayer figcaption { width: 16rem;}#playback progress {width: 220px;}
}
@media screen and (max-width:400px) { figure#audioplayer figcaption { width: 14rem;}
}

In the next article, I’ll use the Web Audio API to add and animate a left and right channel meter display for the player.

在下一篇文章中,我将使用Web Audio API为播放器添加左右声道显示并为其设置动画。

翻译自: https://thenewcode.com/985/Making-An-Audio-Player-With-HTML5-Part-3-Microdata-and-Skinning

自定义制作音频播放器

自定义制作音频播放器_使用HTML5制作音频播放器,第3部分:微数据和皮肤相关推荐

  1. 带倍速播放的播放器_带有HTML5的MP3播放器

    带倍速播放的播放器 MP3 Player with HTML5 In you are a beginner in HTML5 and you are looking for new knowledge ...

  2. html音乐播放器代码自动,html5 css3音乐播放器代码

    特效描述:html5 css3 音乐播放器代码.html5 css3音乐播放器代码 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 标题歌手 00:00/00:00 var music ...

  3. 用html制作个人站点,【制作个人网站】如何在网上制作自己的网页?如何用html5制作个人主页?制作个人网页设计思路是怎样的?...

    [制作个人网站]如何在网上制作自己的网页?如何用html5制作个人主页?制作个人网页设计思路是怎样的?下面就和小编一起来看看吧! 如何在网上制作自己的网页? 网站设计的八个步骤现在看到的工具越来越多, ...

  4. html原生音频播放器倍速,HTML5倍数功能视频播放器(加速2倍,1.5倍播放)

    HTML5倍数功能视频播放器(加速2倍,1.5倍播放) 倍数功能视频播放器的应用: 培训场景,教育教学场景下,可以倍速观看视频,比如1.5倍,2倍的速度观看视频,可以更快速的看完课程,节省时间. va ...

  5. html5中音乐播放器怎么写,html5简单音乐播放器

    自己写的一个简单的音乐播放器, 主要实现了控制播放暂停,时间显示,音乐进度条点击以及拖动改变播放进度效果. 基于jquery编写,需要引入jquery. HTML: 00:00:00 00:00:00 ...

  6. 计算机基础应用软件ppt制作,大学计算机基础_演示文稿制作软件.ppt

    大学计算机基础_演示文稿制作软件资料 插入影片和声音 插入影片 插入声音 播放CD乐曲 录制声音 5.5 演示文稿中的动画和超链接技术 5.5.1 为幻灯片加入动画效果 5.5.2 创建超级链接 为幻 ...

  7. 电脑PHP动画制作画板,HTML_html5教程制作简单画板代码分享,HTML5制作简单画板 复制代码代 - phpStudy...

    html5教程制作简单画板代码分享 HTML5制作简单画板 复制代码代码如下: http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min ...

  8. 制作mysql rpm包_一步步制作RPM包

    一.RPM制作步骤 我们在企业中有的软件基本都是编译的,我们每次安装都得编译,那怎么办呢?那就根据我们的需求制作RPM安装包吧.先来说说基本布骤: 1.Planning what you want   ...

  9. 制作唐诗网页代码_分享FrontPage制作网页的几个技巧

    最近笔者学会了用FrontPage XP做网页,心理特高兴,非常想把我在制作主页过程中的一些经验和大家交流交流.切磋切磋,我们一起来看看吧. 用表格做按钮 很多人为了做出按钮效果,不得不去动用一些图像 ...

最新文章

  1. 面试官问: 如何保证 MQ消息是有序的?
  2. DS-5/RVDS4.0变量初始化错误
  3. [转]VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
  4. 光谱分析软件_利用Tracker软件分析太阳光谱中辐射强度与波长的关系
  5. set和enum类型的用法和区别
  6. 【HTML/CSS】CSS权重、继承及引入方式
  7. python执行到input后执行下一程序_Python基础知识储备,如何开关一个while循环
  8. pandas不显示index_Pandas中文官档 ~ 基础用法1
  9. 在进行Forms身份验证时如何将此信息映射到GenericPrincipal 和 FormsIdentity 对象?
  10. Atitit golang开发环境搭建 目录 1. 编辑helo.go 1 1.1. 调试编译 1 2. Ide选择liteide 2 3. 问题解决 2 4. 附录 2 4.1. Go语言标准库常
  11. 开发交接文档_为开发人员创造更好的设计交接体验
  12. 写点什么好呢2? 钱、事业、婚姻、人生意义
  13. 极兔快递 | 快递单号查询API
  14. CAD等高线转地形高程散点
  15. Windows 10 1809 on ubuntu1804 完美安装docker
  16. C DoEvents
  17. 新版火狐 拖 功能_Firefox 33的新功能
  18. 微信小程序--操作微信自带的返回按钮使上个页面刷新列表或刷新数据
  19. 论文投稿指南——中文核心期刊推荐(水利工程)
  20. 2017计算机二c语言题库,2017计算机二c语言题库试题及答案

热门文章

  1. 一文尽览 | 全景/鱼眼相机低速自动驾驶的近距离感知(识别+重建+定位+工程化)...
  2. 分享给高考生一些我的观点
  3. 通常来讲,要制定一个清晰的、可执行的计划,需要遵循 SMART原则
  4. 软件工程开发模型以及在软件工程中的作用
  5. C/C++:Ubuntu20.04报错:无法打开mysql/mysql.h
  6. (C++)出现错误error: expected unqualified-id before numeric constant|
  7. 前端页面实现倒计时效果的几种方法
  8. 中大 管理科学与工程 计算机水平,管理科学与工程丨中山大学 了解一下
  9. 【windows start命令】windows类似nohup命令
  10. fc4字体美化与基本配置