vibe coding 了一个音乐播放器,技术门槛其实为零

我最开始使用腾讯云控制台,对象存储的存储桶。 上传了几首歌,接着就是我几个小时的debug。 我把html文件保存到这个存储桶,然后也启用了静态网站域名(这里如果自定义域名必须要备案),但是这个URL我在浏览器打开会直接下载html文件而不是显示音乐播放器。

于是我加了一个header,也就是第二行。于是Windows端可以正常显示出来,但是Android端无法显示,仍是下载html文件

chrome_sXzhpUHZcB.png

解决方案是把腾讯云的html删掉,使用 Cloudflare ,在 Compute → workers & pages 新建一个 Application,这里一定要把html文件放在文件夹里面,把文件夹上传过去。 接下来可以自定义域名,一套流程行云流水。 在Notion可以完美embed这个播放器,速度很快。 我实在是不喜欢腾讯的生态,在六月初便把 zanemono.com 的 Register 迁移到 Cloudflare了。

https://music.zanemono.com/

这是 Gemini 给我的代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Zane's Jukebox - Notion Optimized</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css">
  <style>
    /* 1. 基础重置与居中逻辑 */
    * { margin: 0; padding: 0; box-sizing: border-box; }
    
    body, html {
      width: 100%;
      height: 100%;
      background: transparent !important; /* 核心:确保背景透明以适应 Notion */
      overflow: hidden;
      display: flex;
      justify-content: center; /* 水平居中 */
      align-items: center;     /* 垂直居中 */
    }

    /* 2. 播放器容器优化 */
    .player-container {
      width: 92%;              /* 左右留出间距,不挨着边沿 */
      max-width: 500px;        /* 限制最大宽度,防止在大屏下太散 */
      padding: 10px;
      transition: all 0.3s ease;
    }

    #player {
      border-radius: 16px;     /* 更圆润的边角 */
      overflow: hidden;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); /* 更柔和的阴影 */
      background: #fff;        /* 默认浅色背景 */
    }

    /* 3. APlayer 内部样式修正 */
    .aplayer {
      margin: 0 !important;
      border: none !important;
    }

    /* 修正图片显示:确保封面图在不同尺寸下都能正确填充 */
    .aplayer .aplayer-pic {
      background-size: cover !important;
      background-position: center !important;
      transition: all 0.3s ease;
    }

    /* 按钮大小适中微调 */
    .aplayer .aplayer-icon {
      width: 18px !important;
      height: 18px !important;
      opacity: 0.8;
    }

    /* 4. 列表与滚动条简约化 */
    .aplayer .aplayer-list {
      text-align: left;
    }
    .aplayer-list::-webkit-scrollbar { width: 4px; }
    .aplayer-list::-webkit-scrollbar-thumb {
      background: #ccc;
      border-radius: 10px;
    }

    /* 5. 适配 Notion 深色模式 */
    @media (prefers-color-scheme: dark) {
      #player {
        background: #2f3437; /* 匹配 Notion 深色模式背景色 */
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
      }
      .aplayer {
        background: #2f3437 !important;
        color: #efefef !important;
      }
      .aplayer .aplayer-info .aplayer-music .aplayer-title { color: #fff !important; }
      .aplayer .aplayer-info .aplayer-music .aplayer-author { color: #999 !important; }
      .aplayer .aplayer-list { background: #2f3437 !important; }
      .aplayer .aplayer-list ol li { border-top: 1px solid #3f4447 !important; }
      .aplayer .aplayer-list ol li:hover { background: #3f4447 !important; }
      .aplayer .aplayer-list ol li.aplayer-list-light { background: #3f4447 !important; }
    }
  </style>
</head>
<body>

  <div class="player-container">
    <div id="player"></div>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js"></script>
  <script>
    const songs = [
      {
        name: 'title',
        artist: 'Artist',
        url: '.mp3',
        cover: '.jpg'
      }

    ];

    const ap = new APlayer({
      container: document.getElementById('player'),
      fixed: false,          // 不开启吸底模式,适合 Embed
      autoplay: false,
      theme: '#c026d3',      // 主题色
      loop: 'all',           // 列表循环
      order: 'random',       // 默认随机播放模式
      listFolded: true,      // 默认折叠列表
      listMaxHeight: '200px',
      preload: 'metadata',   // 仅预加载元数据,节省流量
      audio: songs
    });

    // 进阶优化:确保每次打开页面时都随机切入一首不同的歌
    // 注意:部分浏览器策略限制,可能需要用户点击后才能切歌,但逻辑已就绪
    window.onload = () => {
        ap.list.switch(Math.floor(Math.random() * songs.length));
    };

    // 自动报错跳过逻辑
    ap.on('error', () => {
      console.error('资源加载失败,尝试跳过...');
      setTimeout(() => ap.skipForward(), 1000);
    });
  </script>
</body>
</html>