blog.humaneguitarist.org

discoveries in digital audio, music notation, and information encoding

Archive for the ‘JavaScript’ tag

on adding a JavaScript API to our Flash player at work

leave a comment

Sometimes being home sick means finding things to work on that I wouldn't have done had I been in the office, but need to be done eventually.

So, today I worked on augmenting a JavaScript API for our Flash player at work. Before I go any further, here's a screenshot below. Note that the JavaScript console for Googles' Chrome browser is visible at the bottom.

NC Live Media Player

As you can see, the "movie" is not just the "movie", so to speak. That's to say, there's a very cool bookmarking feature that, if clicked, returns a URL that if visited will start the given video at the point in time at which the user clicked the bookmark. The "movie" also includes some whitespace on the left hand side where links to "part 2"s of certain videos appear if they exist. That's great, but it totally makes our Flash player inappropriate for providing embed codes, etc. since the "movie" is more than the actual video screen and the controls (play, pause, captions, etc.). And, yes, we have to use our own player given that we have to deal with all kinds of authentication and rights issues, which this player support via calls to PHP scripts.

Anyway, a few months ago I'd created a basic JavaScript API so that I could make a demo using our player for SAVS, which is completely reliant on two things: being able to receive the current time of the player and also being able to send a new current time to the player.

Today, I expanded the API a little bit though in the image above you can see a call to the function that moves, in the case above, the player to the 10 second mark. I added support for changing the volume, pausing the video, playing the video if it's paused, turning captions on/off, and getting the total duration of the media file, etc. Basically, I'm trying to add support for anything we'd need to replace the bookmark button and other features with HTML buttons, etc.

There's still lots of work to do, but it's working well provided I embed the SWF file with the <object> tag:

<object
  id="thisMovie"
  data="video2_js.swf"
  style="height: 500px; width: 500px;"
  type="application/x-shockwave-flash">
  <param name="movie" value="video2_js.swf" />
</object>

Then I can use these JavaScript functions on the page that embeds the player …

<script type="text/javascript">
//see: http://kirill-poletaev.blogspot.com/2011/02/exchange-data-between-actionscript-3.html
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

// ... more functions were here, but there's too much for a blog post. :-]

function ncl_getCurrentTime() {
  var callResult = getFlashMovie("thisMovie").getCurrentTime("");
  return callResult;
}

function ncl_getTotalTime() {
  var callResult = getFlashMovie("thisMovie").getTotalTime("");
  return callResult;
}
</script>

… provided I make sure the ActionScript in the Flash player is prepared for those callbacks …

//see: http://kirill-poletaev.blogspot.com/2011/02/exchange-data-between-actionscript-3.html


//send current time value to JavaScript function
function sendCurrentTimeToJS(name:Number):Number
{
    var now:int = cfp.playheadTime;
    return now;
}
ExternalInterface.addCallback("getCurrentTime", sendCurrentTimeToJS);

//send total time value to JavaScript function
function sendTotalTimeToJS(name:Number):Number
{
    var total:int = cfp.totalTime;
    return total;
}
ExternalInterface.addCallback("getTotalTime", sendTotalTimeToJS);
--------------

Related Content:

Written by nitin

February 23rd, 2012 at 6:14 pm

Posted in scripts

Tagged with , , ,

NCDevCon 2011

one comment

I attended NCDevCon a few weeks ago and just wanted to post my notes and provide relevant links for later use/study.

I'm only going to jot down the major takeaways I had from the sessions I attended (listed in alphabetical order). Undoubtedly, the link to the session information might be irrelevant when the 2012 event nears. But videos of each can be seen for free (I think) at NC State's College of Textiles' page here.

AngluarJS – What HTML Would Have Been If It Had Been Designed For Building Web Applications (Tim Cunningham)

The AngularJS session was a great and the speaker also makes great (and strong!) beer than he shared with attendees after the sessions.

There's not too much to say here except this is something for me to keep an eye on.

Notes:

  • Client-side scripting is like the "Wild Wild West".
  • AngularJS is MVC: JSON is the model, HTML the view.
  • Built for testing.
  • jQuery is good for DOM manipulation; AngularJS increases the level of abstraction.
  • Not yet at 1.0, so maybe don't rely on it just yet.
  • Look up "dependency injection".

HTML5 vs Flash Video: Choose Wisely (Ben Farrell)

This was a basic intro to HTML5/Flash video. I think it's too soon for people to get on either side of the fence, not to mention there's too much money to be lost if Adobe doesn't figure out how to play well with certain devices (i.e. Apple). And it looks like they are doing just that.

Notes:

  • Use Modernizr to test for codec support.
  • Apple's HTTP Live Streaming is a "bait and switch" as the Quicktime plug-in is required.

Introduction to jQuery Mobile (Ray Camden)

This was really helpful to me since I wouldn't mind doing something mobile compatible but I hesitate to write mobile apps and have to compile them for particular devices even with a cross-compiler like PhoneGap.

I'll definitely have a look-see at jQuery Mobile as it has a lot of out-of-box features that can ease the task of writing effective, easy-to-navigate pages.

Notes:

  • Takes advantage of HTML5's "data" attribute from <div> tags.
    • Lists: <data-role="listview">
    • Filtering support: <data-filter="true">
      • The filter only works on the data on the current page, not the entire set of data.
  • Check out: Search, Slider, Collapsable Blocks, swipeable events, etc.

