- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我提出了一些问题,试图使音乐播放器完成工作,并得出结论,我需要重新编写代码。有了这个新鲜的代码,它变得更加流畅了,我现在相信我的错误是一个简单的修复程序,但我不确定它们是什么。我将在下面提供一个简短的视频以及说明和代码。感谢您对我哪里出错了的任何投入和解释!
因此,在页面加载/刷新后,track1的标题为“Send Me On My Way”(可以在HTML中看到)。但是,这不会播放歌曲。音轨1(或其他)将播放以下(nextSong / previousSong)功能。然后它将显示track1.mp3(不是标题),我试图编辑文件中歌曲的名称,但后来没有播放。
这是使播放器按预期方式启动和运行的主要问题。最后,我希望通过允许用户跳过这首歌来向进度条添加一些功能,虽然这不是完全需要的,但是可以通过简单的编辑来实现。
下面的视觉
https://imgur.com/a/oFuBKLY
</audio>
<header id="about">
<div class="menu">
<span class="bar"></span>
</div>
<nav class="nav">
<div class="overlay">
<ul>
<li><a href="index.html">Home</a> </li>
<li><a class=active href="Album.html">Album</a> </li>
<li><a href="Gallery.html">Gallery</a> </li>
<li><a href="Book.html">Book Us</a> </li>
</ul>
</div>
</nav>
<div id="main">
<div id="image">
<img src="/images/J&G Logo.png"/>
</div>
<div id="player">
<div output id ="songTitle" >Im On My Way</div>
<div id="buttons">
<button id="pre" onclick="pre()"><img src="/images/backwards.png"></button>
<button id="play" onclick="playOrPauseSong()"><img src="/images/play.png"></button>
<button id="next" onclick="next()"><img src="/images/forwards.png"></button>
</div>
</div>
<div id="seek-bar">
<div id="fill"></div>
<div id="handle"></div>
</div>
</div>
var songs = ["/music/Track1.mp3", "/music/Track2.mp3", "/music/Track3.mp3", "/music/Track4.mp3", "/music/Track5.mp3", "/music/Track6.mp3", "/music/Track7.mp3"];
var poster = ["/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png"];
var songTitle = document.getElementById("songTitle");
var fillBar = document.getElementById("fill");
var song = new Audio();
var currentSong = 0;
function playSong(){
song.src = songs[currentSong];
songTitle.textContent = songs[currentSong];
song.play();
}
function playOrPauseSong(){
if(song.paused){
song.play();
$("#play img").attr("src","/images/Pause.png");
}
else{
song.pause();
$("#play img").attr("src","/Images/Play.png");
}
}
song.addEventListener('timeupdate',function(){
var position = song.currentTime / song.duration;
fillBar.style.width = position * 100 +'%';
});
function next(){
currentSong++;
if(currentSong > 6){
currentSong = 0;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function pre(){
currentSong--;
if(currentSong < 0){
currentSong = 6;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
最佳答案
我根据您的代码,进度条和非常基本的标题选择逻辑创建了一个小示例。我还修复了第一个播放 Action 和第一个标题问题。
您可以引用w3schools,在其中可以找到有关事件和标签属性的更多示例。
var songs = ["https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-5.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-6.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-7.mp3"];
var poster = ["/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png"];
var titles = ["I'm On My Way", "Rolling In The Deep", "Mad World", "Too Close", "Feelin' Good", "I Will Wait", "All These Things That I've Done"]
var songTitle = document.getElementById("songTitle");
var fillBar = document.getElementById("fill");
var song = new Audio();
var currentSong = 0;
songTitle.textContent = titles[currentSong];
function playSong(){
song.src = songs[currentSong];
songTitle.textContent = titles[currentSong];
song.play();
}
function playOrPauseSong(){
if(song.paused){
playSong();
$("#play img").attr("src","/images/Pause.png");
}
else{
song.pause();
$("#play img").attr("src","/Images/Play.png");
}
}
song.addEventListener('timeupdate',function(){
$('#seekbar').attr("value", this.currentTime / this.duration);
});
function next(){
currentSong++;
if(currentSong > songs.length - 1){
currentSong = 0;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function pre(){
currentSong--;
if(currentSong < 0){
currentSong = songs.length - 1;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function countProgress(event) {
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</audio>
<header id="about">
<div class="menu">
<span class="bar"></span>
</div>
<nav class="nav">
<div class="overlay">
<ul>
<li><a href="index.html">Home</a> </li>
<li><a class=active href="Album.html">Album</a> </li>
<li><a href="Gallery.html">Gallery</a> </li>
<li><a href="Book.html">Book Us</a> </li>
</ul>
</div>
</nav>
<div id="main">
<div id="image">
<img src="/images/J&G Logo.png"/>
</div>
<div id="player">
<div output id="songTitle"></div>
<div id="buttons">
<button id="pre" onclick="pre()"><img src="/images/backwards.png"></button>
<button id="play" onclick="playOrPauseSong()"><img src="/images/play.png"></button>
<button id="next" onclick="next()"><img src="/images/forwards.png"></button>
</div>
</div>
<progress id="seekbar" value="0" max="1" style="width:200px;"></progress>
</div>
关于javascript - JavaScript音乐播放器(进度栏+轨道标题错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61663784/
我想使用 Orbited 进行聊天。我还找到了 Orbited2。有什么不同? Orbited 死了没有?我想用solid solution,不用担心会被关闭或不支持。我还没有找到任何关于 Orbit
我最近开始学习SFML,我有一个问题,如何使第二个物体在轨道上运动,请帮助。 #include using namespace sf; int main() { RenderWindow wi
我正在尝试使用 Tweepy 获取所有带有关键字的推文,但它没有返回某些关键字的任何内容。例如,如果使用 Obama 作为关键字,我会收到很多推文,如果我使用 Arduino,我不会收到任何返回信息,
在我看来,我有一个复选框和一个标签。我正在使用 SLIM,所以代码是 = check_box_tag 'All Products' = label_tag 'All Products' 生成的等效 H
正如倾斜所暗示的那样,我试图弄清楚如何嵌入 soundcloud 文件,以及如何轻松更改嵌入的声音.. 我有一个网站,目前,让用户写一个故事,然后附加一个图像或视频。对于视频,我使用 vimeo 和
我创建了一个在应用程序的实际背景上绘制的 slider 轨道,并且还绘制了 UISlider 拇指图像。我知道如何设置 slider 的缩略图。但如何隐藏 UISlider 轨道呢? 最佳答案 如果你
从 HTTP 链接下载的 Windows Media DRM 轨道是否可以合法渐进播放? 我已经设法在没有 DRM 的情况下做到了这一点,但这里有人告诉我,使用 DRM 是不可能的。这是真的? 如果是
我有一个简单的 vtt 轨道文件编辑器,其中构建的 vtt 文件内容保存在 var vtt 中. 目前我通过保存vtt的内容来添加轨道。到文件,然后将文件读取为 我想省略保存到文件的步骤,直接将变量
我有一个简单的应用程序,用户可以在其中的文本字段中输入内容以获得各种结果。我想要一个功能,如果用户输入某些内容然后关闭浏览器选项卡,下次他们来时,我可以向他们展示他们之前/最近的搜索。即使他们关闭整个
我试图在不同的线程中同时运行 4 个 MP3 轨道。我正在使用 JLayer1.0 MP3 library播放 MP3。鉴于我无法控制线程何时启动,我使用 CountDownLatch 至少让它们同时
我可以在我的 Android 应用程序中播放来自 SoundCloud 的轨道吗?我正在尝试这段代码,但它不起作用: String res = "https://api.soundcloud.com/
我正在使用 Apple Music API 的 recent played endpoint返回最近播放的媒体 Assets 列表。 然后我使用其中之一并在 MPMusicPlayerControll
我正在使用 Foundation Orbit slider 。它工作正常,只是我需要将一些 css(移动标题)应用于页面上的特定 slider 。 如果我使用以下选择器,它会进行更改,唯一的问题是它是
我最难搞清楚如何在 Foundation 的 Orbit slider 中制作两个文本元素和一个按钮。对于这样的初学者问题,我深表歉意,但我是 Foundation 的新手,有些语法让我感到困惑。 这
我需要来自 SoundCloud 的“最流行”或“ HitTest 门的轨道”,但我找不到任何方法来做到这一点。我可以从 http://api.soundcloud.com/tracks?filter
我刚刚从 Rails 3.2 切换到 Rails 4。我正在努力确保我尽可能了解安全问题,并且我现在担心 session 。看起来 Rails 4 已经不再支持除基于 cookie 的 session
我正在开发一个应用程序,用户可以在其中流式传输或下载视频。我使用 ExoPlayer 2.9.6 实现了相同的功能。目前,在播放下载的内容时,当我尝试切换质量时,它仅显示下载的轨道。我知道它的默认行为
有谁知道制作这样的标题的最佳方法 http://i.imgur.com/NOSF0.png ?我试过使用 Firebug 并实现了这个 http://i.imgur.com/cMB3Y.png但是当我
我正在使用 Zurb 轨道 slider :http://www.zurb.com/playground/jquery_image_slider_plugin 我使用以下设置进行幻灯片放映: $(wi
所以我们在这里:http://greeceinsiders.com/VLASIOS/offcanvas/studio.html 我按照说明在页面中放置轨道 slider ,但这个似乎不起作用。我从其他
我是一名优秀的程序员,十分优秀!