音频/视频

Material design风格HTML5 audio音频播放器

阿里云


jAudio.js 是一款基于 HTML5 audio 的 Material design 风格音频播放器 jQuery 插件。该音频播放器可以设置音频播放列表,每首曲子的封面,标题等,还可以控制歌曲的播放和快进,而且它使用上非常简单。

使用方法:

使用 Material design 风格音频播放器插件需要引入 jQuery 和 jaudio.min.js。

也想出现在这里?联系我们
创客主机
  1. <script src="js/jquery.min.js"></script>
  2. <script src="js/jaudio.min.js"></script>

HTML 结构:

该 Material design 风格音频播放器的基本 HTML 结构如下:

  1. <div class='jAudio--player'>
  2.     <audio></audio>
  3.     <div class='jAudio--ui'>
  4.       <div class='jAudio--thumb'></div>
  5.       <div class='jAudio--status-bar'>
  6.         <div class='jAudio--details'></div>
  7.         <div class='jAudio--volume-bar'></div>
  8.         <div class='jAudio--progress-bar'>
  9.           <div class='jAudio--progress-bar-wrapper'>
  10.             <div class='jAudio--progress-bar-played'>
  11.               <span class='jAudio--progress-bar-pointer'></span>
  12.             </div>
  13.           </div>
  14.         </div>
  15.         <div class='jAudio--time'>
  16.           <span class='jAudio--time-elapsed'>00:00</span>
  17.           <span class='jAudio--time-total'>00:00</span>
  18.         </div>
  19.       </div>
  20.     </div>
  21.  
  22.     <div class='jAudio--playlist'>
  23.     </div>
  24.  
  25.     <div class='jAudio--controls'>
  26.       <ul>
  27.         <li><button class='btn' data-action='prev' id='btn-prev'><span></span></button></li>
  28.         <li><button class='btn' data-action='play' id='btn-play'><span></span></button></li>
  29.         <li><button class='btn' data-action='next' id='btn-next'><span></span></button></li>
  30.       </ul>
  31.     </div>
  32. </div>

CSS 样式:

