云盘资源分享论坛

 找回密码
 立即注册
搜索
热搜: 书籍 电影 音乐
查看: 180|回复: 0

音乐示例代码有吗?

[复制链接]

966

主题

156

回帖

4492

积分

中级会员

Rank: 3Rank: 3

UID
32013
金钱
3371
钻石
7
积分
4492
注册时间
2023-7-27
发表于 2023-8-13 14:00:22 | 显示全部楼层 |阅读模式

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>音乐播放器</title>
  5.   <style>
  6.     body {
  7.       background-color: #f5f5f5;
  8.       font-family: Arial, sans-serif;
  9.     }
  10.     .container {
  11.       max-width: 400px;
  12.       margin: 0 auto;
  13.       padding: 20px;
  14.       text-align: center;
  15.       background-color: #fff;
  16.       border-radius: 10px;
  17.       box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  18.     }
  19.     h2 {
  20.       margin-top: 0;
  21.     }
  22.     audio {
  23.       width: 100%;
  24.       margin-bottom: 20px;
  25.     }
  26.     .file-input-container {
  27.       text-align: left;
  28.       margin-bottom: 20px;
  29.     }
  30.     .file-input-container label {
  31.       display: inline-block;
  32.       padding: 10px 20px;
  33.       background-color: #2196f3;
  34.       color: #fff;
  35.       border-radius: 4px;
  36.       cursor: pointer;
  37.       transition: background-color 0.3s ease;
  38.     }
  39.     .file-input-container label:hover {
  40.       background-color: #0d8bf7;
  41.     }
  42.     .file-input-container input {
  43.       display: none;
  44.     }
  45.     button {
  46.       padding: 10px 20px;
  47.       font-size: 16px;
  48.       background-color: #2196f3;
  49.       color: #fff;
  50.       border: none;
  51.       border-radius: 4px;
  52.       cursor: pointer;
  53.       transition: background-color 0.3s ease;
  54.     }
  55.     button:hover {
  56.       background-color: #0d8bf7;
  57.     }
  58.     .lyrics {
  59.       text-align: left;
  60.       margin-top: 20px;
  61.       white-space: pre-wrap;
  62.       font-size: 14px;
  63.       line-height: 1.6;
  64.     }
  65.   </style>
  66. </head>
  67. <body>
  68.   <div class="container">
  69.     <h2>音乐播放器</h2>
  70.     <audio id="audio" controls>
  71.       <source src="" type="audio/mpeg">
  72.     </audio>
  73.     <div class="file-input-container">
  74.       <label for="fileInput">选择音乐文件</label>
  75.       <input type="file" id="fileInput">
  76.     </div>
  77.     <button id="playBtn">播放</button>
  78.     <button id="pauseBtn">暂停</button>
  79.     <div class="lyrics" id="lyricsContainer"></div>
  80.     <script>
  81.       var audio = document.getElementById('audio');
  82.       var playBtn = document.getElementById('playBtn');
  83.       var pauseBtn = document.getElementById('pauseBtn');
  84.       var fileInput = document.getElementById('fileInput');
  85.       var lyricsContainer = document.getElementById('lyricsContainer');

  86.       playBtn.addEventListener('click', function() {
  87.         audio.play();
  88.       });

  89.       pauseBtn.addEventListener('click', function() {
  90.         audio.pause();
  91.       });

  92.       fileInput.addEventListener('change', function(e) {
  93.         var file = e.target.files[0];
  94.         var url = URL.createObjectURL(file);

  95.         audio.src = url;
  96.         audio.play(); // 自动开始播放
  97.       });

  98.       // 歌词显示示例,需要替换为实际的歌词数据
  99.       var lyricsData = `
  100.         [00:00.00]歌词第一行
  101.         [00:05.00]歌词第二行
  102.         [00:10.00]歌词第三行
  103.       `;

  104.       // 将歌词数据显示在页面上
  105.       lyricsContainer.textContent = lyricsData;
  106.     </script>
  107.   </div>
  108. </body>
  109. </html>
复制代码


盘基地论坛免责声明
1、本站资源来自互联网用户收集发布,仅供用于学习和交流。
2、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。
3、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决。
4、联系邮箱:admin@panjdzy.com
5、官方网址:www.panjdzy.com
6、备用网址:www.panjd.top




上一篇:找出最大公约数和最小公倍数的快速方法?
下一篇:宇宙中的黑暗物质和黑暗能量究竟是什么?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|云盘资源分享论坛

GMT+8, 2025-6-25 15:20

Powered by Discuz!    联系邮箱:admin@panjdzy.com

本站资源来自互联网用户收集发布,仅供用于学习和交流。

如有侵权之处,请联系站长并出示版权证明以便删除,敬请谅解!

快速回复 返回顶部 返回列表