Does not change the volume at the audio tag during playback?

audioPlayerButtons function() {
 $player_back = $('#player-back');
 $player_next = $('#player-next');
 $player_random = $('#player-random');
 $player_pause = $('#player-pause');
 $player_play = $('#player-play');
 $player_volume = $('#player-volume');

 $audio.on('ended', function () {
 track_index += 1;
setTrack();
});

 $player_back.click(function (e) {
 if ((track_index - 1) < 0) {
 track_index = audioPlayerList.length - 1;
setTrack();
$audio.trigger('play');
return;
}

 track_index -= 1;
setTrack();
});

 $player_next.click(function (e) {
 if ((track_index + 1) > audioPlayerList.length) {
 track_index = 0;
setTrack();
$audio.trigger('play');
return;
}

 track_index += 1;
setTrack();
});

 $player_pause.click(function (e) {
$audio.trigger('pause');
});

 $player_play.click(function (e) {
$audio.trigger('play');
});

 $player_volume.change(function (e) {
 $audio.volume = $player_volume.val() / 100;
console.log($audio.volume);
});
}

function setTrack() {
 first_audio_track = audioPlayerList[0];
 track_index = 0;

 $audio.attr('src', audio_path + first_audio_track.file);
$current_track_name_ui.text(first_audio_track.filename);

 if (first_audio_track.youtube) {
$current_track_link_ui.show();
 $current_track_link_ui.attr('href', first_audio_track.youtube);
 } else {
$current_track_link_ui.hide();
}
}

initializeAudioPlayer function() {
 audio_path = '/storage/tracks/kimberannie/';

 $audio = $('#audio');
 $current_track_name_ui = $('.kimberly-radio .track .running p');
 $current_track_link_ui = $('.kimberly-radio .track .running a');

 if (audioPlayerList.length === 0) return;

audioPlayerButtons();
setTrack();

 // $audio.trigger('play');
}

initializeAudioPlayer();


Does not change the sound of the audio tag during playback
March 19th 20 at 08:30
2 answers
March 19th 20 at 08:32
Solution
At the Audio object, all the rules work the tag is not. Decided
audioPlayerButtons function() {
 $player_back = $('#player-back');
 $player_next = $('#player-next');
 $player_random = $('#player-random');
 $player_pause = $('#player-pause');
 $player_play = $('#player-play');
 $player_volume = $('#player-volume');

 audio.addEventListener('onended', function () {
 track_index += 1;
setTrack();
});

 $player_back.click(function (e) {
 if ((track_index - 1) < 0) {
 track_index = audioPlayerList.length - 1;
setTrack();
audio.play();
return;
}

 track_index -= 1;
setTrack();
});

 $player_next.click(function (e) {
 if ((track_index + 1) > audioPlayerList.length) {
 track_index = 0;
setTrack();
audio.play();
return;
}

 track_index += 1;
setTrack();
});

 $player_pause.click(function (e) {
audio.pause();
});

 $player_play.click(function (e) {
audio.play();
});

 $player_volume.change(function (e) {
 audio.volume = $player_volume.val() / 100;

});
}

function setTrack() {
 first_audio_track = audioPlayerList[0];
 track_index = 0;

 audio.src = audio_path + first_audio_track.file;
$current_track_name_ui.text(first_audio_track.filename);

 if (first_audio_track.youtube) {
$current_track_link_ui.show();
 $current_track_link_ui.attr('href', first_audio_track.youtube);
 } else {
$current_track_link_ui.hide();
}
}

initializeAudioPlayer function() {
 audio_path = '/storage/tracks/kimberannie/';

 audio = new Audio();
 $current_track_name_ui = $('.kimberly-radio .track .running p');
 $current_track_link_ui = $('.kimberly-radio .track .running a');

 if (audioPlayerList.length === 0) return;

audioPlayerButtons();
setTrack();
}

initializeAudioPlayer();
At the Audio object, all the rules work the tag is not. Decided

In both cases, the variables $audio, and audio to be announced, you probably don't show all the code, and what exactly is happening is unclear.
It is also unclear which of them "audio object".

In the first variant, for some reason, you set the value to the volume from the jquery wrapper. Of course, it does not change the volume. - Casimir58 commented on March 19th 20 at 08:35
@Casimir58, why is it not declared?
audio = new Audio(); - lucious.Dietri commented on March 19th 20 at 08:38
@lucious.Dietri, before the variable has no keywords.
the fact that it somehow works is luck.
when you crash - a question of time. - Casimir58 commented on March 19th 20 at 08:41
March 19th 20 at 08:34
It is necessary not only to change the src, but to call play().
Made a mistake in the title of the question, reread)) - lucious.Dietri commented on March 19th 20 at 08:37

Find more questions by tags HTMLJavaScript