下面是该音频播放器的主要 CSS 样式。你可以修改下面的样式来制作你自己需要的音频播放器样式。

  1. .jAudio--player {
  2.   display: table;
  3.   overflow: hidden;
  4.   background: #fff;
  5.   box-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
  6.   margin: 100px auto;
  7.   width: 352px;
  8. }
  9.  
  10. .jAudio--player:after {
  11.   content: " ";
  12.   display: block;
  13.   width: 100%;
  14.   clear: both;
  15. }
  16.  
  17. .jAudio--player .jAudio--ui {
  18.   position: relative;
  19.   width: 100%;
  20. }
  21.  
  22. .jAudio--player .jAudio--status-bar {
  23.   width: 100%;
  24.   z-index: 1;
  25.   position: relative;
  26.   padding: 100px 2rem 2rem 2rem;
  27.   display: table;
  28. }
  29.  
  30. .jAudio--player .jAudio--status-bar:after {
  31.   content: " ";
  32.   display: block;
  33.   width: 100%;
  34.   clear: both;
  35. }
  36.  
  37. .jAudio--player .jAudio--controls {
  38.   width: 100%;
  39.   display: table;
  40.   background: #fafafa;
  41. }
  42.  
  43. .jAudio--player .jAudio--controls:after {
  44.   content: " ";
  45.   display: block;
  46.   width: 100%;
  47.   clear: both;
  48. }
  49.  
  50. .jAudio--player .jAudio--controls ul {
  51.   display: table;
  52.   overflow: hidden;
  53.   width: 100%;
  54. }
  55.  
  56. .jAudio--player .jAudio--controls ul:after {
  57.   content: " ";
  58.   display: block;
  59.   width: 100%;
  60.   clear: both;
  61. }
  62.  
  63. .jAudio--player .jAudio--controls li {
  64.   position: relative;
  65.   width: 33.3333%;
  66.   height: 5rem;
  67.   line-height: 5rem;
  68. }
  69.  
  70. .jAudio--player .jAudio--thumb {
  71.   position: absolute;
  72.   top: 0;
  73.   left: 0;
  74.   height: 100%;
  75.   width: 100%;
  76.   background-size: cover;
  77.   background-position: center center;
  78. }
  79.  
  80. .jAudio--player .jAudio--time {
  81.   display: table;
  82.   width: 100%;
  83. }
  84.  
  85. .jAudio--player .jAudio--time:after {
  86.   content: " ";
  87.   display: block;
  88.   width: 100%;
  89.   clear: both;
  90. }
  91.  
  92. .jAudio--player .jAudio--time * {
  93.   width: 50%;
  94.   display: block;
  95.   float: left;
  96.   color: #fff;
  97.   text-shadow: 0 1px 1px #000;
  98.   font-size: 0.9rem;
  99. }
  100.  
  101. .jAudio--player .jAudio--time .jAudio--time-elapsed { text-align: left; }
  102.  
  103. .jAudio--player .jAudio--time .jAudio--time-total { text-align: right; }
  104.  
  105. .jAudio--player .jAudio--details * {
  106.   color: #fff;
  107.   text-shadow: 0 1px 1px #000;
  108.   font-size: 1.2rem;
  109. }
  110.  
  111. .jAudio--player .jAudio--details *:first-of-type { font-weight: bold; }
  112.  
  113. .jAudio--player .jAudio--details p { width: 100%; }
  114.  
  115. .jAudio--player .jAudio--details p span { display: block; }
  116.  
  117. .jAudio--player .jAudio--progress-bar { margin: 1.33333rem 0; }
  118.  
  119. .jAudio--player .jAudio--progress-bar .jAudio--progress-bar-wrapper {
  120.   width: 100%;
  121.   position: relative;
  122.   background: rgba(255, 255, 255, 0.3);
  123.   cursor: pointer;
  124.   border-radius: 10px;
  125.   overflow: hidden;
  126. }
  127.  
  128. .jAudio--player .jAudio--progress-bar .jAudio--progress-bar-played {
  129.   height: 10px;
  130.   background: #FF6666;
  131.   position: relative;
  132.   border-radius: 10px;
  133. }
  134.  
  135. .jAudio--player .jAudio--progress-bar .jAudio--progress-bar-pointer {
  136.   height: 10px;
  137.   width: 10px;
  138.   border-radius: 50%;
  139.   position: absolute;
  140.   right: 0;
  141.   background: #fff;
  142. }
  143.  
  144. .jAudio--player .jAudio--playlist { background: #fff; }
  145.  
  146. .jAudio--player .jAudio--playlist .jAudio--playlist-item {
  147.   display: block;
  148.   width: 100%;
  149.   padding: 1.33333rem 2rem;
  150.   display: table;
  151. }
  152.  
  153. .jAudio--player .jAudio--playlist .jAudio--playlist-item:after {
  154.   content: " ";
  155.   display: block;
  156.   width: 100%;
  157.   clear: both;
  158. }
  159.  
  160. .jAudio--player .jAudio--playlist .jAudio--playlist-item.active {
  161.   background: #f55c5c;
  162.   border-bottom-color: #f55c5c;
  163. }
  164.  
  165. .jAudio--player .jAudio--playlist .jAudio--playlist-item.active * { color: #fff; }
  166.  
  167. .jAudio--player .jAudio--playlist .jAudio--playlist-item:not(.active):hover { background: #fafafa; }
  168.  
  169. .jAudio--player .jAudio--playlist .jAudio--playlist-item:last-of-type {
  170.   border: 0;
  171.   margin-bottom: 0;
  172. }
  173.  
  174. .jAudio--player .jAudio--playlist .jAudio--playlist-thumb {
  175.   float: left;
  176.   margin-right: 0.66667rem;
  177.   display: table;
  178. }
  179.  
  180. .jAudio--player .jAudio--playlist .jAudio--playlist-thumb:after {
  181.   content: " ";
  182.   display: block;
  183.   width: 100%;
  184.   clear: both;
  185. }
  186.  
  187. .jAudio--player .jAudio--playlist .jAudio--playlist-thumb img {
  188.   height: 2.4rem;
  189.   width: 2.4rem;
  190.   border-radius: 50%;
  191.   float: left;
  192.   margin-right: 0.5rem;
  193. }
  194.  
  195. .jAudio--player .jAudio--playlist .jAudio--playlist-meta-text h4 {
  196.   font-size: 1rem;
  197.   color: #000;
  198. }
  199.  
  200. .jAudio--player .jAudio--playlist .jAudio--playlist-meta-text p { font-size: 0.8rem; }
  201.  
  202. .btn {
  203.   position: relative;
  204.   overflow: hidden;
  205.   position: absolute;
  206.   top: 0;
  207.   left: 0;
  208.   width: 100%;
  209.   height: 100%;
  210.   background: transparent;
  211.   border: 0;
  212. }
  213.  
  214. .btn span {
  215.   position: absolute;
  216.   display: table;
  217.   height: 15px;
  218.   top: 50%;
  219.   left: 50%;
  220.   -webkit-transform: translate(-50%, -50%);
  221.   -ms-transform: translate(-50%, -50%);
  222.   transform: translate(-50%, -50%);
  223.   overflow: hidden;
  224. }
  225.  
  226. .btn span:before, .btn span:after {
  227.   display: block;
  228.   content: " ";
  229.   height: 0;
  230.   float: left;
  231.   border-color: transparent;
  232.   border-style: solid;
  233. }
  234.  
  235. .btn:active { background: #f5f5f5; }
  236.  
  237. #btn-prev span:before, #btn-prev span:after, #btn-next span:before, #btn-next span:after, #btn-play span:before, #btn-play span:after {
  238.   border-top: 7.5px solid transparent;
  239.   border-bottom: 7.5px solid transparent;
  240. }
  241.  
  242. #btn-prev span:before, #btn-prev span:after {
  243.   border-right: 15px solid #ddd;
  244.   border-left: 0;
  245. }
  246.  
  247. #btn-prev:active span:before, #btn-prev:active span:after { border-right-color: #FF6666 !important; }
  248.  
  249. #btn-next span:before, #btn-next span:after {
  250.   border-left: 15px solid #ddd;
  251.   border-right: 0;
  252. }
  253.  
  254. #btn-next:active span:before, #btn-next:active span:after { border-left-color: #FF6666 !important; }
  255.  
  256. #btn-play span:before {
  257.   border-left: 15px solid #ddd;
  258.   border-right: 0;
  259. }
  260.  
  261. #btn-play span:after { display: none; }
  262.  
  263. #btn-play:active span:before, #btn-play.active span:before { border-left-color: #FF6666 !important; }
  264.  
  265. #btn-pause span:before, #btn-pause span:after {
  266.   width: 5px;
  267.   height: 15px;
  268.   background: #FF6666;
  269.   border: 0;
  270. }
  271.  
  272. #btn-pause span:before { margin-right: 5px; }
  273.  
  274. #btn-pause span:active:before, #btn-pause span:active:after, #btn-pause span.active:before, #btn-pause span.active:after {
  275.   background: #fff;
  276.   margin-right: 5px;
  277. }
  278.  
  279. .jAudio--player .jAudio--controls li button span:before, .jAudio--player .jAudio--controls li button span:after {
  280.   -webkit-transition: border-color 0.3s ease 0s;
  281.   transition: border-color 0.3s ease 0s;
  282. }
  283.  
  284. .jAudio--player .jAudio--thumb {
  285.   -webkit-transition: all 0.5s ease 0s;
  286.   transition: all 0.5s ease 0s;
  287. }
  288.  
  289. .jAudio--player .jAudio--progress-bar .jAudio--progress-bar-played {
  290.   -webkit-transition: all 0.2s ease 0s;
  291.   transition: all 0.2s ease 0s;
  292. }
  293.  
  294. .jAudio--player .jAudio--playlist .jAudio--playlist-item {
  295.   -webkit-transition: all 0.5s ease 0s;
  296.   transition: all 0.5s ease 0s;
  297. }
  298.  
  299. .jAudio--player .jAudio--playlist .jAudio--playlist-item * {
  300.   -webkit-transition: all 0.3s ease 0s;
  301.   transition: all 0.3s ease 0s;
  302. }

