blog.humaneguitarist.org

discoveries in digital audio, music notation, and information encoding

geo this, geo that: easy acquisition of KML files with BatchGeo

leave a comment

Geolocation/geocoding is so "hip" these days. Everyone's so obsessed where where they and other things are. There's almost a comparison with 3-D filmmaking …

Funny. Not too many folks seem all that concerned with when things are.

Anyway …

At work, we have a database with all the libraries we serve and their addresses. And the other week we needed to quickly make a map with all their locations.

If necessity if the mother of invention, laziness is it's favorite uncle.

Enter BatchGeo. We were able to take those values from our database and get a map generated in minutes. But it gets better.

One of the nice things about this process is that in addition to a map, you also get a KML file download option. Taking this little XML file, it's a simple process (via XSL or other) to make a delimited file containing the inputted names of institutions and their latitude and longitude (altitude is also available).

From there, it's not brain surgery to get those coordinates into a database and using an SQL JOIN to be able to push out an institution's name and now its coordinates, too, whenever.

Just in case someone wants/needs to do something similar with an address book or a list of businesses, etc.

--------------

Related Content:

Written by nitin

January 28th, 2012 at 9:52 am

Posted in technophilia,XML

Tagged with , , , ,

holy silence: the art of movie theaters

leave a comment

Tonight's a bust. I over-napped after work and now, as I listen to some Josquin des Prez, I think the most I can do tonight is write a little blog post and then go out for a beer.

I saw "The Artist" this weekend. I don't give a rip about critics and awards, etc. but, having said that, this one reaches the heights of sublimity.

movie poster for The Artist

This is the first time I've seen a silent, well mostly silent, film on the big screen. Big images and big music. It was really beautiful and sorrowful to think how this has been sublimated to talkies and now the "everything must be in 3-D" way. It's a good reminder in general, but also in the library context, that new and newer technology isn't necessarily better. It's just different. With every gain, something is lost.

Watching the film also reminded me of a newsletter entry and interview I worked on during my time at SCIWAY.net. I interviewed John Coles and Mark Tiedje of SCMovieTheatres.com about their research into South Carolina movies and movie theaters of the past. You can read the newsletter entry here and the interview here.

When my co-worker Cedric and I interviewed John and Mark, we did so at the Majestic Grill in Charleston, SC. Sadly, like many old movie theaters the restaurant and all its crazy film memorabilia are no longer being shown, as it were. The interview lasted well over four hours; there was just too much great stuff we learned. I still remember I'd talked to John and Mark about watching some old Saturday serials together. In particular, we talked a little about this Batman serial from the 1940's I'd recently seen and how it was total war propaganda replete with racial slurs toward the "enemy".

