Search code examples
javascripthttpsplaylist

HTTPS block my audio playlist. How to solve it?


I created my first website and I'm trying to correct all my problems. I have a file javascript which can play songs automatically (audio playlist). It works on my computer and it worked when I uploaded.

Now, I securised my website and when I want to play my audio playlist, at the end of a song, it didn't go to the next song. Moreover, I'm redirected on the file (it leaves my principal page). I really don't understand this problem and I'm not enable to solve it alone.

Do you know if I can do something with my .htacess file or in my javascript file ?

var audio;
var playlist;
var tracks;
var current;
init();
function init(){
    current = 0;
    audio = $('audio');
    playlist = $('#playlist');
    tracks = playlist.find('li a');
    len = tracks.length;
    audio[0].play();
    playlist.find('a').click(function(e){
        e.preventDefault();
        link = $(this);
        current = link.parent().index();
        run(link, audio[0]);
    });
    audio[0].addEventListener('ended',function(e){
        current++;
        if(current < len){
            link = playlist.find('a')[current];  
            run($(link),audio[0]);  
        }
    });
}
function run(link, player){
    player.src = link.attr('href');
    par = link.parent();
    par.addClass('active').siblings().removeClass('active');
    audio[0].load();
    audio[0].play();
}

Solution

  • Your html includes

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    

    on a https site, http requests are blocked

    try

    <script type="text/javascript" src="//code.jquery.com/jquery-1.8.2.min.js"></script>
    

    without http or https the request will be made with the protocol used by the page, e.g. https if the page is https

    Once you fix that - your code may run - though your request for playlist.js fails and there's a 403 error when trying to use ErrorDocument - so the 403 is when trying to use ErrorDocument, but the error for getting playlist.js may be different