-2
I have this playlist script, in it I wanted the name of the video selected in the playlist turns to P tag
$(document).ready(function() {
video = $("#video");
nome = $("#nome");
init();
function init() {
current = 0;
playlist = $("#playlist");
tracks = playlist.find("li a");
len = tracks.length;
playlist.find("a").click(function(e) {
e.preventDefault();
link = $(this);
current = link.parent().index();
run(link);
});
$("#anterior").on("click", function(e) {
current--;
if (current == len) {
current = 0;
link = playlist.find("a")[0];
} else {
link = playlist.find("a")[current];
}
run($(link));
});
$("#proximo").on("click", function(e) {
current++;
if (current == len) {
current = 0;
link = playlist.find("a")[0];
} else {
link = playlist.find("a")[current];
}
run($(link));
});
}
function run(link) {
video.src = link.attr("href");
nome.innerHTML = link.innerHTML
par = link.parent();
par.addClass("active").siblings().removeClass("active");
video.load();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<p id="nome"></p>
<video id="video" width="200px" controls class="player" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">
Video nao suportado
</video>
<div id="anterior">proximo</div>
<div id="proximo">anterior</div>
<ul id="playlist">
<li class="active"><a href="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">Big Buck Bunny 1</a></li>
<li><a href="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">Big Buck Bunny 2</a></li>
<li><a href="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4">Big Buck Bunny 3</a></li>
</ul>
it is better to use in the second function, the way it is not working in the buttons, only if you click on the tag A
– João Victor
which buttons? you are referring to the
div
previous and next?– Gabriel Gonçalves
I changed the code for the functioning of the "buttons", first when clicking it takes the
href
tag<a>
and then assigns a new value to the video, that is, changes the video, according to thehref
of the tag and it already takes her text and updates the title<p>
. Also, I put a condition structure, for if the value is less than 0, it returns to 0, because in your code when you click on the previous one it decreases to -1, for example.– Gabriel Gonçalves