Well, I'm feeling like George Valentin from "The Artist" – old and washed up in my nostalgia for the past. Like him, I think I'll turn to the bottle, but for me it's going to be of the beer variety.

    Written by nitin

    January 24th, 2012 at 9:31 pm

    trying to easily format Solr results as HTML with Python

    leave a comment

    Just a quick Saturday morning post …

    One of the nice things about Solr is the ability to pass parameters that will return the results in various formats, including a Python dictionary.

    I wanted to see if I could whip up a little function that would let me pass to it both the name of a Solr element (like "title") and then the HTML element I want it mapped to.

    It doesn't seem that bad, and is a good reminder that building UIs is in large part about parsing data into HTML, upon which things like CSS and JavaScript can enter and act re: display and interface.

    Anyway, so here's an example of some code that gets five results from a Solr instance and then uses the function I wrote to output some HTML elements:

    import urllib2 as urllib
    
    ### first, get 5 Solr results formatted as a Python dictionary
    query_url = 'http://data.twigkit.com/solr-gutenberg/select/?q=poe&version=2.2&start=0&rows=5&wt=python&explainOther'
    solr = urllib.urlopen(query_url).read() #read the results
    print type(solr) #returns that it's a string :-[
    solr = eval(solr) #turns the string into a dictionary. yay.
    print type(solr) #returns that it's now a dictionary!
    
    ### second, write a function that converts stuff to HTML
    def pysolr2html(tagIn, tagOut):
        tagVal = solr['response']['docs'][i][tagIn]
        htmlVars = (tagOut, tagIn, tagVal, tagOut)
        return '<%s class="solr_%s">%s</%s>' %htmlVars
    
    ### third, iterate over the response
    i = 0
    for doc in solr['response']['docs']:
        print pysolr2html('id','span')
        print pysolr2html('title','p')
        i = i + 1
    

    And here's the output from IDLE:

    >>>
    <type 'str'>
    <type 'dict'>
    <span class="solr_id">etext8893</span>
    <p class="solr_title">Selections from Poe</p>
    <span class="solr_id">etext9511</span>
    <p class="solr_title">Several Works by Edgar Allan Poe</p>
    <span class="solr_id">etext9512</span>
    <p class="solr_title">The Works of Edgar Allan Poe, Volume 1</p>
    <span class="solr_id">etext9516</span>
    <p class="solr_title">The Works of Edgar Allan Poe, Volume 5</p>
    <span class="solr_id">etext9513</span>
    <p class="solr_title">The Works of Edgar Allan Poe, Volume 2</p>

    I'll probably do this with PHP in the end and see how easy it might be to make a small Solr wrapper, kind of like Tempo which is super light-weight. But for now, I need to remind myself it's the weekend.

    :P

    --------------

    Related Content:

    Written by nitin

    January 21st, 2012 at 12:03 pm

    Hammer prepares to nail restoration efforts

    leave a comment

    From the folks at the Brutal as Hell website:

    Here’s some killer news for fans of Hammer Horror. Yesterday Hammer announced that they would be partnering with several film outlets to bring over 30 of their classic horror flicks to Blu-ray in the coming months and years … What makes this a notable project is that Hammer is investing heavily in the restoration of these films, as opposed to taking the lazy man’s road and creating basic upconverted dumps.

    source: Hammer Films to Launch Monumental Restoration Project | Brutal As Hell. Retrieved January 20, 2012, from http://www.brutalashell.com/2012/01/hammer-films-to-launch-monumental-restoration-project/

    You can read more at Hammer's official WordPress blog here.

    I don't have a Blu-ray player, but this should eventually be good news for streaming, too. Gawd, I wish I was in the film restoration business.

    --------------

    Related Content:

    Written by nitin

    January 20th, 2012 at 11:33 pm

    Posted in film,news

    Tagged with ,

    installing lxml on my Amazon Linux instance

    leave a comment

    Last night I installed lxml on my Amazon Linux AMI (ami-31814f58) and it was just as not-straightforward as when my co-worker and I put it on our CentOS sever a few weeks ago.

    So by referring to the yum log, I think the following covers what I needed to install with yum:

    gcc-4.4.5-6.35.amzn1.i686 #for building lxml
    python26-devel-2.6.7-1.36.amzn1.i686
    libxslt-1.1.26-2.6.amzn1.i686 #this can't be necessary given the line below, right?
    libxslt-devel-1.1.26-2.6.amzn1.i686
    libxml2-devel-2.7.6-1.9.amzn1.i686

    … and then I used easy_install (which already was on the system 'far as I know) to install lxml a la: easy_install lxml.

    For whatever reason, the easy_install part took several, several minutes. But I was watching "Season of the Witch" so I didn't mind.

    --------------

    Related Content:

    Written by nitin

    January 16th, 2012 at 10:39 am

    Posted in technophilia

    Tagged with , , , ,

    syntax highlighting on WordPress: you can quote me on this

    leave a comment

    I've totally over-blogged this month, but just as a note to self …

    I've noticed that when using a syntax highlighter with WordPress – I'm using Syntax Highlighter Compress – that using single quotes can sometimes cause the highlighting to break down.

    In the example below I have identical code written twice. Well, almost identical. In the first, I'm surrounding "data-startTime" with single quotes and in the second I'm using doubles. The first has some highlighting problems where single quotes are.

    Oh well, I guess I'll just have to keep an eye on that.

    function jAUs_3(this_currentTime,thisAudioTag_stopTime,i){
    
      if (thisAudioTag_stopTime){
        //if there's a data-stopTime attribute then ...
        if (this_currentTime > thisAudioTag_stopTime){
          //... reset audio to data-startTime when data-stopTime is reached.
          audioTagArray[i].currentTime = audioTagArray[i].getAttribute('data-startTime');
          audioTagArray[i].pause();
        }
      }
      else if (audioTagArray[i].ended == true){
        //if there's no data-stopTime, move back to data-startTime when playback has ended.
        audioTagArray[i].currentTime = audioTagArray[i].getAttribute('data-startTime');
        audioTagArray[i].pause();
      }
    }
    
    function jAUs_3(this_currentTime,thisAudioTag_stopTime,i){
    
      if (thisAudioTag_stopTime){
        //if there's a data-stopTime attribute then ...
        if (this_currentTime > thisAudioTag_stopTime){
          //... reset audio to data-startTime when data-stopTime is reached.
          audioTagArray[i].currentTime = audioTagArray[i].getAttribute("data-startTime");
          audioTagArray[i].pause();
        }
      }
      else if (audioTagArray[i].ended == true){
        //if there's no data-stopTime, move back to data-startTime when playback has ended.
        audioTagArray[i].currentTime = audioTagArray[i].getAttribute("data-startTime");
        audioTagArray[i].pause();
      }
    }
    
    --------------

    Related Content:

    Written by nitin

    January 14th, 2012 at 11:46 am

    jAUs 3-D: no glasses required

    leave a comment

    So, I am slightly obsessive compulsive.

    I worked a little more tonight on this jAUs thing to add support for start and stop time attributes in the HTML5 <audio> tag.

    Video should work, too, with a little work, but I don't care about that right now.

    What I did tonight was make it so that if a "stopTime" attribute is used, then after that point is reached the player will move the scrubber back to the original "startTime" value though at that point the playback is already paused.

    If there is no "stopTime" attribute, then after the file's played itself to the end, the scrubber will move back to the "startTime" value. Again, playback is already paused at that point.

    I've tested this with Firefox 9.01, Internet Explorer 9, Safari 4.0.5, Opera 11.60, and Chrome 16.0.912.75 on my Windows 7 (32-bit) laptop.

    Running everything from my desktop, I had no problems except that I should mention that if I used the "autoplay" attribute and set it to "true", Chrome didn't start the playback as it should, but it seems that maybe that's a Chrome problem that others are having, too.

    Testing with the files uploaded to my hosted account was a different story. Opera seemed to need a page refresh before the scrubber would locate itself at the proper positions – though adding a pesky alert() at the beginning seemed to make Opera happy. Chrome and Safari seemed to take a few seconds to get situated, although they seemed to generally need a restart to move the scrubber to the right place for the last audio player. I didn't test the alert() thing for these two. Firefox did well although I hate the way Firefox moves the audio players around depending on whether the audio has been played or not. And that leaves IE9 … which, hands down, did the best. Maybe that's because of the exception I'd added for it as I mentioned in an earlier post.

    So, there's still work to do and things to investigate.

    Also, I haven't tested this with really long files or anything so I don't know how that would go. But then again, as I've heard others say, HTML5 media elements aren't really for long-form media anyway.

    Oh yeah, one more thing. I did in fact change to "data-startTime" and "data-stopTime" to make the HTML legal HTML5.

    Here's the HTML5 code itself, letting one see that the JavaScript has now been moved into a separate JS file.

    <!DOCTYPE html>
    <html>
      <head>
        <title>jAUs</title>
        <meta charset="UTF-8" />
      </head>
      <body>
    
      <script type="text/javascript" src="jAUs.js"></script>
    
      <p>This is the entire recording of Shakespeare's Sonnet 130, read by Nathan Miller for
      <a href="http://librivox.org/sonnet-130-by-william-shakespeare/">LibriVox</a>.</p>
      <audio controls>
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
      <p>"My mistress' eyes are nothing like the sun." - <em>start = 10; end = 13.</em></p>
      <audio class="jAUs" controls data-startTime="10" data-stopTime="13">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
      <p>"End of poem."- <em>start = 57, no end specified.</em></p>
      <audio class="jAUs" controls data-startTime="57">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
    </body>
    </html>
    

    Oh, and here's the JavaScript file:

    /*
    ***** Note: This software is still in ALPHA. Please refrain from using
    the code without first contacting Nitin Arora at nitaro74@gmail.com.
    Thanks!
    ***** 
    
    jAUs: JavaScript <audio> Shark.
    
    Copyright (c) 2012 Nitin Arora. 
    
    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:
    
    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software. 
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    
    jAUs is licensed under the MIT license:
    
    http://www.opensource.org/licenses/mit-license.php.
    
    */
    
    function jAUs(){
    
      audioTagArray = document.getElementsByClassName("jAUs");
    
      for (i=0;i<=audioTagArray.length-1;i++){
        var thisAudioTag = audioTagArray[i];
        jAUs_2(audioTagArray,thisAudioTag);
      }
    }
    
    function jAUs_2(audioTagArray,thisAudioTag){
      //if this is placed directly into jAUs() - i.e. not a separate function,
      //then this whole thing doesn't seem to work.
    
      if (navigator.appName == "Microsoft Internet Explorer"){
        thisAudioTag.onloadeddata = function(){
          var thisAudioTag_startTime = thisAudioTag.getAttribute("data-startTime");
          thisAudioTag.currentTime = thisAudioTag_startTime;
        }
      }
    
      else {
        var thisAudioTag_startTime = thisAudioTag.getAttribute("data-startTime");
        thisAudioTag.currentTime = thisAudioTag_startTime;
      }
    
      var thisAudioTag_stopTime = thisAudioTag.getAttribute("data-stopTime");
      var stopString = "jAUs_3(this.currentTime," + thisAudioTag_stopTime + "," + i + ");";
      //returns "jAUs_3(this.currentTime, 13, i);" where "i" is an int.
    
      thisAudioTag.setAttribute("ontimeupdate",stopString);
    }
    
    function jAUs_3(this_currentTime,thisAudioTag_stopTime,i){
    
      if (thisAudioTag_stopTime){
        //if there's a data-stopTime attribute then ...
        if (this_currentTime > thisAudioTag_stopTime){
          //... reset audio to data-startTime when data-stopTime is reached.
          audioTagArray[i].currentTime = audioTagArray[i].getAttribute("data-startTime");
          audioTagArray[i].pause();
        }
      }
      else if (audioTagArray[i].ended == true){
        //if there's no data-stopTime, move back to data-startTime when playback has ended.
        audioTagArray[i].currentTime = audioTagArray[i].getAttribute("data-startTime");
        audioTagArray[i].pause();
      }
    }
    
    window.onload = function(){
      jAUs();
    }
    

    Update, January 12, 2012: Turns out "jAUs" is the name for some robotic SDK and I'm not too crazy about that name anyway. So, I'm leaning toward "m(AUj)ulate" (pronounced like 'modulate') which would stand for something like "My Untimely Little Audio Tag Extender". The word "untimely" being, of course, a play on the fact that time is what this is all about. The parenthetical bit refers to "audio" (AU) and JavaScript (j).

    I might replace "My" with "Meow" in homage to one of my friend's cat. When said with a good Southern drawl, "Meow" actually isn't that different sounding than "My". By the way, the cat's name actually starts with an "M", but I don't want to have to pay the royalties.

    And, yes, I care much more about the name/acronym than the script itself.

    :P

    Update, January 15, 2012: OK, this is interesting. If, for the source of the audio file, I actually use the audio files on the Archive.org site for the LibriVox recordings like so …

      <audio class="jAUs" controls data-startTime="10" data-stopTime="13">
        <source src="http://www.archive.org/download/sonnet_130_librivox/sonnet130_shakespeare_njm_64kb.mp3" type="audio/mp3" />
        <source src="http://www.archive.org/download/sonnet_130_librivox/sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    

    … then this seems to be working OK in all the browsers. Chrome seems, per casual observation, the slowest in terms of getting the scrubber moved to the appropriate points, but I guess this is progress.

    Related to all this stuff I've been messing with, I found this: Consistent event firing with HTML5 video – Dev.Opera. But here, too, they use an alert() to notify the user that metadata is loaded using "onloadedmetadata", but in my tests it seems like the alert() function itself was what was fixing the inability of some browsers to set the current time as my script was instructing …

    --------------

    Related Content:

    Written by nitin

    January 11th, 2012 at 7:55 pm

    jAUs 2: just when you thought it was safe to go back to hating Internet Explorer

    leave a comment

    Yesterday, I posted this about trying to add "startTime" and "stopTime" attributes to the HTML5 <audio> tag using each of the major desktop browsers' native HTML5 audio player.

    If anyone read that post, it's clear I ran into some problems with Internet Explorer 9 when all the other HTML5 browsers seemed to be fine with my JavaScript.

    Well, I updated that post today to reflect a possible solution. Possible in the sense that it works, but I don't know if it's the best – or even a good – solution to the IE problem.

    It basically involved checking for IE as the user's browser and using the HTML5 media events to find the event that would make IE wait until the right time before trying to access the current time of the audio element. I also referred to this page on Microsoft's site in terms of checking for IE.

    You can read that update here: http://blog.humaneguitarist.org/2012/01/09/jaus-trying-to-add-a-starttime-attribute-to-the-audio-tag#update011012.

    Hooray for anchor tags – and shark repellent.

    --------------

    Related Content:

    Written by nitin

    January 10th, 2012 at 3:27 pm

    Posted in digital audio

    Tagged with ,

    jAUs: trying to add a startTime attribute to the audio tag

    leave a comment

    I work up this morning feeling unwell, but I still went in to work for a few minutes to enable Remote Desktop as it had stopped working (was a Windows Firewall thing) …

    Anyway, on the walk back home I started thinking about something I've wanted to play with for a while.

    And that's seeing what it would take to add support for a "startTime" attribute for the HTML5 <audio> tag using a browser's built-in player. I think it's a real oversight that there isn't native support for passing the start and stop times in the <audio> and <video> tags themselves. Um, there isn't right?

    Adding support for a "stopTime" attribute would, I think, require more than I'm willing to think about right now (I should be napping) because obviously that entails checking the current time against the point at which one would want the media to stop.

    But adding a simple (and, yes, non-standard) "startTime" attribute inside the <audio> tag seems pretty easy – if you aren't using IE. Ugh.

    As you can see in the code below there's an alert() that returns a null, but without it IE (version 9) won't set the audio players to the values in the "startTime" attributes. The other "major" browsers do fine without it. And, really, it can't be there because it's annoying as hell.

    But I think this still points to the problem of each browser having its own player. Take Safari for instance. It doesn't natively show the current or total time of the track. Chrome doesn't show the total time.

    Still think Flash is a bad thing?

    :P

    <!DOCTYPE html>
    <html>
      <head>
        <title>jAUs</title>
        <script type="text/javascript">
          function jAUs(){
            var audioTag = document.getElementsByClassName('jAUs');
            for (i=0;i<=audioTag.length;i++){
              var audioTag_startTime = audioTag[i].getAttribute('startTime');
              alert('');
              audioTag[i].currentTime = audioTag_startTime;
            }
          }
        </script>
      </head>
    <body onload="jAUs()">
    
      <audio class="jAUs" controls startTime="10">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
      <br />
    
      <audio class="jAUs" controls startTime="25">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
    </body>
    </html>
    

    ps: If this ever turns into a little project of mine, it needs a decently cool name to keep my interest. "JS" for JavaScript and "AU" for audio mashed up equals "jAUs". I hope that isn't already taken within the JavaScript/HTML5 domain.

    Update, January 09, 2012: Now that an hour has past and I finished watching "Thor & Loki: Blood Brothers", I figured out how to elegantly do the "stopTime" thing – well, at least I think it's better than what I was thinking earlier today!

    So unlike in the code above, the JavaScript below only hits on one <audio> element (the one with an "id" value of "jAUs") and not all the ones with a "class" value of "jAUs". But the point is that this new code adds the "ontimeupdate" attribute to the <audio> tag and makes it run a function called stopper() that will stop the audio once the current time is greater than the designated stopping time.

    Now, there's still work to do. For example, the code should test for the existence of the "stopTime" attribute before forcing the stopper() function to run, but that's no big deal. I also need to test doing this as above – i.e. hitting all <audio> tags with a "class" value of "jAUs" – and see how that works. And there's that pesky IE thing, too.

    Anyway, this is working in the other "major" browsers 'far as I can tell.

    <!DOCTYPE html>
    <html>
      <head>
        <title>jAUs</title>
        <script type="text/javascript">
          function jAUs(){
            var audioTag = document.getElementById('jAUs');
            var audioTag_startTime = audioTag.getAttribute('startTime'); //returns "10"
            //alert(''); //no IE love this time, sorry!
            audioTag.currentTime = audioTag_startTime;
            var audioTag_stopTime = audioTag.getAttribute('stopTime');  //returns "20"
            var stopThis = "stopper(this.currentTime," + audioTag_stopTime + ");"; //returns "stopper(this.currentTime,20);"
            audioTag.setAttribute('ontimeupdate',stopThis); //sends current time and stopTime value to stopper()
          }
          function stopper(currentTime, stopTime){
            var audioTag = document.getElementById('jAUs');
            if (currentTime > stopTime){
              audioTag.pause(); //stops playback if the current time is greater than the stopTime value
            }
          }
        </script>
      </head>
      <body onload="jAUs()">
    
      <audio id="jAUs" controls startTime="10" stopTime="20">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
    </body>
    </html>
    

    Update, January 09, 2012: I still don't like it, but it seems that the alert() line can go at the top of the jAUs() function and still allow all this to work on IE 9. At least that prevents an alert message for each <audio> tag within the page.

    Update, January 10, 2012: Ah. Now, we might be getting somewhere. I don't know if it's just a band-aid fix, but if I add an "onloadeddata" bit for IE9 this actually seems to be working just fine. The problem was that IE didn't consider the <audio> element's properties to be accessible, thus giving me an "Invalid State Error" with a code number of 11 which is this, more or less: "An attempt was made to use an object that is not, or is no longer, usable." So, IE9 is taking a little longer than the other browsers in realizing what's what.

    <!DOCTYPE html>
    <html>
      <head>
        <title>jAUs</title>
        <script type="text/javascript">
          function jAUs(){
            audioTag = document.getElementById('jAUs'); //this is a global variable
            var audioTag_startTime = audioTag.getAttribute('startTime'); //returns "10"
            //alert(audioTag.readyState); //IE returns "0", other browsers "4"
            //alert(audioTag.readyState); //IE and others return "4"
    
            //needs to be for IE9 only ... I guess it waits until the audioTag is ready to go.
            if (navigator.appName == 'Microsoft Internet Explorer')
            {
              audioTag.onloadeddata = function() {
                audioTag.currentTime = audioTag_startTime;
              }
            }
            else {
              audioTag.currentTime = audioTag_startTime;
            }
    
            var audioTag_stopTime = audioTag.getAttribute('stopTime');  //returns "13"
            var stopThis = "stopper(this.currentTime," + audioTag_stopTime + ");";
            //returns "stopper(this.currentTime, 13);"
    
            audioTag.setAttribute('ontimeupdate',stopThis);
          }
    
          function stopper(currentTime, stopTime){
            if (currentTime > stopTime){
              audioTag.pause();
            }
          }
        </script>
      </head>
      <body onload="jAUs()">
    
      <audio id="jAUs" controls startTime="10" stopTime="13">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
    </body>
    </html>
    

    Update, January 10, 2012: Hopefully (for you and me) this is the last update for a while. Hey, I'm still sick, jerk!

    Anyway, this is a test for hitting on all <audio> tags with a class value of "jAUs".

    <!DOCTYPE html>
    <html>
      <head>
        <title>jAUs</title>
        <script type="text/javascript">
          function jAUs(){
    
            audioTagArray = document.getElementsByClassName('jAUs');
    
            for (i=0;i<=audioTagArray.length-1;i++){
              var thisAudioTag = audioTagArray[i];
              jAUs_2(audioTagArray,thisAudioTag);
            }
          }
    
          function jAUs_2(audioTagArray,thisAudioTag){
          //if this is placed directly into jAUs() - i.e. not a separate function,
          //then this whole thing doesn't seem to work.
    
            if (navigator.appName == 'Microsoft Internet Explorer'){
              thisAudioTag.onloadeddata = function(){
                var thisAudioTag_startTime = thisAudioTag.getAttribute('startTime');
                thisAudioTag.currentTime = thisAudioTag_startTime;
              }
            }
    
            else {
              var thisAudioTag_startTime = thisAudioTag.getAttribute('startTime');
              thisAudioTag.currentTime = thisAudioTag_startTime;
            }
    
            var thisAudioTag_stopTime = thisAudioTag.getAttribute('stopTime');
            var stopString = "jAUs_3(this.currentTime," + thisAudioTag_stopTime + "," + i + ");";
            //returns "jAUs_3(this.currentTime, 13, i);" where "i" is an int.
    
            thisAudioTag.setAttribute('ontimeupdate',stopString);
          }
    
          function jAUs_3(this_currentTime,thisAudioTag_stopTime,i){
    
            if (this_currentTime > thisAudioTag_stopTime){
              audioTagArray[i].pause();
            }
          }
        </script>
      </head>
      <body onload="jAUs()">
    
      <audio class="jAUs" controls startTime="10" stopTime="13">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
      <br />
    
      <audio class="jAUs" controls startTime="25" stopTime="26">
        <source src="sonnet130_shakespeare_njm.mp3" type="audio/mp3" />
        <source src="sonnet130_shakespeare_njm.ogg" type="audio/ogg" />
        Your browser does not support the audio element.
      </audio>
    
    </body>
    </html>
    

    By the way, using the HTML5 "data-" prefix a la "data-startTime" would make the attribute(s) valid, though still not part of a standard per the <audio> tag specifically. But I guess the "data-" prefix is an acknowledgment of reality.

    --------------

    Related Content:

    Written by nitin

    January 9th, 2012 at 12:29 pm

    Posted in digital audio

    Tagged with , ,

    simple point and search with a maps API

    leave a comment

    I'm currently working with some folks on a pilot project to build a shared index of digital collection metadata from libraries in North Carolina. My part entails harvesting the metadata and indexing it with Solr.

    Since most of the stuff is North Carolina centric, I thought it might be neat to use the API that the index will have to drag a marker on a map and then use the marker location to send a search to the index. My co-worker also wants to do something similar so people can search using a map marker for a project of hers. So, I thought I'd investigate.

    I wanted to see how easy it was to do this with the Google Maps API and, well, it is pretty easy. Especially, since I found this marker dragging example.

    There's lot of stuff that can be done, like dynamically populating the page with a set of results via AJAX but for now I'm just using the city name plus a pre-written string to create a search string that the user has to manually click.

    In the little example I made (below), I'm using my home state of South Carolina. If you move the marker within SC and drop it, a simple search string is created for sending a search, ironically, to Bing Maps for the term "restaurants" and that city.

    I think a search like this is really for fun, but it might be a nice way to search and learn a little geography along the way. I've also got an idea for a game using this kind of search that's sort of a spin on Concentration for digital collections, but I'll write that up later. I'm hungry and need to start enjoying my Saturday. Looking at these restaurants searches is making me even hungrier.

    :/

      Written by nitin

      January 7th, 2012 at 11:29 am

      Switch to our mobile site