javascriptquicktime.docx
《javascriptquicktime.docx》由会员分享,可在线阅读,更多相关《javascriptquicktime.docx(13页珍藏版)》请在冰豆网上搜索。
javascriptquicktime
HowtoUseJavascripttoControlQuicktime(eithersoundorvideo)
byStephenWilson,Professor,ConceptualInformationArtsProgram,ArtDept,SFSU
Javascriptcontrolofsoundandvideoishighlyspecifictothebrowser,theversionofthebrowser,theplug-in, theoperatingsystem,andtheformatofthefileused Writingroutinesthatwillworkacrossallthesevariationsiscomplex. Therearedifferentcodeforembeddingfiles,differentsetsofjavascriptcommandsavailable,anddifferentjavascriptsyntaxforaddressingthefiles. ItisworththeeffortbecauseJavascriptenablesyoutocreateyourownvisualinterfacestomedia(thusnotrelyingonthestandardcontrollers)andtodynamicallycontrolfeaturesofthemediasuchasstart,stop,pause,locationtoplay,volume,etc. TheexamplebelowillustratesuseofQuicktimetocontrolsoundandmovies. Itassumesyouhavetheappropriatequicktimepluginforyourbrowserandoperatingsystem. Seeapple'ssitefordownloadingtheapproriateplug-in. Alsowiththeconstantchangeofbrowsers,theseexamplesmightnotworkwithyoursystem.
UnfortunatelyatthetimeofcompilingthisresourcetherewerenoadequateguidesortutorialsforusingJavascripttocontrolquicktime. EvenApple'ssitewassketchy. Herearesomelinksthatmightbeuseful:
∙Infoartsgeneralguideonhowtoauthorwebpagesthatincludesound
∙InfoArtsquickguidetoQuickTimeontheWeb
∙InfoartshowtoguidelistingoflinkstoappleandothertuoritalsonQuicktimeandJavascriptcontrolofJavascript
∙InfoartshowtoguidelistingoflinkstoJavascripttutorials
∙InfoartsguideonhowtousejavascripttocontrolNetscape'sLiveAudioplugin(LiveAudiowasthemainplug-inusedbyNetscape tocontrolAudiobutnowotherplug-inshavecomeintoprevalence.)
**LimitationsontheseExamples-NetscapeOnlyforNow-DocumentObjectModels(DOM)
Unfortunately,theexamplesbelowwillonlyworkreliablywithNetscapeNavigator4fornow. IdiosyncraciesintheMacintoshversionofInternetExplorerdevelopmentleftouttheabilityofJavascripttotalktoQuicktimeinExplorer4and5. FurthermoretheW3organization'sstandardsforaddressingobjectsonapagemeansthattheexamplesherewillprobablynotworkinNetscape6+andExplorer6+ Theauthorwillcontinuetoworkontheproblems.
Theproblemsareworthexploringbecausetheyillustratethecurrentcomplexities. Javascriptrequirestheabilitytoidentifytheobjectinthewebpagethatistobeactedon. ThemethodforindicatingobjectsiscalledtheDocumentObjectModelorDOM. Navigator,Explorer,andtheW3orgallusedifferentmethodsoflocatingobjectsonapage.
ThereareotherapproachespossiblewithInternetExplorer. The bgsoundmethodofembeddingsoundsalsoallowsuseofJavascript. Althoughdetailscannotbeofferedhere,pleasevisitMicrosoftDeveloperNetworkinformationonbgsoundforlistingofpossiblecommands. Also,seeDrJavascript'spagesonuseofactiveXtocontrolaudioinExplorer-EmbeddingSoundinWebPages,PartI:
AudioControlExampleCode-DocJavaScript.Theexamplesbelowshouldbeusefulbecauseuseoftheseotherjavascriptsystemswouldbesimilartowhatispresentedhere. Althoughitisbeyondthescopeofthistutorial,itmightbepossibletowriteJavascriptfunctionsthatuseddetectionofbrowser,version,andostomakeroutinesthatwouldworkinmostsituations.,
EmbeddingtheQuicktimefileinwebpages.
Differentbrowsersrequiredifferentcommandstoembedfiles. AtthetimeofwritingthispagethenewestInternetExplorerwasusingtheOBJECTtagandNavigatorwasusingtheEMBEDtag. Thecodebelowshouldworkonmostbrowserssinceitusesbothmethods. TheclassidisrequiredbyExplorertoidentifythequicktimeplugin. Thenumberisreference#setbyApplefortheactiveXidentifierforQuicktimeplug-in. Aviewermightneedtodownloadthequicktimeplug-insincemicrosoftquitincludingitautomaticallywiththeIEbrowser.
Theexampleillustratesloadingtwofiles. Oneisamidisoundfilecalled"Jesu-Joy.mid"andtheotherisaquicktimemoviefilecalled"test.mov". Yoursrcwouldneedtoincludethefullorrelativeurlleadingtowhereyourfilesarestored. (2filesareloadedherejustforthesakeofthisexample). EachfileneedsanameoridassignedbecauseJavascriptwouldneedtheesepropertiestodirectcommands. Theid/nameofthefirstoneisdeclaredtobe"jesu"andthesecondisdeclaredas"test". TheseOBJECTsequencesareplacedwithintheBODYhtmltags. ThisexampleisbasedonresourcesforanAppledeveloperWhat'sNewwebpageonQuicktime.
Theheightandwidthwouldneedtobesetappropriatelyforyourfiles. Alsonotethesettingofthepropertyenablejavascript="true". ThisisrequiredtomakeQuicktimeabletorespondtoJavascriptcommands. Alsoyouneedtotreatthesequicktimefilesasvisualelementsofyourpageandusehtml,styles,tables,etctopositionthemonthepage.Thisexampleplacesthe2filessidebysideina2columntable; otherhtmlpageelementshavebeenomittedintheexamplecode.
LoadingtwofilesbyObjectandEmbedmethod
----(otherhtmlcode)
----
02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase=" width="180"height="160" id="jesu"> src="jesu-joy.mid" name="jesu" enablejavascript="true" autostart="false">
| 02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase=" width="180"height="160" id="test"> src="test.mov" name="test" enablejavascript="true" controller="true" autostart="false"> |
----(otherhtmlcode)
----
BuildingLinksorButtonsorImagemapstoactivatetheJavascriptcommands
Hereisasampleofthe JavascriptcommandsQuicktimeunderstands:
movnameisthenameassignedwiththeobjectorembedloadedthefile.
∙movname.Play()
∙movname.Stop()
∙movname.rewind()
∙movname.SetRate(rate) 1=normalrate; 2+=quickspeed; 0=paused;-1...=backwards
∙movname.SetTime(time) For.movfilestimeisindicatedbynumberofframes-forexamplefora6framepersecondmoviesetTime(30)wouldtakeitto30thframeor5seconds.Forsoundthetimeisindicatedinmiliseconds-forexample,22000(22x1000)wouldtakeitto22thsecond. **notethissettingisdifferentthanthehour:
minute:
second:
framenotationusedintheembedtag.
∙movname.SetVolume(vol)
∙movname.SetStartTime(time)setsstarttimeforloopingusinghours:
minutes:
seconds:
framenotation
∙movname.SetEndTime(time)setsendtimeforloopingusinghours:
minutes:
seconds:
framenotation
ThesecommandscanbeuseddirectlyattachedtolinksorbuttonsorincorporatedintomorecomplexJavascriptfuntions. Thecommandneedstoreferencethemovieandtheninvokethejavascriptcommand.Themethodofidentifyingthemovieobjectcandifferindifferentbrowsers. Theexamplesbelowillustratereferringbyname"document.jesu"andreferringbythearrayJavascriptkeepsofallobjectsthathavebeenloaded.Snce"jesu"wasthefirstoneloadeditwasthe0thitemoftheembedsarray-embeds(0). Intheseexamples regularHREFhtmlisusedbuttheurlisreplacedwiththecalltojavascript. **Notethereareothercommandsavailable;seetheAppledeveloperWhat'sNewwebpageonQuicktime. Hereisalistofthejavascriptcommandslistedonthatpage.
voidPlay(
voidStop()
Step(intcount)
SetRate(floatrate)
GetRate()
SetTime(inttime)
GetTime()
SetVolume(intvolume)
GetVolume()
SetMovieName(stringmovieName)
GetMovieName()
SetMovieID(intmovieID)
GetMovieID()
SetStartTime(inttime)
GetStartTime()
SetEndTime(inttime)
GetEndTime()
SetIsLooping(booleanloop)
GetIsLooping()
SetLoopIsPalindrome(booleanloop)
GetLoopIsPalindrome()
GetMute()
SetMute(booleanmute)
SetBgColor(stringcolor)
GetBgColor()
StartingandStopping:
Herearesomelinksthatusethevariousmethodsofaddressingtocausethemoviestostopandstart.
Callinganobject(referencedbyname)methoddirectly
javascript:
document.jesu.Play()
javascript:
document.jesu.Stop()
javascript:
document.test.Play()
javascript:
document.test.Stop()
Callinganobject(indexedinthedocument"embeds"arraybyindex)methoddirectly
javascript:
document.embeds[0].Play()
javascript:
document.embeds[0].Stop()
javascript:
document.embeds[1].Play()
javascript:
document.embeds[1].Stop()
Callinganobject(indexedinthedocument"embeds"arraybyname)methoddirectly
javascript:
document.embeds['jesu].Play()
javascript:
document.embeds['jesu'].Stop()
javascript:
document.embeds['test'].Play()
javascript:
document.embeds['test'].Stop()
Hereisasampleofthecompletehtmlcode
document.jesu.Play();">javascript:
document.jesu.Play()
TheW3orgnewDOMstandardsusethe"getElementByID"toidentifyobjects. Thisstandardhasbeenpartiallyadoptedby