@arseniylebedev

Не меняется громкость у аудио тега во время проигрывания?

function audioPlayerButtons() {
    $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();
    }
}

function initializeAudioPlayer() {
    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();


Не меняется звук у аудио тега во время проигрывания
  • Вопрос задан
  • 71 просмотр
Решения вопроса 1
@arseniylebedev Автор вопроса
У Audio объекта все норм работает у тега нет. Решил
function audioPlayerButtons() {
    $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();
    }
}

function initializeAudioPlayer() {
    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();
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
Stalker_RED
@Stalker_RED
Надо не только сменить src, но и вызвать play().
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
28 нояб. 2024, в 13:22
1000 руб./за проект
28 нояб. 2024, в 13:00
70000 руб./за проект
28 нояб. 2024, в 12:59
30000 руб./за проект