In an effort to keep the encoding of the time alignment as simple as possible, the alignment information is embedded into regular html via a specialized attribute. This is based upon the HyperAudio concept developed by Mark Boas over at HappyWorm .
Example
<h2 data-time_start="0">Counting</h2>
<span data-time_start="1000">One</span>
<span data-time_start="2000">Two</span>
<span data-time_start="3000" data-time_end="4000">Three</span>
<br />
<span>This text won't be highlighted</span>
<div data-time_start="4000" data-time_end="5500">We Just Counted to 3!</div>
<h2 data-time_start="0">Counting</h2>
<span data-time_start="1000">One</span>
<span data-time_start="2000">Two</span>
<span data-time_start="3000">Three</span>
Bad:
<h2 data-time_start="0">Counting</h2>
<span data-time_start="3500">One</span>
//time starts before previous start time: Bad
<span data-time_start="2000" data-time_end="2500">Two</span>
//time starts before previous end time: Bad
<span data-time_start="2400">Three</span> --time starts before previous end time
<!-- Include necessary css and javascript --> <link type="text/css" href="css/skin/jplayer.blue.monday.css" rel="stylesheet" /> <link type="text/css" href="css/mediaAlignedText.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.jplayer.min.js"></script> <script type="text/javascript" src="js/jquery.scrollTo-min.js"></script> <script type="text/javascript" src="js/jquery.mediaAlignedText.js"></script>
<!-- Setup Player Media Files-->
<script type="text/javascript">
var media_files = [{
"title":"The Hobbit - Chapter 1a",
"media_type":"AUDIO",
"media": {
mp3: "media_files/hobbit-1a.mp3",
wav: "media_files/hobbit-1a.wav"
}
}];
<!-- Initialize the Player-->
$(document).ready(function(){
$('#jquery_jplayer_1').mediaAlignedText({
'media_files': media_files
});
});
</script>
<div id="jquery_jplayer_1"></div> <!-- Base element for player functionality -->
<div id="mat_jplayer_controls"></div> <!-- Container for jPlayer Controls -->
<div id="mat_text_viewer"> <!-- Container for the Hyperaudio Tagged Text -->
<h3>The Hobbit - J.R.R Tokien</h3>
<span data-time_start="0">In</span>
<span data-time_start="1160">a</span>
<span data-time_start="1460">hole</span>
...
<span data-time_start="41220">fond</span>
<span data-time_start="41470">of</span>
<span data-time_start="41660">visitors</span>.
</div>
<link type="text/css" href="css/skin/jplayer.blue.monday.css" rel="stylesheet" />
<link type="text/css" href="css/mediaAlignedText.css" rel="stylesheet" />
<link type="text/css" href="css/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo-min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.mediaAlignedText.js"></script>
<script type="text/javascript" src="js/jquery.mediaAlignedTextEditor.js"></script>
$('#jquery_jplayer_1').mediaAlignedTextEditor({
'url': media_url, //the url of the media file
'file_type': file_type, //the file_type of the media file e.g. mp3 or wav
'text_init_type': text_init_type, //length of text segments [WORD, LINE, SENTENCE, STANZA, TAGGED]
'text': text //the plain (or HyperAudio Tagged )text to be aligned
});
<div id="mat_init">
<div>
<label for="mat_media_url">Media URL</label>
<input type="text" id="mat_media_url" value =""/>
</div>
<div>
<label for="mat_media_file_type">Media File Type</label>
<select id="mat_media_file_type">
<option value="mp3">mp3</option>
<option value="wav">wav</option>
</select>
</div>
<div>
<label for="mat_init_type">Text Initialization Type</label>
<select id="mat_init_type">
<option value="WORD">Plain Text - Create Word Segments</option>
<option value="LINE">Plain Text - Create Line Segments</option>
<option value="SENTENCE">Plain Text - Create Sentence Segments</option>
<option value="STANZA">Plain Text - Create Stanza Segments</option>
<option value="TAGGED">Text Already Segmented and Tagged</option>
</select>
</div>
<div>
<label for="mat_text_input">Text</label><br />
<textarea id="mat_text_input" rows="5" cols="50">[INPUT TEXT HERE]</div>
<button onclick="
$('#mat_init_alignment').hide('200');
$('#mat_editor').show('200')
$('#jquery_jplayer_1').mediaAlignedTextEditor({
'url': $('#mat_media_url').val(),
'file_type': $('#mat_media_file_type').val(),
'text_init_type': $('#mat_init_type').val(),
'text': $('#mat_text_input').val()});;">Intialize Alignment</button>
</div>
<div id="jquery_jplayer_1"></div>
<div id="mat_jplayer_controls"></div>
<div id="mat_editor"></div>
$('#jquery_jplayer_1').mediaAlignedText({
'jplayer_controls_id' : 'mat_jplayer_controls',//id of the div where jplayer controls reside
'media_files' : {}, //array of media files and types to initiate
'text_viewer_css_selector' : '#mat_text_viewer', //id of the div where the text is displayed
'jplayer_options' : {}, //additional jplayer options to initiate
'jplayer_control_options' : {}, //options to send to the jplayer control generator
'jplayer_controls_generate' : true, //flag indicating if controls should be generated or not
'highlight_function' : _textSegmentHighlight, //the function to use to highlight - requires object and text_segment_id as arguments
'highlight_remove_function' : _textSegmentHighlightRemove, //function to remove highligh - requires object and text_segment_id as arguments
'time_start_attribute' : 'data-time_start', //attribute to designate start time encoding
'time_end_attribute' : 'data-time_end', //attribute to designate end time encoding
'check_time_disabled' : false //flag to indicate if you want to turn off checking time to change highlighting as recording plays
});
function($this, text_segment_index) {
//add the 'mat_highlighted_text_segment' class to the specified text segment
$('[data-mat_segment='+text_segment_index+']').addClass('mat_highlighted_text_segment');
//scroll the text viewer to the highlighted segment
$($this.data('mediaAlignedText').text_viewer_css_selector).scrollTo(
'.mat_highlighted_text_segment', 250, {'axis': 'y', 'offset': -20}
);
};
function($this, text_segment_index){
$('[data-mat_segment='+text_segment_index+']').removeClass('mat_highlighted_text_segment');
};
{
'jp_container_id' : 'jp_container_1', //the id for the container of the controls
'title' : '', //defaults to the title of the media file
'media_type' : 'audio' //the media type for the container - only audio currently
}
media_files = [{
"title":"The Hobbit - Chapter 1a",
"media_type":"AUDIO",
"media": {
mp3: "media_files/hobbit-1a.mp3",
wav: "media_files/hobbit-1a.wav"
}
}];
$('#jquery_jplayer_1').mediaAlignedTextEditor({
'media_file_type' : 'mp3', //type of media file
'text_init_type' : 'WORD', //what to break on (can be WORD, LINE, SENTENCE, STANZA, TAGGED(already tagged)
'eclosing_tag' : 'span', // the tag to enclose the text segments in
'url' : '', //url of the media file
'text' : '', //the text to align
'editor_css_selector' : '#mat_editor', //css selector for editor
'generate_editor_html' : true, //flag indicating if editor html should be generated or not
'viewable_media_segments' : 5, //average number of segments viewable on the viewer
'color_toggle_classes' : ['mat_toggle_bg_color_0', 'mat_toggle_bg_color_1', 'mat_toggle_bg_color_2', 'mat_toggle_bg_color_3'], //array of classes to toggle through
'media_aligned_text_options': {} //options to pass to the mediaAlignedText init function
});