初始化插件:

首先需要做的事情是给音频播放器添加一个播放列表。播放列表是一个对象数组,它的格式如下所示。然后可以将播放列表变量以参数的形式传入 jAudio()方法中来初始化该音频播放器。

  1. var t = {
  2.   playlist: [
  3.     {
  4.       file: "resources/tracks/01.mp3",
  5.       thumb: "resources/thumbs/01.jpg",
  6.       trackName: "Dusk",
  7.       trackArtist: "Tobu & Syndec",
  8.       trackAlbum: "Single",
  9.     },
  10.     {
  11.       file: "resources/tracks/02.mp3",
  12.       thumb: "resources/thumbs/02.jpg",
  13.       trackName: "Blank",
  14.       trackArtist: "Disfigure",
  15.       trackAlbum: "Single",
  16.     },
  17.     {
  18.       file: "resources/tracks/03.mp3",
  19.       thumb: "resources/thumbs/03.jpg",
  20.       trackName: "Fade",
  21.       trackArtist: "Alan Walker",
  22.       trackAlbum: "Single",
  23.     }
  24.   ]
  25. }
  26.  
  27. $(".jAudio--player").jAudio(t);

配置参数:

该音频播放器的可用配置参数有:

playlist:播放列表

defaultAlbum:默认的专辑,默认值 undefined

defaultArtist:默认的歌手,默认值 undefined

autoPlay:自动播放,默认值为 false

debug:默认值为 false

Material design 风格 HTML5 audio 音频播放器

已有 439 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

评论:

1 条评论,访客:0 条,博主:0 条

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!