Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript playing music on a site

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #42659
    chanman
    Member

    I realize this idea is totally outdated but my client wants it and what the client wants most of the time the client gets. I figured out how to put music on the site and it works great and is fast. what i’m wanting to know is there a way to when the site loads there is a popup which says there is music do they want it to play or not. Me and a friend have the popup kinda working but the music plays regardless of the popup. I’ll post the pen in a little bit.

    #124119
    chanman
    Member

    The pen is here: http://cdpn.io/xIKFw
    Sorry but I don’t have time to post the images so the css won’t work right. If you cant figure it out without them let me know and ill post them when I get a chance.

    #124120
    tomrogers123
    Member

    It would be easy to give the user a warning using JavaScript. You could attach an event handler to the document and run this when it was ready:

    window.confirm(“if you wish to continue music will stop playing”);

    You could then write logic that. if they confirmed, would fire the audio playing (only if you have a JS API).

    #124121
    chanman
    Member

    I don’t really know but just a little js so your probably going to have to do this in baby steps.

    #124129
    chrisburton
    Participant

    I would talk the client out of it. Just because the client likes it doesn’t mean majority of his user base will. And that’s what is important.

    #124247
    tomrogers123
    Member

    Playing around, this JS seems to work:

    var selection = window.confirm(‘This page has sound on it. Confirm to play’),
    testTrack = document.getElementById(‘audio’);

    if(selection == true) {
    testTrack.load();
    testTrack.play()
    }

    That doesn’t sort out your pause link quite yet (can add if needed), but it does make it so it will only start playing if they click OK at the confirmation. If you need anymore help let me know. Interestingly also, I couldn’t just update the codepen because confirm doesn’t seem to run.

    I do kinda agree with @chrisburton too though in that having a big popup when the page loads is obtrusive and may hinder good UX. But hey, if that’s what you need that’s fine I guess :)

    #124249
    chanman
    Member

    Thanks guys I’m probably going to try and talk him out of it but this would still be a good thing to know how to do.

    #124252
    tomrogers123
    Member

    Smart move I think!

    #123764
    chrisburton
    Participant

    @tomrogers123 I disagree. I don’t think it’s “fine” to force a user to have to automatically get rid of an unnecessary popup. Especially every time you visit the site (unless he’s using a cookie).


    @chanman
    Let us know what your client comes back with in case you need help convincing.

    #124415
    chanman
    Member

    @tomrogers123 where would I need to put that code in this code:

    $(document).ready(function(){
    var name = prompt(“Would you like to play background music?(yes or no)” );
    var Audio = document.getElementById(‘audio’),
    ctrl = document.getElementById(‘audio-controls’);
    ctrl.onclick = function () {
    var pause = ctrl.innerHTML === ‘pause’;
    ctrl.innerHTML = pause ? ‘play’ : ‘pause’;
    ctrl.className = pause ? ‘pause’ : ‘play’;

    var method = pause ? ‘pause’ : ‘play’;
    Audio[method]();

    return false;
    };
    if(name === “yes”){$(document).ready();}
    else{ctrl.onclick();}
    });

    #124426
    Paulie_D
    Member

    >Just allow them to turn it off. That’s all you need

    Nope…give them the option to turn it on….much better.

    #124440
    Paulie_D
    Member

    >Depending on the site. Sometimes it fits.

    Strongly disagree. I surf… a lot…and I can’t think of a single site I have EVER visited that would benefit from having sound activated by default.

    #124438
    chanman
    Member

    @eric my problem with it is what if somebody opens it up in there office or even better in the library and the speakers were left to high from the last person that’s going to scare them to death.


    @paulie_d
    thanks for backing me up on this I think were totally right.

    #124444
    chanman
    Member

    @eric ok i’ll agree but i think you have to think about what kind of song it is also and how loud it’s going to play on default.

    #124446
    Paulie_D
    Member

    One other thing….If you go down the route of NOT having sound by default then then the option should be given in a special section of the page (perhaps in the header or at the top of an aside) to say something like…”We have sound…click here to enable”.

    I hate anything that pops up.

Viewing 15 posts - 1 through 15 (of 21 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.