0
I’m trying to make a player, and I can’t use icons, I have to do everything on one page, I can’t change the text of the button to Pause
when the audio is running and Play
when the audio is paused, what I tried was that more did not work `videoElement pause.();
playButton.querySelector('span').className = "btPlay".innerHTML("Pause");`
` videoElement.play();
playButton.querySelector('span').className = "btPause".innerHTML("Pause");`
What am I doing wrong? Here’s the js
complete and the part of html
which refers to the button
when I refresh the page it plays normally, then I press pause
it pauses normally, and shows the button play
only then I shake play
it does not show the pause
and these two errors appear
var player, drag;
var audioElement, playButton, slider, audioButton, icoAudio;
function selectPlayer(elem){
if( player != elem ){
player = elem;
}
audioElement = player.querySelector('audio'); //Objeto do player
playButton = player.querySelector('.play'); //Botão play e pause
slider = player.querySelector('.slider');
sliderVol = slider.querySelector('.bar');
audioButton = player.querySelector('.audio');
//Ações do mouse
playButton.addEventListener('click', playAudio);
slider.addEventListener('mousedown', startDrag);
slider.addEventListener('mousemove', showVolume);
sliderVol.addEventListener('mousemove', showVolume);
slider.addEventListener('mouseup', startDrag);
sliderVol.addEventListener('mouseup', startDrag);
sliderVol.querySelector('span').addEventListener('mouseup', startDrag);
document.addEventListener('mouseup', startDrag);
audioButton.addEventListener('click', mute);
}
function startDrag(event){
if(event.type == "mousedown"){
drag = true;
}else{
drag = false;
}
}
function showVolume(event){
if(drag){
var w = slider.clientWidth;
var x = (event.clientX) - slider.offsetLeft;
var pctVol = x/w;
if(pctVol >1 ){
sliderVol.style.width = 100+"%";
audioElement.volume = 1;
}else if( pctVol < 0 ){
sliderVol.style.width = 0+"%";
audioElement.volume = 0;
}else{
sliderVol.style.width = (x/w) * 100+"%";
audioElement.volume = pctVol;
}
if(pctVol<=0){
audioButton.querySelector('span').className = 'ion-volume-mute';
}else if(pctVol>0 && pctVol<=0.6){
audioButton.querySelector('span').className = 'ion-volume-low';
}else{
audioButton.querySelector('span').className = 'ion-volume-medium';
}
}
}
function mute(){
if(!audioElement.muted){
audioElement.muted = true;
audioElement.volume = 0;
sliderVol.style.width = 0+"%";
audioButton.querySelector('span').className = 'ion-volume-mute';
}else{
audioElement.muted = false;
audioElement.querySelector('span').className = 'ion-volume-medium';
audioElement.volume = 0.9;
sliderVol.style.width = 90+"%";
}
}
function playAudio(){
// Verifica se a música foi iniciada
if(audioElement.played.length != 0){
// Verifica se a música foi pausada
if(audioElement.played.start(0)==0 && !audioElement.paused){
audioElement.pause(); // Pausa a música
playButton.querySelector('span').className = "btPlay"; // Muda a imagem do botão pause para o play
playButton.innerHTML = "<img src='http://i.cubeupload.com/Ad7lc8.png' width='25' height='25' alt='Reproduzir' title='Reproduzir'/>";
}else{
audioElement.play();
playButton.querySelector('span').className = "btPause"; // Muda a imagem do botão play para pause
playbutton.innerHTML = "<img src='http://i.cubeupload.com/SPRXTQ.png' width='25' height='25' alt='Pausar' title='Pausar'>";
}
}else{
audioElement.play(); //Se não estiver pausada ela toca automaticamente
playButton.querySelector('span').className = "btPause"; // Muda o icone do botão play para pause
playButton.innerHTML = "<img src='http://i.cubeupload.com/SPRXTQ.png' width='25' height='25' alt='Pausar' title='Pausar'>";
}
}
HTML
<!-- Botão de play e pause -->
<div class="control left play">
<!-- btPause -->
<!-- Como padrão a imagem que apresenta no player é de pausar -->
<span class="btPause"><img src='http://i.cubeupload.com/SPRXTQ.png' width='25' height='25' alt='Pausar' title='Pausar'></span>
</div>
You need to super edit this post, ta very messy..
– Matheus Vitor
was the best I could, wait, someone already edits, just does not understand why of the negative vote if I am here to learn, and I am not asking anything ready
– goio
It’s no use just throwing the code at the question. You need to be specific, show where things happen, explain, show clearly and accurately. Where it happens what, put arrows, screen prints, record a video etc. (no, dirty rs)... I made the joke just so you could see that you have to show the problem more clearly.
– Sam
Type: I have this button here (shows the code) and when clicking on it calls this function (code)... I want to click change the text from X to Y... the button starts with the text X....
– Sam
@dvd rsrs edited the question, I made the example of the friend down there and it worked, only it is giving an error, I do not know why
– goio