Geolocation 101 (Andrew Powell)

This tied in well with the jQuery Mobile class. We talked about the HTML5 Geolocation API, the history of geolocation technology and presidential executive orders, and its role in "Tomorrow Never Dies".

Notes:

  • You must always ask for user permission; some browsers make sure the user agrees.
  • Don't write geolocation intensive apps; they drain batteries.
  • Cell phone tower location is the least accurate but fastest, followed by Wi-Fi, then GPS (slowest, most accurate).
  • Not all devices/OS' support altitude reporting.
  • Look up "GeoFencing".

Tame Your CSS3 With Sass (Les James)

This was a really helpful class as I'd never heard of Sass, which the presenter described as a "CSS metalanguage". There really aren't any notes that need writing, I simply need to use it.

BTW: there was one fellow there who worked for the government and had a CSS file over 2k lines long that he inherited from his predecessor. He will definitely be using Sass in the future!

QR Code Crazy (Shawn Dunning)

This was a great overview of the history and uses of Quick Response, or QR codes. In addition to seeing some examples, we talked about how the smartphone/QR code bit presents accessibility issues (more Digital Divide, if you believe in that). And a week or so later, I also heard this on NPR which asked if by the time QR codes could become more widely adopted they might already be obsolete.

Notes:

  • Uses position boxes and, per the standard, white/black should be switchable.
    • I wondered about putting QR codes on archival scans to verify the image's orientation and color balance, i.e with some metadata embedded in the code itself.
  • Smartphones use regular expressions to determine that a URL string exists and subsequently points a browser to the site. The code itself is simply a string.

What Is NodeJS And Why You Should Care (Garrett Johnson)

A little over my head, but that's why I went right?

:P

Notes:

  • Research node.js; possibly use to serve up a website.

Writing JavaScript That Doesn't Suck (Bucky Schwarz)

If you watch only one video online, watch this one. Useful and highly, highly entertaining.

Notes:

  • Consider using strict equality in JavaScript (===).
  • jQuery "leads to one-off scripting … ".
  • Selector speed (fastest to slowest): id, element, class.
    • Don't search for a single class unless you have to.
  • Don't declare new variables inside a loop (doh! I do this all the time).
  • Look up "dirty bit".

This was the last session I attended and afterward I talked to the speaker. He recommended "JavaScript: The Good Parts" as a quick, no-nonsense read to help improve my JavaScript.

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

Related Content:

Written by nitin

October 9th, 2011 at 12:00 pm

syntax highlighting with WordPress: that's not that!

leave a comment

A few months ago I posted on how I used the Syntax Highlighter Evolved plugin for WordPress to make code snippets more readable.

Anyway, at the time I was really excited to be able to put some nice looking code/markup into my posts. Never mind that the code itself wasn't so nice!

:P

Over time, of course, I've wanted to make things easier. As I mentioned in the earlier post I was pasting in my code using Deans' FCKEditor, using the Styles drop-down to mark up my code as <code> and then in turn editing the source HTML to change the <code> tag to a <pre> tag with the appropriate attribute to denote that my code was either Python or XML, etc.

Well, as I remarked to a friend of mine today over lunch, I'm sick of doing that.

So I dug around in all the files that are part of Dean's FCKEditor. I learned that by editing the "ckeditor/plugins/stylescombo/styles/default.js" file that I could add options to the Styles drop-down menu. Now, when I paste in Python, XML, or Javascript I just need to highlight the code and pick the right option from the Styles list. It's SO much easier.

Here's an image of the Styles list with the added options mentioned:

If you are curious to see the .js file with the minor additions, I've pasted it below – and even highlighted it using the new Code: Javascript option.

/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.addStylesSet('default',[{name:'Blue Title',element:'h3',styles:{color:'Blue'}},
{name:'Red Title',element:'h3',styles:{color:'Red'}},
{name:'Marker: Yellow',element:'span',styles:{'background-color':'Yellow'}},
{name:'Marker: Green',element:'span',styles:{'background-color':'Lime'}},
{name:'Big',element:'big'},
{name:'Small',element:'small'},
{name:'Typewriter',element:'tt'},
{name:'Computer Code',element:'code'},
{name:'Keyboard Phrase',element:'kbd'},
{name:'Sample Text',element:'samp'},
{name:'Variable',element:'var'},
{name:'Deleted Text',element:'del'},
{name:'Inserted Text',element:'ins'},
{name:'Cited Work',element:'cite'},
{name:'Inline Quotation',element:'q'},
{name:'Language: RTL',element:'span',attributes:{dir:'rtl'}},
{name:'Language: LTR',element:'span',attributes:{dir:'ltr'}},
{name:'Image on Left',element:'img',attributes:{style:'padding: 5px; margin-right: 5px',border:'2',align:'left'}},
{name:'Image on Right',element:'img',attributes:{style:'padding: 5px; margin-left: 5px',border:'2',align:'right'}},
/* start of added options */
{name:'Code: Python',element:'pre',attributes:{class:'brush:python'}},
{name:'Code: XML',element:'pre',attributes:{class:'brush:xml'}},
{name:'Code: Javascript',element:'pre',attributes:{class:'brush:javascript'}}
/* end of added options */
]);
--------------

Related Content:

Written by nitin

March 13th, 2011 at 10:48 pm

Switch to our mobile site