Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Counting the plays

    On my music site I am using the Kolber audio.js script along with the html5 audio player.
    All is working just fine. Now I need to count the plays.
    I need some way of keeping track of song played which will update my database table on the fly.
    I tried using a simple iframe but that did not seem to work properly.
    The basic script for how he does the switching of playing the songs is posted below.
    If anyone wants to tackle the job, I would appreciate the help.
    If you require to be paid for your services, we can work on that as well.

    audio.js

    working page
    Mr Oldies online radio station

    Code:
          $(function() { 
            // Setup the player to autoplay the next track
            var a = audiojs.createAll({
              trackEnded: function() {
                var next = $('ol li.playing').next();
                if (!next.length) next = $('ol li').first();
                next.addClass('playing').siblings().removeClass('playing');
                audio.load($('a', next).attr('data-src'));
                audio.play();
              }
            });
            
            // Load in the first track
            var audio = a[0];
                first = $('ol a').attr('data-src');
            $('ol li').first().addClass('playing');
            audio.load(first);
    
            // Load in a track on click
            $('ol li').click(function(e) {
              e.preventDefault();
              $(this).addClass('playing').siblings().removeClass('playing');
              audio.load($('a', this).attr('data-src'));
              audio.play();
            });
            // Keyboard shortcuts
            $(document).keydown(function(e) {
              var unicode = e.charCode ? e.charCode : e.keyCode;
                 // right arrow
              if (unicode == 39) {
                var next = $('li.playing').next();
                if (!next.length) next = $('ol li').first();
                next.click();
                // back arrow
              } else if (unicode == 37) {
                var prev = $('li.playing').prev();
                if (!prev.length) prev = $('ol li').last();
                prev.click();
                // spacebar
              } else if (unicode == 32) {
                audio.playPause();
              }
            })
          });

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by Suwannee_guy View Post
    I need some way of keeping track of song played which will update my database table on the fly.
    I tried using a simple iframe but that did not seem to work properly.
    This is not a job for Javascript. For security reasons Javascript is not able to create, write to, modify or delete any file. It can only read files (using AJAX).


    This is the seventh time these teams have met, but they haven't met since the last time they played. - Commentator Channel 4

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •