From 753f60c7d4769fa72d3b910e491f37db6f130898 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:19:21 -0500 Subject: dymaxion --- .../demo/mp3-player-button/basic.html | 48 ++++ .../mp3-player-button/css/mp3-player-button.css | 114 ++++++++++ .../mp3-player-button/image/arrow-right-black.gif | Bin 0 -> 67 bytes .../mp3-player-button/image/arrow-right-black.png | Bin 0 -> 167 bytes .../mp3-player-button/image/arrow-right-white.gif | Bin 0 -> 67 bytes .../mp3-player-button/image/arrow-right-white.png | Bin 0 -> 167 bytes .../demo/mp3-player-button/index.html | 188 ++++++++++++++++ .../mp3-player-button/script/mp3-player-button.js | 247 +++++++++++++++++++++ 8 files changed, 597 insertions(+) create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/basic.html create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/css/mp3-player-button.css create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.gif create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.png create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.gif create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.png create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/index.html create mode 100755 docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/script/mp3-player-button.js (limited to 'docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button') diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/basic.html b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/basic.html new file mode 100755 index 0000000..9a4b151 --- /dev/null +++ b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/basic.html @@ -0,0 +1,48 @@ + + + +SoundManager 2 Demo: Basic MP3 Play Button (Simple Demo) + + + + + + + + +

SoundManager 2 / Basic MP3 Play Button: Template

+ +

View the source code of this page for detail. Don't forget to set soundManager.debugMode = false; to disable debug output.

+ +

Walking Walking

+ +

Armstrong Beat Armstrong Beat

+ +

SoundManager 2 project home

+ + + + + diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/css/mp3-player-button.css b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/css/mp3-player-button.css new file mode 100755 index 0000000..e5e1ce6 --- /dev/null +++ b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/css/mp3-player-button.css @@ -0,0 +1,114 @@ +/* + + SoundManager 2: Basic MP3 player CSS + ------------------------------------ + + Clicks on links to MP3s are intercepted via JS, calls are + made to SoundManager to load/play sounds. CSS classes are + appended to the link, which are used to highlight the + current play state and so on. + + Class names are applied in addition to "sm2_button" base. + + Default: + + sm2_button + + Additional states: + + sm2_playing + sm2_paused + + eg. + + + some.mp3 + + + some.mp3 + + + Note you don't require ul.graphic / ul.flat etc. for your use + if only using one style on a page. You can just use .sm2_button{} + and so on, but isolate the CSS you want. + + Side note: Would do multiple class definitions eg. + + a.sm2_default.sm2_playing{} + + .. except IE 6 has a parsing bug which may break behaviour, + applying sm2_playing {} even when the class is set to sm2_default. + + + If you want to make your own UI from scratch, here is the base: + + Default + hover state, "click to play": + + a.sm2_button {} + a.sm2_button:hover {} + + Playing + hover state, "click to pause": + + a.sm2_playing {} + a.sm2_playing:hover {} + + Paused + hover state, "click to resume": + + a.sm2_paused {} + a.sm2_paused:hover {} + +*/ + +a.sm2_button { + position:relative; + display:inline-block; /* If you worry about old browser bugs, Firefox 2 might not like this and may need -moz-inline-box instead. :D */ + width:18px; + height:18px; + text-indent:-9999px; /* don't show link text */ + overflow:hidden; /* don't draw inner link text */ + vertical-align:middle; + /* and, a bit of round-ness for the cool browsers. */ + -moz-border-radius:6px; + -webkit-border-radius:6px; + -o-border-radius:6px; + border-radius:6px; + margin-top:-1px; /* vertical align tweak */ + /* safari 3.1+ fun (/W3 working draft extension, TBD.) */ + -webkit-transition-property: hover; + -webkit-transition: all 0.2s ease-in-out; + -moz-transition: all 0.2s ease-in-out 0s; /* firefox 4 (couldn't sort out -moz-transform vs. MozTransform, so, "all" for now) */ + -o-transition-property: background-color; /* opera 10.5 */ + -o-transition-duration: 0.15s; +} + +a.sm2_button:focus { + outline:none; /* maybe evil, but don't show the slight border outline on focus. */ +} + +a.sm2_button, +a.sm2_button.sm2_paused:hover { + background-color:#3399cc; + background-image:url(../image/arrow-right-white.png); + /* where possible, use data: and skip the HTTP request. Fancy-pants. Would use short-hand background: for above, but IE 8 doesn't override background-image. */ + background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAKCAYAAABmBXS+AAAAbklEQVQY02NgQAL//v1jZMAF/v//vwuIs9HEUBUBTbj4HwIeA3EGVsVAxtn/qOAVUGM8uknIiv4hsV8A5ZKxKfoLVvnvHwifAzLtMKwDSQLBVSBti27dJajkcSD2RJODO3wtkOOMz/tMSJJYAxMA5dmsL0IfubQAAAAASUVORK5CYII=); + *background-image:url(../image/arrow-right-white.gif); /* IE 6+7 don't do DATA: URIs */ + background-repeat:no-repeat; + background-position:5px 50%; +} + +a.sm2_button:hover, +a.sm2_button.sm2_playing, +a.sm2_button.sm2_playing:hover { + background-color:#cc3333; +} + +a.sm2_button.sm2_playing, +a.sm2_button.sm2_playing:hover { + -moz-transform:rotate(90deg); + -webkit-transform:rotate(90deg); +} + +a.sm2_button.sm2_paused, +a.sm2_button.sm2_paused:hover { + background-color:#666; +} \ No newline at end of file diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.gif b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.gif new file mode 100755 index 0000000..3b4900e Binary files /dev/null and b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.gif differ diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.png b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.png new file mode 100755 index 0000000..fc55124 Binary files /dev/null and b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-black.png differ diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.gif b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.gif new file mode 100755 index 0000000..9e760e1 Binary files /dev/null and b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.gif differ diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.png b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.png new file mode 100755 index 0000000..4189094 Binary files /dev/null and b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/image/arrow-right-white.png differ diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/index.html b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/index.html new file mode 100755 index 0000000..6cc1ff5 --- /dev/null +++ b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/index.html @@ -0,0 +1,188 @@ + + + +SoundManager 2 Demo: Basic MP3 Play Button + + + + + + + + + + + +
+ +

SoundManager 2 / Inline MP3 Player Button

+ +

Basic MP3 Play Button Examples

(also see basic demo.) + +
+ +
+ +
+ +

Inline text, with "play" button

+ +

Example code (link with a sm2_button CSS class):

+
<p> Spare change <a href="/path/to/coins.mp3" title="Play &quot;coins&quot;" class="sm2_button">coins.mp3</a> </p>
+

Renders as:

+
+

Spare change coins.mp3

+

Note that the text inside the link is hidden and replaced with an image, but should be descriptive - or at least should say something generic, like "play".

+
+

Basic MP3 play button, no text

+ +

Code:

+ +
<a href="../jsAMP-preview/audio/office_lobby.mp3" title="Play &quot;Office Lobby&quot;" class="sm2_button">Office Lobby</a>
+ +

Renders as:

+

+ Office Lobby +

+

How It Works

+ +

SoundManager 2 intercepts clicks to MP3 links and plays them inline. The script assigns additional CSS classes to the links to indicate their state (playing/paused, etc.)

+ +

Static Examples

+ +

CSS classes are dynamically applied as follows:

+ + + +

Basic CSS

+ +

If you want to make your own UI from scratch, here is the base:

+ +
+ Default + hover state, "click to play":
+
+ a.sm2_button {}
+ a.sm2_button:hover {}
+
+ Playing + hover state, "click to pause":
+
+ a.sm2_button.sm2_playing {}
+ a.sm2_button.sm2_playing:hover {}
+
+ Paused + hover state, "click to resume":
+
+ a.sm2_button.sm2_paused {}
+ a.sm2_button.sm2_paused:hover {}
+
+ +

Other Options

+ +

By default, one sound will be played at a time; you can easily change a "config" object value to turn on playlist-like behaviour (i.e., play the next MP3 when the current one finishes.)

+ +
+
+// (within mp3-player-button.js)
+this.config = {
+ playNext: false // stop after one sound, or play through list until end
+}
+
+ +

I'd like to use this.

+

See this basic demo for reference.

+ +

+ SoundManager 2 project page (not an MP3 link) +

+ +
+ + + diff --git a/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/script/mp3-player-button.js b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/script/mp3-player-button.js new file mode 100755 index 0000000..96e0346 --- /dev/null +++ b/docs/dymaxion/soundmanagerv297a-20101010/demo/mp3-player-button/script/mp3-player-button.js @@ -0,0 +1,247 @@ +/* + + SoundManager 2 Demo: Play MP3 links via button + ---------------------------------------------- + + http://schillmania.com/projects/soundmanager2/ + + A simple demo making MP3s playable "inline" + and easily styled/customizable via CSS. + + A variation of the "play mp3 links" demo. + + Requires SoundManager 2 Javascript API. + +*/ + +function BasicMP3Player() { + var self = this; + var pl = this; + var sm = soundManager; // soundManager instance + this.excludeClass = 'button-exclude'; // CSS class for ignoring MP3 links + this.links = []; + this.sounds = []; + this.soundsByURL = []; + this.indexByURL = []; + this.lastSound = null; + this.soundCount = 0; + var isIE = (navigator.userAgent.match(/msie/i)); + + this.config = { + playNext: false, // stop after one sound, or play through list until end + autoPlay: false // start playing the first sound right away + } + + this.css = { + // CSS class names appended to link during various states + sDefault: 'sm2_button', // default state + sLoading: 'sm2_loading', + sPlaying: 'sm2_playing', + sPaused: 'sm2_paused' + } + + this.includeClass = this.css.sDefault; + + + this.addEventHandler = function(o,evtName,evtHandler) { + typeof(attachEvent)=='undefined'?o.addEventListener(evtName,evtHandler,false):o.attachEvent('on'+evtName,evtHandler); + } + + this.removeEventHandler = function(o,evtName,evtHandler) { + typeof(attachEvent)=='undefined'?o.removeEventListener(evtName,evtHandler,false):o.detachEvent('on'+evtName,evtHandler); + } + + this.classContains = function(o,cStr) { + return (typeof(o.className)!='undefined'?o.className.match(new RegExp('(\\s|^)'+cStr+'(\\s|$)')):false); + } + + this.addClass = function(o,cStr) { + if (!o || !cStr || self.classContains(o,cStr)) return false; + o.className = (o.className?o.className+' ':'')+cStr; + } + + this.removeClass = function(o,cStr) { + if (!o || !cStr || !self.classContains(o,cStr)) return false; + o.className = o.className.replace(new RegExp('( '+cStr+')|('+cStr+')','g'),''); + } + + this.getSoundByURL = function(sURL) { + return (typeof self.soundsByURL[sURL] != 'undefined'?self.soundsByURL[sURL]:null); + } + + this.isChildOfNode = function(o,sNodeName) { + if (!o || !o.parentNode) { + return false; + } + sNodeName = sNodeName.toLowerCase(); + do { + o = o.parentNode; + } while (o && o.parentNode && o.nodeName.toLowerCase() != sNodeName); + return (o.nodeName.toLowerCase() == sNodeName?o:null); + } + + this.events = { + + // handlers for sound events as they're started/stopped/played + + play: function() { + pl.removeClass(this._data.oLink,this._data.className); + this._data.className = pl.css.sPlaying; + pl.addClass(this._data.oLink,this._data.className); + }, + + stop: function() { + pl.removeClass(this._data.oLink,this._data.className); + this._data.className = ''; + }, + + pause: function() { + pl.removeClass(this._data.oLink,this._data.className); + this._data.className = pl.css.sPaused; + pl.addClass(this._data.oLink,this._data.className); + }, + + resume: function() { + pl.removeClass(this._data.oLink,this._data.className); + this._data.className = pl.css.sPlaying; + pl.addClass(this._data.oLink,this._data.className); + }, + + finish: function() { + pl.removeClass(this._data.oLink,this._data.className); + this._data.className = ''; + if (pl.config.playNext) { + var nextLink = (pl.indexByURL[this._data.oLink.href]+1); + if (nextLink1) { + // ignore right-click + return true; + } + var o = self.getTheDamnLink(e); + if (o.nodeName.toLowerCase() != 'a') { + o = self.isChildOfNode(o,'a'); + if (!o) return true; + } + var sURL = o.getAttribute('href'); + if (!o.href || !soundManager.canPlayLink(o) || self.classContains(o,self.excludeClass)) { + return true; // pass-thru for non-MP3/non-links + } + if (!self.classContains(o,self.includeClass)) { + return true; + } + sm._writeDebug('handleClick()'); + var soundURL = (o.href); + var thisSound = self.getSoundByURL(soundURL); + if (thisSound) { + // already exists + if (thisSound == self.lastSound) { + // and was playing (or paused) + thisSound.togglePause(); + } else { + // different sound + thisSound.togglePause(); // start playing current + sm._writeDebug('sound different than last sound: '+self.lastSound.sID); + if (self.lastSound) self.stopSound(self.lastSound); + } + } else { + // create sound + thisSound = sm.createSound({ + id:'basicMP3Sound'+(self.soundCount++), + url:soundURL, + onplay:self.events.play, + onstop:self.events.stop, + onpause:self.events.pause, + onresume:self.events.resume, + onfinish:self.events.finish + }); + // tack on some custom data + thisSound._data = { + oLink: o, // DOM node for reference within SM2 object event handlers + className: self.css.sPlaying + }; + self.soundsByURL[soundURL] = thisSound; + self.sounds.push(thisSound); + if (self.lastSound) { + // stop last sound + self.stopSound(self.lastSound); + } + thisSound.play(); + } + + self.lastSound = thisSound; // reference for next call + + if (typeof e != 'undefined' && typeof e.preventDefault != 'undefined') { + e.preventDefault(); + } else { + event.returnValue = false; + } + return false; + } + + this.stopSound = function(oSound) { + soundManager.stop(oSound.sID); + soundManager.unload(oSound.sID); + } + + this.init = function() { + sm._writeDebug('basicMP3Player.init()'); + var oLinks = document.getElementsByTagName('a'); + // grab all links, look for .mp3 + var foundItems = 0; + for (var i=0, j=oLinks.length; i0) { + self.addEventHandler(document,'click',self.handleClick); + if (self.config.autoPlay) { + self.handleClick({target:self.links[0],preventDefault:function(){}}); + } + } + sm._writeDebug('basicMP3Player.init(): Found '+foundItems+' relevant items.'); + } + + this.init(); + +} + +var basicMP3Player = null; + +soundManager.useFlashBlock = true; +soundManager.url = '../../swf/'; // path to directory containing SM2 SWF + +soundManager.onready(function() { + if (soundManager.supported()) { + // soundManager.createSound() etc. may now be called + basicMP3Player = new BasicMP3Player(); + } +}); \ No newline at end of file -- cgit v1.2.3-70-g09d2