1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655 |
- /*!
- *
- * MediaElement.js
- * HTML5 <video> and <audio> shim and player
- * http://mediaelementjs.com/
- *
- * Creates a JavaScript object that mimics HTML5 MediaElement API
- * for browsers that don't understand HTML5 or can't play the provided codec
- * Can play MP4 (H.264), Ogg, WebM, FLV, WMV, WMA, ACC, and MP3
- *
- * Copyright 2010-2014, John Dyer (http://j.hn)
- * License: MIT
- *
- */
- // Namespace
- var mejs = mejs || {};
- // version number
- mejs.version = '2.23.5';
- // player number (for missing, same id attr)
- mejs.meIndex = 0;
- // media types accepted by plugins
- mejs.plugins = {
- silverlight: [
- {version: [3,0], types: ['video/mp4','video/m4v','video/mov','video/wmv','audio/wma','audio/m4a','audio/mp3','audio/wav','audio/mpeg']}
- ],
- flash: [
- {version: [9,0,124], types: ['video/mp4','video/m4v','video/mov','video/flv','video/rtmp','video/x-flv','audio/flv','audio/x-flv','audio/mp3','audio/m4a', 'audio/mp4', 'audio/mpeg', 'video/dailymotion', 'video/x-dailymotion', 'application/x-mpegURL', 'audio/ogg']}
- // 'video/youtube', 'video/x-youtube',
- // ,{version: [12,0], types: ['video/webm']} // for future reference (hopefully!)
- ],
- youtube: [
- {version: null, types: ['video/youtube', 'video/x-youtube', 'audio/youtube', 'audio/x-youtube']}
- ],
- vimeo: [
- {version: null, types: ['video/vimeo', 'video/x-vimeo']}
- ]
- };
- /*
- Utility methods
- */
- mejs.Utility = {
- encodeUrl: function(url) {
- return encodeURIComponent(url); //.replace(/\?/gi,'%3F').replace(/=/gi,'%3D').replace(/&/gi,'%26');
- },
- escapeHTML: function(s) {
- return s.toString().split('&').join('&').split('<').join('<').split('"').join('"');
- },
- absolutizeUrl: function(url) {
- var el = document.createElement('div');
- el.innerHTML = '<a href="' + this.escapeHTML(url) + '">x</a>';
- return el.firstChild.href;
- },
- getScriptPath: function(scriptNames) {
- var
- i = 0,
- j,
- codePath = '',
- testname = '',
- slashPos,
- filenamePos,
- scriptUrl,
- scriptPath,
- scriptFilename,
- scripts = document.getElementsByTagName('script'),
- il = scripts.length,
- jl = scriptNames.length;
-
- // go through all <script> tags
- for (; i < il; i++) {
- scriptUrl = scripts[i].src;
- slashPos = scriptUrl.lastIndexOf('/');
- if (slashPos > -1) {
- scriptFilename = scriptUrl.substring(slashPos + 1);
- scriptPath = scriptUrl.substring(0, slashPos + 1);
- } else {
- scriptFilename = scriptUrl;
- scriptPath = '';
- }
-
- // see if any <script> tags have a file name that matches the
- for (j = 0; j < jl; j++) {
- testname = scriptNames[j];
- filenamePos = scriptFilename.indexOf(testname);
- if (filenamePos > -1) {
- codePath = scriptPath;
- break;
- }
- }
-
- // if we found a path, then break and return it
- if (codePath !== '') {
- break;
- }
- }
-
- // send the best path back
- return codePath;
- },
- /*
- * Calculate the time format to use. We have a default format set in the
- * options but it can be imcomplete. We ajust it according to the media
- * duration.
- *
- * We support format like 'hh:mm:ss:ff'.
- */
- calculateTimeFormat: function(time, options, fps) {
- if (time < 0) {
- time = 0;
- }
- if(typeof fps == 'undefined') {
- fps = 25;
- }
- var format = options.timeFormat,
- firstChar = format[0],
- firstTwoPlaces = (format[1] == format[0]),
- separatorIndex = firstTwoPlaces? 2: 1,
- separator = ':',
- hours = Math.floor(time / 3600) % 24,
- minutes = Math.floor(time / 60) % 60,
- seconds = Math.floor(time % 60),
- frames = Math.floor(((time % 1)*fps).toFixed(3)),
- lis = [
- [frames, 'f'],
- [seconds, 's'],
- [minutes, 'm'],
- [hours, 'h']
- ];
- // Try to get the separator from the format
- if (format.length < separatorIndex) {
- separator = format[separatorIndex];
- }
- var required = false;
- for (var i=0, len=lis.length; i < len; i++) {
- if (format.indexOf(lis[i][1]) !== -1) {
- required=true;
- }
- else if (required) {
- var hasNextValue = false;
- for (var j=i; j < len; j++) {
- if (lis[j][0] > 0) {
- hasNextValue = true;
- break;
- }
- }
- if (! hasNextValue) {
- break;
- }
- if (!firstTwoPlaces) {
- format = firstChar + format;
- }
- format = lis[i][1] + separator + format;
- if (firstTwoPlaces) {
- format = lis[i][1] + format;
- }
- firstChar = lis[i][1];
- }
- }
- options.currentTimeFormat = format;
- },
- /*
- * Prefix the given number by zero if it is lower than 10.
- */
- twoDigitsString: function(n) {
- if (n < 10) {
- return '0' + n;
- }
- return String(n);
- },
- secondsToTimeCode: function(time, options) {
- if (time < 0) {
- time = 0;
- }
- // Maintain backward compatibility with method signature before v2.18.
- if (typeof options !== 'object') {
- var format = 'm:ss';
- format = arguments[1] ? 'hh:mm:ss' : format; // forceHours
- format = arguments[2] ? format + ':ff' : format; // showFrameCount
- options = {
- currentTimeFormat: format,
- framesPerSecond: arguments[3] || 25
- };
- }
- var fps = options.framesPerSecond;
- if(typeof fps === 'undefined') {
- fps = 25;
- }
- var format = options.currentTimeFormat,
- hours = Math.floor(time / 3600) % 24,
- minutes = Math.floor(time / 60) % 60,
- seconds = Math.floor(time % 60),
- frames = Math.floor(((time % 1)*fps).toFixed(3));
- lis = [
- [frames, 'f'],
- [seconds, 's'],
- [minutes, 'm'],
- [hours, 'h']
- ];
- var res = format;
- for (i=0,len=lis.length; i < len; i++) {
- res = res.replace(lis[i][1]+lis[i][1], this.twoDigitsString(lis[i][0]));
- res = res.replace(lis[i][1], lis[i][0]);
- }
- return res;
- },
-
- timeCodeToSeconds: function(hh_mm_ss_ff, forceHours, showFrameCount, fps){
- if (typeof showFrameCount == 'undefined') {
- showFrameCount=false;
- } else if(typeof fps == 'undefined') {
- fps = 25;
- }
-
- var tc_array = hh_mm_ss_ff.split(":"),
- tc_hh = parseInt(tc_array[0], 10),
- tc_mm = parseInt(tc_array[1], 10),
- tc_ss = parseInt(tc_array[2], 10),
- tc_ff = 0,
- tc_in_seconds = 0;
-
- if (showFrameCount) {
- tc_ff = parseInt(tc_array[3])/fps;
- }
-
- tc_in_seconds = ( tc_hh * 3600 ) + ( tc_mm * 60 ) + tc_ss + tc_ff;
-
- return tc_in_seconds;
- },
-
- convertSMPTEtoSeconds: function (SMPTE) {
- if (typeof SMPTE != 'string')
- return false;
- SMPTE = SMPTE.replace(',', '.');
-
- var secs = 0,
- decimalLen = (SMPTE.indexOf('.') != -1) ? SMPTE.split('.')[1].length : 0,
- multiplier = 1;
-
- SMPTE = SMPTE.split(':').reverse();
-
- for (var i = 0; i < SMPTE.length; i++) {
- multiplier = 1;
- if (i > 0) {
- multiplier = Math.pow(60, i);
- }
- secs += Number(SMPTE[i]) * multiplier;
- }
- return Number(secs.toFixed(decimalLen));
- },
-
- /* borrowed from SWFObject: http://code.google.com/p/swfobject/source/browse/trunk/swfobject/src/swfobject.js#474 */
- removeSwf: function(id) {
- var obj = document.getElementById(id);
- if (obj && /object|embed/i.test(obj.nodeName)) {
- if (mejs.MediaFeatures.isIE) {
- obj.style.display = "none";
- (function(){
- if (obj.readyState == 4) {
- mejs.Utility.removeObjectInIE(id);
- } else {
- setTimeout(arguments.callee, 10);
- }
- })();
- } else {
- obj.parentNode.removeChild(obj);
- }
- }
- },
- removeObjectInIE: function(id) {
- var obj = document.getElementById(id);
- if (obj) {
- for (var i in obj) {
- if (typeof obj[i] == "function") {
- obj[i] = null;
- }
- }
- obj.parentNode.removeChild(obj);
- }
- },
- determineScheme: function(url) {
- if (url && url.indexOf("://") != -1) {
- return url.substr(0, url.indexOf("://")+3);
- }
- return "//"; // let user agent figure this out
- },
- // taken from underscore
- debounce: function(func, wait, immediate) {
- var timeout;
- return function() {
- var context = this, args = arguments;
- var later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- },
- /**
- * Returns true if targetNode appears after sourceNode in the dom.
- * @param {HTMLElement} sourceNode - the source node for comparison
- * @param {HTMLElement} targetNode - the node to compare against sourceNode
- */
- isNodeAfter: function(sourceNode, targetNode) {
- return !!(
- sourceNode &&
- targetNode &&
- typeof sourceNode.compareDocumentPosition === 'function' &&
- sourceNode.compareDocumentPosition(targetNode) & Node.DOCUMENT_POSITION_PRECEDING
- );
- }
- };
- // Core detector, plugins are added below
- mejs.PluginDetector = {
- // main public function to test a plug version number PluginDetector.hasPluginVersion('flash',[9,0,125]);
- hasPluginVersion: function(plugin, v) {
- var pv = this.plugins[plugin];
- v[1] = v[1] || 0;
- v[2] = v[2] || 0;
- return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
- },
- // cached values
- nav: window.navigator,
- ua: window.navigator.userAgent.toLowerCase(),
- // stored version numbers
- plugins: [],
- // runs detectPlugin() and stores the version number
- addPlugin: function(p, pluginName, mimeType, activeX, axDetect) {
- this.plugins[p] = this.detectPlugin(pluginName, mimeType, activeX, axDetect);
- },
- // get the version number from the mimetype (all but IE) or ActiveX (IE)
- detectPlugin: function(pluginName, mimeType, activeX, axDetect) {
- var version = [0,0,0],
- description,
- i,
- ax;
- // Firefox, Webkit, Opera
- if (typeof(this.nav.plugins) != 'undefined' && typeof this.nav.plugins[pluginName] == 'object') {
- description = this.nav.plugins[pluginName].description;
- if (description && !(typeof this.nav.mimeTypes != 'undefined' && this.nav.mimeTypes[mimeType] && !this.nav.mimeTypes[mimeType].enabledPlugin)) {
- version = description.replace(pluginName, '').replace(/^\s+/,'').replace(/\sr/gi,'.').split('.');
- for (i=0; i<version.length; i++) {
- version[i] = parseInt(version[i].match(/\d+/), 10);
- }
- }
- // Internet Explorer / ActiveX
- } else if (typeof(window.ActiveXObject) != 'undefined') {
- try {
- ax = new ActiveXObject(activeX);
- if (ax) {
- version = axDetect(ax);
- }
- }
- catch (e) { }
- }
- return version;
- }
- };
- // Add Flash detection
- mejs.PluginDetector.addPlugin('flash','Shockwave Flash','application/x-shockwave-flash','ShockwaveFlash.ShockwaveFlash', function(ax) {
- // adapted from SWFObject
- var version = [],
- d = ax.GetVariable("$version");
- if (d) {
- d = d.split(" ")[1].split(",");
- version = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
- }
- return version;
- });
- // Add Silverlight detection
- mejs.PluginDetector.addPlugin('silverlight','Silverlight Plug-In','application/x-silverlight-2','AgControl.AgControl', function (ax) {
- // Silverlight cannot report its version number to IE
- // but it does have a isVersionSupported function, so we have to loop through it to get a version number.
- // adapted from http://www.silverlightversion.com/
- var v = [0,0,0,0],
- loopMatch = function(ax, v, i, n) {
- while(ax.isVersionSupported(v[0]+ "."+ v[1] + "." + v[2] + "." + v[3])){
- v[i]+=n;
- }
- v[i] -= n;
- };
- loopMatch(ax, v, 0, 1);
- loopMatch(ax, v, 1, 1);
- loopMatch(ax, v, 2, 10000); // the third place in the version number is usually 5 digits (4.0.xxxxx)
- loopMatch(ax, v, 2, 1000);
- loopMatch(ax, v, 2, 100);
- loopMatch(ax, v, 2, 10);
- loopMatch(ax, v, 2, 1);
- loopMatch(ax, v, 3, 1);
- return v;
- });
- // add adobe acrobat
- /*
- PluginDetector.addPlugin('acrobat','Adobe Acrobat','application/pdf','AcroPDF.PDF', function (ax) {
- var version = [],
- d = ax.GetVersions().split(',')[0].split('=')[1].split('.');
- if (d) {
- version = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
- }
- return version;
- });
- */
- // necessary detection (fixes for <IE9)
- mejs.MediaFeatures = {
- init: function() {
- var
- t = this,
- d = document,
- nav = mejs.PluginDetector.nav,
- ua = mejs.PluginDetector.ua.toLowerCase(),
- i,
- v,
- html5Elements = ['source','track','audio','video'];
- // detect browsers (only the ones that have some kind of quirk we need to work around)
- t.isiPad = (ua.match(/ipad/i) !== null);
- t.isiPhone = (ua.match(/iphone/i) !== null);
- t.isiOS = t.isiPhone || t.isiPad;
- t.isAndroid = (ua.match(/android/i) !== null);
- t.isBustedAndroid = (ua.match(/android 2\.[12]/) !== null);
- t.isBustedNativeHTTPS = (location.protocol === 'https:' && (ua.match(/android [12]\./) !== null || ua.match(/macintosh.* version.* safari/) !== null));
- t.isIE = (nav.appName.toLowerCase().indexOf("microsoft") != -1 || nav.appName.toLowerCase().match(/trident/gi) !== null);
- t.isChrome = (ua.match(/chrome/gi) !== null);
- t.isChromium = (ua.match(/chromium/gi) !== null);
- t.isFirefox = (ua.match(/firefox/gi) !== null);
- t.isWebkit = (ua.match(/webkit/gi) !== null);
- t.isGecko = (ua.match(/gecko/gi) !== null) && !t.isWebkit && !t.isIE;
- t.isOpera = (ua.match(/opera/gi) !== null);
- t.hasTouch = ('ontouchstart' in window); // && window.ontouchstart != null); // this breaks iOS 7
- // Borrowed from `Modernizr.svgasimg`, sources:
- // - https://github.com/Modernizr/Modernizr/issues/687
- // - https://github.com/Modernizr/Modernizr/pull/1209/files
- t.svgAsImg = !!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1');
- // create HTML5 media elements for IE before 9, get a <video> element for fullscreen detection
- for (i=0; i<html5Elements.length; i++) {
- v = document.createElement(html5Elements[i]);
- }
- t.supportsMediaTag = (typeof v.canPlayType !== 'undefined' || t.isBustedAndroid);
- // Fix for IE9 on Windows 7N / Windows 7KN (Media Player not installer)
- try{
- v.canPlayType("video/mp4");
- }catch(e){
- t.supportsMediaTag = false;
- }
- t.supportsPointerEvents = (function() {
- // TAKEN FROM MODERNIZR
- var element = document.createElement('x'),
- documentElement = document.documentElement,
- getComputedStyle = window.getComputedStyle,
- supports;
- if(!('pointerEvents' in element.style)){
- return false;
- }
- element.style.pointerEvents = 'auto';
- element.style.pointerEvents = 'x';
- documentElement.appendChild(element);
- supports = getComputedStyle &&
- getComputedStyle(element, '').pointerEvents === 'auto';
- documentElement.removeChild(element);
- return !!supports;
- })();
- // Older versions of Firefox can't move plugins around without it resetting,
- t.hasFirefoxPluginMovingProblem = false;
- // detect native JavaScript fullscreen (Safari/Firefox only, Chrome still fails)
- // iOS
- t.hasiOSFullScreen = (typeof v.webkitEnterFullscreen !== 'undefined');
- // W3C
- t.hasNativeFullscreen = (typeof v.requestFullscreen !== 'undefined');
- // webkit/firefox/IE11+
- t.hasWebkitNativeFullScreen = (typeof v.webkitRequestFullScreen !== 'undefined');
- t.hasMozNativeFullScreen = (typeof v.mozRequestFullScreen !== 'undefined');
- t.hasMsNativeFullScreen = (typeof v.msRequestFullscreen !== 'undefined');
- t.hasTrueNativeFullScreen = (t.hasWebkitNativeFullScreen || t.hasMozNativeFullScreen || t.hasMsNativeFullScreen);
- t.nativeFullScreenEnabled = t.hasTrueNativeFullScreen;
- // Enabled?
- if (t.hasMozNativeFullScreen) {
- t.nativeFullScreenEnabled = document.mozFullScreenEnabled;
- } else if (t.hasMsNativeFullScreen) {
- t.nativeFullScreenEnabled = document.msFullscreenEnabled;
- }
- if (t.isChrome) {
- t.hasiOSFullScreen = false;
- }
- if (t.hasTrueNativeFullScreen) {
- t.fullScreenEventName = '';
- if (t.hasWebkitNativeFullScreen) {
- t.fullScreenEventName = 'webkitfullscreenchange';
- } else if (t.hasMozNativeFullScreen) {
- t.fullScreenEventName = 'mozfullscreenchange';
- } else if (t.hasMsNativeFullScreen) {
- t.fullScreenEventName = 'MSFullscreenChange';
- }
- t.isFullScreen = function() {
- if (t.hasMozNativeFullScreen) {
- return d.mozFullScreen;
- } else if (t.hasWebkitNativeFullScreen) {
- return d.webkitIsFullScreen;
- } else if (t.hasMsNativeFullScreen) {
- return d.msFullscreenElement !== null;
- }
- }
- t.requestFullScreen = function(el) {
- if (t.hasWebkitNativeFullScreen) {
- el.webkitRequestFullScreen();
- } else if (t.hasMozNativeFullScreen) {
- el.mozRequestFullScreen();
- } else if (t.hasMsNativeFullScreen) {
- el.msRequestFullscreen();
- }
- }
- t.cancelFullScreen = function() {
- if (t.hasWebkitNativeFullScreen) {
- document.webkitCancelFullScreen();
- } else if (t.hasMozNativeFullScreen) {
- document.mozCancelFullScreen();
- } else if (t.hasMsNativeFullScreen) {
- document.msExitFullscreen();
- }
- }
- }
- // OS X 10.5 can't do this even if it says it can :(
- if (t.hasiOSFullScreen && ua.match(/mac os x 10_5/i)) {
- t.hasNativeFullScreen = false;
- t.hasiOSFullScreen = false;
- }
- }
- };
- mejs.MediaFeatures.init();
- /*
- extension methods to <video> or <audio> object to bring it into parity with PluginMediaElement (see below)
- */
- mejs.HtmlMediaElement = {
- pluginType: 'native',
- isFullScreen: false,
- setCurrentTime: function (time) {
- this.currentTime = time;
- },
- setMuted: function (muted) {
- this.muted = muted;
- },
- setVolume: function (volume) {
- this.volume = volume;
- },
- // for parity with the plugin versions
- stop: function () {
- this.pause();
- },
- // This can be a url string
- // or an array [{src:'file.mp4',type:'video/mp4'},{src:'file.webm',type:'video/webm'}]
- setSrc: function (url) {
-
- // Fix for IE9 which can't set .src when there are <source> elements. Awesome, right?
- var
- existingSources = this.getElementsByTagName('source');
- while (existingSources.length > 0){
- this.removeChild(existingSources[0]);
- }
-
- if (typeof url == 'string') {
- this.src = url;
- } else {
- var i, media;
- for (i=0; i<url.length; i++) {
- media = url[i];
- if (this.canPlayType(media.type)) {
- this.src = media.src;
- break;
- }
- }
- }
- },
- setVideoSize: function (width, height) {
- this.width = width;
- this.height = height;
- }
- };
- /*
- Mimics the <video/audio> element by calling Flash's External Interface or Silverlights [ScriptableMember]
- */
- mejs.PluginMediaElement = function (pluginid, pluginType, mediaUrl) {
- this.id = pluginid;
- this.pluginType = pluginType;
- this.src = mediaUrl;
- this.events = {};
- this.attributes = {};
- };
- // JavaScript values and ExternalInterface methods that match HTML5 video properties methods
- // http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlayback.html
- // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html
- mejs.PluginMediaElement.prototype = {
- // special
- pluginElement: null,
- pluginType: '',
- isFullScreen: false,
- // not implemented :(
- playbackRate: -1,
- defaultPlaybackRate: -1,
- seekable: [],
- played: [],
- // HTML5 read-only properties
- paused: true,
- ended: false,
- seeking: false,
- duration: 0,
- error: null,
- tagName: '',
- // HTML5 get/set properties, but only set (updated by event handlers)
- muted: false,
- volume: 1,
- currentTime: 0,
- // HTML5 methods
- play: function () {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
- this.pluginApi.playVideo();
- } else {
- this.pluginApi.playMedia();
- }
- this.paused = false;
- }
- },
- load: function () {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
- } else {
- this.pluginApi.loadMedia();
- }
-
- this.paused = false;
- }
- },
- pause: function () {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
- if( this.pluginApi.getPlayerState() == 1 ) {
- this.pluginApi.pauseVideo();
- }
- } else {
- this.pluginApi.pauseMedia();
- }
-
-
- this.paused = true;
- }
- },
- stop: function () {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
- this.pluginApi.stopVideo();
- } else {
- this.pluginApi.stopMedia();
- }
- this.paused = true;
- }
- },
- canPlayType: function(type) {
- var i,
- j,
- pluginInfo,
- pluginVersions = mejs.plugins[this.pluginType];
- for (i=0; i<pluginVersions.length; i++) {
- pluginInfo = pluginVersions[i];
- // test if user has the correct plugin version
- if (mejs.PluginDetector.hasPluginVersion(this.pluginType, pluginInfo.version)) {
- // test for plugin playback types
- for (j=0; j<pluginInfo.types.length; j++) {
- // find plugin that can play the type
- if (type == pluginInfo.types[j]) {
- return 'probably';
- }
- }
- }
- }
- return '';
- },
-
- positionFullscreenButton: function(x,y,visibleAndAbove) {
- if (this.pluginApi != null && this.pluginApi.positionFullscreenButton) {
- this.pluginApi.positionFullscreenButton(Math.floor(x),Math.floor(y),visibleAndAbove);
- }
- },
-
- hideFullscreenButton: function() {
- if (this.pluginApi != null && this.pluginApi.hideFullscreenButton) {
- this.pluginApi.hideFullscreenButton();
- }
- },
-
- // custom methods since not all JavaScript implementations support get/set
- // This can be a url string
- // or an array [{src:'file.mp4',type:'video/mp4'},{src:'file.webm',type:'video/webm'}]
- setSrc: function (url) {
- if (typeof url == 'string') {
- this.pluginApi.setSrc(mejs.Utility.absolutizeUrl(url));
- this.src = mejs.Utility.absolutizeUrl(url);
- } else {
- var i, media;
- for (i=0; i<url.length; i++) {
- media = url[i];
- if (this.canPlayType(media.type)) {
- this.pluginApi.setSrc(mejs.Utility.absolutizeUrl(media.src));
- this.src = mejs.Utility.absolutizeUrl(media.src);
- break;
- }
- }
- }
- },
- setCurrentTime: function (time) {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube' || this.pluginType == 'vimeo') {
- this.pluginApi.seekTo(time);
- } else {
- this.pluginApi.setCurrentTime(time);
- }
-
-
-
- this.currentTime = time;
- }
- },
- setVolume: function (volume) {
- if (this.pluginApi != null) {
- // same on YouTube and MEjs
- if (this.pluginType == 'youtube') {
- this.pluginApi.setVolume(volume * 100);
- } else {
- this.pluginApi.setVolume(volume);
- }
- this.volume = volume;
- }
- },
- setMuted: function (muted) {
- if (this.pluginApi != null) {
- if (this.pluginType == 'youtube') {
- if (muted) {
- this.pluginApi.mute();
- } else {
- this.pluginApi.unMute();
- }
- this.muted = muted;
- this.dispatchEvent({type:'volumechange'});
- } else {
- this.pluginApi.setMuted(muted);
- }
- this.muted = muted;
- }
- },
- // additional non-HTML5 methods
- setVideoSize: function (width, height) {
-
- //if (this.pluginType == 'flash' || this.pluginType == 'silverlight') {
- if (this.pluginElement && this.pluginElement.style) {
- this.pluginElement.style.width = width + 'px';
- this.pluginElement.style.height = height + 'px';
- }
- if (this.pluginApi != null && this.pluginApi.setVideoSize) {
- this.pluginApi.setVideoSize(width, height);
- }
- //}
- },
- setFullscreen: function (fullscreen) {
- if (this.pluginApi != null && this.pluginApi.setFullscreen) {
- this.pluginApi.setFullscreen(fullscreen);
- }
- },
-
- enterFullScreen: function() {
- if (this.pluginApi != null && this.pluginApi.setFullscreen) {
- this.setFullscreen(true);
- }
-
- },
-
- exitFullScreen: function() {
- if (this.pluginApi != null && this.pluginApi.setFullscreen) {
- this.setFullscreen(false);
- }
- },
- // start: fake events
- addEventListener: function (eventName, callback, bubble) {
- this.events[eventName] = this.events[eventName] || [];
- this.events[eventName].push(callback);
- },
- removeEventListener: function (eventName, callback) {
- if (!eventName) { this.events = {}; return true; }
- var callbacks = this.events[eventName];
- if (!callbacks) return true;
- if (!callback) { this.events[eventName] = []; return true; }
- for (var i = 0; i < callbacks.length; i++) {
- if (callbacks[i] === callback) {
- this.events[eventName].splice(i, 1);
- return true;
- }
- }
- return false;
- },
- dispatchEvent: function (event) {
- var i,
- args,
- callbacks = this.events[event.type];
- if (callbacks) {
- for (i = 0; i < callbacks.length; i++) {
- callbacks[i].apply(this, [event]);
- }
- }
- },
- // end: fake events
-
- // fake DOM attribute methods
- hasAttribute: function(name){
- return (name in this.attributes);
- },
- removeAttribute: function(name){
- delete this.attributes[name];
- },
- getAttribute: function(name){
- if (this.hasAttribute(name)) {
- return this.attributes[name];
- }
- return null;
- },
- setAttribute: function(name, value){
- this.attributes[name] = value;
- },
- remove: function() {
- mejs.Utility.removeSwf(this.pluginElement.id);
- }
- };
- /*
- Default options
- */
- mejs.MediaElementDefaults = {
- // allows testing on HTML5, flash, silverlight
- // auto: attempts to detect what the browser can do
- // auto_plugin: prefer plugins and then attempt native HTML5
- // native: forces HTML5 playback
- // shim: disallows HTML5, will attempt either Flash or Silverlight
- // none: forces fallback view
- mode: 'auto',
- // remove or reorder to change plugin priority and availability
- plugins: ['flash','silverlight','youtube','vimeo'],
- // shows debug errors on screen
- enablePluginDebug: false,
- // use plugin for browsers that have trouble with Basic Authentication on HTTPS sites
- httpsBasicAuthSite: false,
- // overrides the type specified, useful for dynamic instantiation
- type: '',
- // path to Flash and Silverlight plugins
- pluginPath: mejs.Utility.getScriptPath(['mediaelement.js','mediaelement.min.js','mediaelement-and-player.js','mediaelement-and-player.min.js']),
- // name of flash file
- flashName: 'flashmediaelement.swf',
- // streamer for RTMP streaming
- flashStreamer: '',
- // set to 'always' for CDN version
- flashScriptAccess: 'sameDomain',
- // turns on the smoothing filter in Flash
- enablePluginSmoothing: false,
- // enabled pseudo-streaming (seek) on .mp4 files
- enablePseudoStreaming: false,
- // start query parameter sent to server for pseudo-streaming
- pseudoStreamingStartQueryParam: 'start',
- // name of silverlight file
- silverlightName: 'silverlightmediaelement.xap',
- // default if the <video width> is not specified
- defaultVideoWidth: 480,
- // default if the <video height> is not specified
- defaultVideoHeight: 270,
- // overrides <video width>
- pluginWidth: -1,
- // overrides <video height>
- pluginHeight: -1,
- // additional plugin variables in 'key=value' form
- pluginVars: [],
- // rate in milliseconds for Flash and Silverlight to fire the timeupdate event
- // larger number is less accurate, but less strain on plugin->JavaScript bridge
- timerRate: 250,
- // initial volume for player
- startVolume: 0.8,
- // custom error message in case media cannot be played; otherwise, Download File
- // link will be displayed
- customError: "",
- success: function () { },
- error: function () { }
- };
- /*
- Determines if a browser supports the <video> or <audio> element
- and returns either the native element or a Flash/Silverlight version that
- mimics HTML5 MediaElement
- */
- mejs.MediaElement = function (el, o) {
- return mejs.HtmlMediaElementShim.create(el,o);
- };
- mejs.HtmlMediaElementShim = {
- create: function(el, o) {
- var
- options = {},
- htmlMediaElement = (typeof(el) == 'string') ? document.getElementById(el) : el,
- tagName = htmlMediaElement.tagName.toLowerCase(),
- isMediaTag = (tagName === 'audio' || tagName === 'video'),
- src = (isMediaTag) ? htmlMediaElement.getAttribute('src') : htmlMediaElement.getAttribute('href'),
- poster = htmlMediaElement.getAttribute('poster'),
- autoplay = htmlMediaElement.getAttribute('autoplay'),
- preload = htmlMediaElement.getAttribute('preload'),
- controls = htmlMediaElement.getAttribute('controls'),
- playback,
- prop;
- // extend options
- for (prop in mejs.MediaElementDefaults) {
- options[prop] = mejs.MediaElementDefaults[prop];
- }
- for (prop in o) {
- options[prop] = o[prop];
- }
-
- // clean up attributes
- src = (typeof src == 'undefined' || src === null || src == '') ? null : src;
- poster = (typeof poster == 'undefined' || poster === null) ? '' : poster;
- preload = (typeof preload == 'undefined' || preload === null || preload === 'false') ? 'none' : preload;
- autoplay = !(typeof autoplay == 'undefined' || autoplay === null || autoplay === 'false');
- controls = !(typeof controls == 'undefined' || controls === null || controls === 'false');
- // test for HTML5 and plugin capabilities
- playback = this.determinePlayback(htmlMediaElement, options, mejs.MediaFeatures.supportsMediaTag, isMediaTag, src);
- playback.url = (playback.url !== null) ? mejs.Utility.absolutizeUrl(playback.url) : '';
- playback.scheme = mejs.Utility.determineScheme(playback.url);
- if (playback.method == 'native') {
- // second fix for android
- if (mejs.MediaFeatures.isBustedAndroid) {
- htmlMediaElement.src = playback.url;
- htmlMediaElement.addEventListener('click', function() {
- htmlMediaElement.play();
- }, false);
- }
-
- // add methods to native HTMLMediaElement
- return this.updateNative(playback, options, autoplay, preload);
- } else if (playback.method !== '') {
- // create plugin to mimic HTMLMediaElement
-
- return this.createPlugin( playback, options, poster, autoplay, preload, controls);
- } else {
- // boo, no HTML5, no Flash, no Silverlight.
- this.createErrorMessage( playback, options, poster );
-
- return this;
- }
- },
-
- determinePlayback: function(htmlMediaElement, options, supportsMediaTag, isMediaTag, src) {
- var
- mediaFiles = [],
- i,
- j,
- k,
- l,
- n,
- type,
- result = { method: '', url: '', htmlMediaElement: htmlMediaElement, isVideo: (htmlMediaElement.tagName.toLowerCase() !== 'audio'), scheme: ''},
- pluginName,
- pluginVersions,
- pluginInfo,
- dummy,
- media;
-
- // STEP 1: Get URL and type from <video src> or <source src>
- // supplied type overrides <video type> and <source type>
- if (typeof options.type != 'undefined' && options.type !== '') {
-
- // accept either string or array of types
- if (typeof options.type == 'string') {
- mediaFiles.push({type:options.type, url:src});
- } else {
-
- for (i=0; i<options.type.length; i++) {
- mediaFiles.push({type:options.type[i], url:src});
- }
- }
- // test for src attribute first
- } else if (src !== null) {
- type = this.formatType(src, htmlMediaElement.getAttribute('type'));
- mediaFiles.push({type:type, url:src});
- // then test for <source> elements
- } else {
- // test <source> types to see if they are usable
- for (i = 0; i < htmlMediaElement.childNodes.length; i++) {
- n = htmlMediaElement.childNodes[i];
- if (n.nodeType == 1 && n.tagName.toLowerCase() == 'source') {
- src = n.getAttribute('src');
- type = this.formatType(src, n.getAttribute('type'));
- media = n.getAttribute('media');
- if (!media || !window.matchMedia || (window.matchMedia && window.matchMedia(media).matches)) {
- mediaFiles.push({type:type, url:src});
- }
- }
- }
- }
-
- // in the case of dynamicly created players
- // check for audio types
- if (!isMediaTag && mediaFiles.length > 0 && mediaFiles[0].url !== null && this.getTypeFromFile(mediaFiles[0].url).indexOf('audio') > -1) {
- result.isVideo = false;
- }
-
- // STEP 2: Test for playback method
-
- // special case for Android which sadly doesn't implement the canPlayType function (always returns '')
- if (result.isVideo && mejs.MediaFeatures.isBustedAndroid) {
- htmlMediaElement.canPlayType = function(type) {
- return (type.match(/video\/(mp4|m4v)/gi) !== null) ? 'maybe' : '';
- };
- }
-
- // special case for Chromium to specify natively supported video codecs (i.e. WebM and Theora)
- if (result.isVideo && mejs.MediaFeatures.isChromium) {
- htmlMediaElement.canPlayType = function(type) {
- return (type.match(/video\/(webm|ogv|ogg)/gi) !== null) ? 'maybe' : '';
- };
- }
- // test for native playback first
- if (supportsMediaTag && (options.mode === 'auto' || options.mode === 'auto_plugin' || options.mode === 'native') && !(mejs.MediaFeatures.isBustedNativeHTTPS && options.httpsBasicAuthSite === true)) {
-
- if (!isMediaTag) {
- // create a real HTML5 Media Element
- dummy = document.createElement( result.isVideo ? 'video' : 'audio');
- htmlMediaElement.parentNode.insertBefore(dummy, htmlMediaElement);
- htmlMediaElement.style.display = 'none';
-
- // use this one from now on
- result.htmlMediaElement = htmlMediaElement = dummy;
- }
-
- for (i=0; i<mediaFiles.length; i++) {
- // normal check
- if (mediaFiles[i].type == "video/m3u8" || htmlMediaElement.canPlayType(mediaFiles[i].type).replace(/no/, '') !== ''
- // special case for Mac/Safari 5.0.3 which answers '' to canPlayType('audio/mp3') but 'maybe' to canPlayType('audio/mpeg')
- || htmlMediaElement.canPlayType(mediaFiles[i].type.replace(/mp3/,'mpeg')).replace(/no/, '') !== ''
- // special case for m4a supported by detecting mp4 support
- || htmlMediaElement.canPlayType(mediaFiles[i].type.replace(/m4a/,'mp4')).replace(/no/, '') !== '') {
- result.method = 'native';
- result.url = mediaFiles[i].url;
- break;
- }
- }
-
- if (result.method === 'native') {
- if (result.url !== null) {
- htmlMediaElement.src = result.url;
- }
-
- // if `auto_plugin` mode, then cache the native result but try plugins.
- if (options.mode !== 'auto_plugin') {
- return result;
- }
- }
- }
- // if native playback didn't work, then test plugins
- if (options.mode === 'auto' || options.mode === 'auto_plugin' || options.mode === 'shim') {
- for (i=0; i<mediaFiles.length; i++) {
- type = mediaFiles[i].type;
- // test all plugins in order of preference [silverlight, flash]
- for (j=0; j<options.plugins.length; j++) {
- pluginName = options.plugins[j];
-
- // test version of plugin (for future features)
- pluginVersions = mejs.plugins[pluginName];
-
- for (k=0; k<pluginVersions.length; k++) {
- pluginInfo = pluginVersions[k];
-
- // test if user has the correct plugin version
-
- // for youtube/vimeo
- if (pluginInfo.version == null ||
-
- mejs.PluginDetector.hasPluginVersion(pluginName, pluginInfo.version)) {
- // test for plugin playback types
- for (l=0; l<pluginInfo.types.length; l++) {
- // find plugin that can play the type
- if (type.toLowerCase() == pluginInfo.types[l].toLowerCase()) {
- result.method = pluginName;
- result.url = mediaFiles[i].url;
- return result;
- }
- }
- }
- }
- }
- }
- }
-
- // at this point, being in 'auto_plugin' mode implies that we tried plugins but failed.
- // if we have native support then return that.
- if (options.mode === 'auto_plugin' && result.method === 'native') {
- return result;
- }
- // what if there's nothing to play? just grab the first available
- if (result.method === '' && mediaFiles.length > 0) {
- result.url = mediaFiles[0].url;
- }
- return result;
- },
- formatType: function(url, type) {
- // if no type is supplied, fake it with the extension
- if (url && !type) {
- return this.getTypeFromFile(url);
- } else {
- // only return the mime part of the type in case the attribute contains the codec
- // see http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#the-source-element
- // `video/mp4; codecs="avc1.42E01E, mp4a.40.2"` becomes `video/mp4`
-
- if (type && ~type.indexOf(';')) {
- return type.substr(0, type.indexOf(';'));
- } else {
- return type;
- }
- }
- },
-
- getTypeFromFile: function(url) {
- url = url.split('?')[0];
- var
- ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase(),
- av = /(mp4|m4v|ogg|ogv|m3u8|webm|webmv|flv|wmv|mpeg|mov)/gi.test(ext) ? 'video/' : 'audio/';
- return this.getTypeFromExtension(ext, av);
- },
-
- getTypeFromExtension: function(ext, av) {
- av = av || '';
-
- switch (ext) {
- case 'mp4':
- case 'm4v':
- case 'm4a':
- case 'f4v':
- case 'f4a':
- return av + 'mp4';
- case 'flv':
- return av + 'x-flv';
- case 'webm':
- case 'webma':
- case 'webmv':
- return av + 'webm';
- case 'ogg':
- case 'oga':
- case 'ogv':
- return av + 'ogg';
- case 'm3u8':
- return 'application/x-mpegurl';
- case 'ts':
- return av + 'mp2t';
- default:
- return av + ext;
- }
- },
- createErrorMessage: function(playback, options, poster) {
- var
- htmlMediaElement = playback.htmlMediaElement,
- errorContainer = document.createElement('div'),
- errorContent = options.customError;
-
- errorContainer.className = 'me-cannotplay';
- try {
- errorContainer.style.width = htmlMediaElement.width + 'px';
- errorContainer.style.height = htmlMediaElement.height + 'px';
- } catch (e) {}
- if (!errorContent) {
- errorContent = '<a href="' + playback.url + '">';
- if (poster !== '') {
- errorContent += '<img src="' + poster + '" width="100%" height="100%" alt="" />';
- }
- errorContent += '<span>' + mejs.i18n.t('mejs.download-file') + '</span></a>';
- }
- errorContainer.innerHTML = errorContent;
- htmlMediaElement.parentNode.insertBefore(errorContainer, htmlMediaElement);
- htmlMediaElement.style.display = 'none';
- options.error(htmlMediaElement);
- },
- createPlugin:function(playback, options, poster, autoplay, preload, controls) {
- var
- htmlMediaElement = playback.htmlMediaElement,
- width = 1,
- height = 1,
- pluginid = 'me_' + playback.method + '_' + (mejs.meIndex++),
- pluginMediaElement = new mejs.PluginMediaElement(pluginid, playback.method, playback.url),
- container = document.createElement('div'),
- specialIEContainer,
- node,
- initVars;
- // copy tagName from html media element
- pluginMediaElement.tagName = htmlMediaElement.tagName;
- // copy attributes from html media element to plugin media element
- for (var i = 0; i < htmlMediaElement.attributes.length; i++) {
- var attribute = htmlMediaElement.attributes[i];
- if (attribute.specified) {
- pluginMediaElement.setAttribute(attribute.name, attribute.value);
- }
- }
- // check for placement inside a <p> tag (sometimes WYSIWYG editors do this)
- node = htmlMediaElement.parentNode;
- while (node !== null && node.tagName != null && node.tagName.toLowerCase() !== 'body' &&
- node.parentNode != null && node.parentNode.tagName != null && node.parentNode.constructor != null && node.parentNode.constructor.name === "ShadowRoot") {
- if (node.parentNode.tagName.toLowerCase() === 'p') {
- node.parentNode.parentNode.insertBefore(node, node.parentNode);
- break;
- }
- node = node.parentNode;
- }
- if (playback.isVideo) {
- width = (options.pluginWidth > 0) ? options.pluginWidth : (options.videoWidth > 0) ? options.videoWidth : (htmlMediaElement.getAttribute('width') !== null) ? htmlMediaElement.getAttribute('width') : options.defaultVideoWidth;
- height = (options.pluginHeight > 0) ? options.pluginHeight : (options.videoHeight > 0) ? options.videoHeight : (htmlMediaElement.getAttribute('height') !== null) ? htmlMediaElement.getAttribute('height') : options.defaultVideoHeight;
-
- // in case of '%' make sure it's encoded
- width = mejs.Utility.encodeUrl(width);
- height = mejs.Utility.encodeUrl(height);
-
- } else {
- if (options.enablePluginDebug) {
- width = 320;
- height = 240;
- }
- }
- // register plugin
- pluginMediaElement.success = options.success;
-
- // add container (must be added to DOM before inserting HTML for IE)
- container.className = 'me-plugin';
- container.id = pluginid + '_container';
-
- if (playback.isVideo) {
- htmlMediaElement.parentNode.insertBefore(container, htmlMediaElement);
- } else {
- document.body.insertBefore(container, document.body.childNodes[0]);
- }
-
- if (playback.method === 'flash' || playback.method === 'silverlight') {
- var canPlayVideo = htmlMediaElement.getAttribute('type') === 'audio/mp4',
- childrenSources = htmlMediaElement.getElementsByTagName('source');
- if (childrenSources && !canPlayVideo) {
- for (var i = 0, total = childrenSources.length; i < total; i++) {
- if (childrenSources[i].getAttribute('type') === 'audio/mp4') {
- canPlayVideo = true;
- }
- }
- }
- // flash/silverlight vars
- initVars = [
- 'id=' + pluginid,
- 'isvideo=' + ((playback.isVideo || canPlayVideo) ? "true" : "false"),
- 'autoplay=' + ((autoplay) ? "true" : "false"),
- 'preload=' + preload,
- 'width=' + width,
- 'startvolume=' + options.startVolume,
- 'timerrate=' + options.timerRate,
- 'flashstreamer=' + options.flashStreamer,
- 'height=' + height,
- 'pseudostreamstart=' + options.pseudoStreamingStartQueryParam];
-
- if (playback.url !== null) {
- if (playback.method == 'flash') {
- initVars.push('file=' + mejs.Utility.encodeUrl(playback.url));
- } else {
- initVars.push('file=' + playback.url);
- }
- }
- if (options.enablePluginDebug) {
- initVars.push('debug=true');
- }
- if (options.enablePluginSmoothing) {
- initVars.push('smoothing=true');
- }
- if (options.enablePseudoStreaming) {
- initVars.push('pseudostreaming=true');
- }
- if (controls) {
- initVars.push('controls=true'); // shows controls in the plugin if desired
- }
- if (options.pluginVars) {
- initVars = initVars.concat(options.pluginVars);
- }
-
- // call from plugin
- window[pluginid + '_init'] = function() {
- switch (pluginMediaElement.pluginType) {
- case 'flash':
- pluginMediaElement.pluginElement = pluginMediaElement.pluginApi = document.getElementById(pluginid);
- break;
- case 'silverlight':
- pluginMediaElement.pluginElement = document.getElementById(pluginMediaElement.id);
- pluginMediaElement.pluginApi = pluginMediaElement.pluginElement.Content.MediaElementJS;
- break;
- }
-
- if (pluginMediaElement.pluginApi != null && pluginMediaElement.success) {
- pluginMediaElement.success(pluginMediaElement, htmlMediaElement);
- }
- };
-
- // event call from plugin
- window[pluginid + '_event'] = function(eventName, values) {
-
- var
- e,
- i,
- bufferedTime;
-
- // fake event object to mimic real HTML media event.
- e = {
- type: eventName,
- target: pluginMediaElement
- };
-
- // attach all values to element and event object
- for (i in values) {
- pluginMediaElement[i] = values[i];
- e[i] = values[i];
- }
-
- // fake the newer W3C buffered TimeRange (loaded and total have been removed)
- bufferedTime = values.bufferedTime || 0;
-
- e.target.buffered = e.buffered = {
- start: function(index) {
- return 0;
- },
- end: function (index) {
- return bufferedTime;
- },
- length: 1
- };
-
- pluginMediaElement.dispatchEvent(e);
- }
-
-
- }
- switch (playback.method) {
- case 'silverlight':
- container.innerHTML =
- '<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" id="' + pluginid + '" name="' + pluginid + '" width="' + width + '" height="' + height + '" class="mejs-shim">' +
- '<param name="initParams" value="' + initVars.join(',') + '" />' +
- '<param name="windowless" value="true" />' +
- '<param name="background" value="black" />' +
- '<param name="minRuntimeVersion" value="3.0.0.0" />' +
- '<param name="autoUpgrade" value="true" />' +
- '<param name="source" value="' + options.pluginPath + options.silverlightName + '" />' +
- '</object>';
- break;
- case 'flash':
- if (mejs.MediaFeatures.isIE) {
- specialIEContainer = document.createElement('div');
- container.appendChild(specialIEContainer);
- specialIEContainer.outerHTML =
- '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" ' +
- 'id="' + pluginid + '" width="' + width + '" height="' + height + '" class="mejs-shim">' +
- '<param name="movie" value="' + options.pluginPath + options.flashName + '?' + (new Date().getTime()) + '" />' +
- '<param name="flashvars" value="' + initVars.join('&') + '" />' +
- '<param name="quality" value="high" />' +
- '<param name="bgcolor" value="#000000" />' +
- '<param name="wmode" value="transparent" />' +
- '<param name="allowScriptAccess" value="' + options.flashScriptAccess + '" />' +
- '<param name="allowFullScreen" value="true" />' +
- '<param name="scale" value="default" />' +
- '</object>';
- } else {
- container.innerHTML =
- '<embed id="' + pluginid + '" name="' + pluginid + '" ' +
- 'play="true" ' +
- 'loop="false" ' +
- 'quality="high" ' +
- 'bgcolor="#000000" ' +
- 'wmode="transparent" ' +
- 'allowScriptAccess="' + options.flashScriptAccess + '" ' +
- 'allowFullScreen="true" ' +
- 'type="application/x-shockwave-flash" pluginspage="//www.macromedia.com/go/getflashplayer" ' +
- 'src="' + options.pluginPath + options.flashName + '" ' +
- 'flashvars="' + initVars.join('&') + '" ' +
- 'width="' + width + '" ' +
- 'height="' + height + '" ' +
- 'scale="default"' +
- 'class="mejs-shim"></embed>';
- }
- break;
-
- case 'youtube':
-
-
- var videoId;
- // youtu.be url from share button
- if (playback.url.lastIndexOf("youtu.be") != -1) {
- videoId = playback.url.substr(playback.url.lastIndexOf('/')+1);
- if (videoId.indexOf('?') != -1) {
- videoId = videoId.substr(0, videoId.indexOf('?'));
- }
- }
- else {
- // https://www.youtube.com/watch?v=
- var videoIdMatch = playback.url.match( /[?&]v=([^&#]+)|&|#|$/ );
- if ( videoIdMatch ) {
- videoId = videoIdMatch[1];
- }
- }
- youtubeSettings = {
- container: container,
- containerId: container.id,
- pluginMediaElement: pluginMediaElement,
- pluginId: pluginid,
- videoId: videoId,
- height: height,
- width: width,
- scheme: playback.scheme,
- variables: options.youtubeIframeVars
- };
-
- // favor iframe version of YouTube
- if (window.postMessage) {
- mejs.YouTubeApi.enqueueIframe(youtubeSettings);
- } else if (mejs.PluginDetector.hasPluginVersion('flash', [10,0,0]) ) {
- mejs.YouTubeApi.createFlash(youtubeSettings, options);
- }
- break;
-
- // DEMO Code. Does NOT work.
- case 'vimeo':
- var player_id = pluginid + "_player";
- pluginMediaElement.vimeoid = playback.url.substr(playback.url.lastIndexOf('/')+1);
-
- container.innerHTML ='<iframe src="' + playback.scheme + 'player.vimeo.com/video/' + pluginMediaElement.vimeoid + '?api=1&portrait=0&byline=0&title=0&player_id=' + player_id + '" width="' + width +'" height="' + height +'" frameborder="0" class="mejs-shim" id="' + player_id + '" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
- if (typeof($f) == 'function') { // froogaloop available
- var player = $f(container.childNodes[0]),
- playerState = -1;
-
- player.addEvent('ready', function() {
-
- player.playVideo = function() {
- player.api( 'play' );
- };
- player.stopVideo = function() {
- player.api( 'unload' );
- };
- player.pauseVideo = function() {
- player.api( 'pause' );
- };
- player.seekTo = function( seconds ) {
- player.api( 'seekTo', seconds );
- };
- player.setVolume = function( volume ) {
- player.api( 'setVolume', volume );
- };
- player.setMuted = function( muted ) {
- if( muted ) {
- player.lastVolume = player.api( 'getVolume' );
- player.api( 'setVolume', 0 );
- } else {
- player.api( 'setVolume', player.lastVolume );
- delete player.lastVolume;
- }
- };
- // parity with YT player
- player.getPlayerState = function() {
- return playerState;
- };
- function createEvent(player, pluginMediaElement, eventName, e) {
- var event = {
- type: eventName,
- target: pluginMediaElement
- };
- if (eventName == 'timeupdate') {
- pluginMediaElement.currentTime = event.currentTime = e.seconds;
- pluginMediaElement.duration = event.duration = e.duration;
- }
- pluginMediaElement.dispatchEvent(event);
- }
- player.addEvent('play', function() {
- playerState = 1;
- createEvent(player, pluginMediaElement, 'play');
- createEvent(player, pluginMediaElement, 'playing');
- });
- player.addEvent('pause', function() {
- playerState = 2;
- createEvent(player, pluginMediaElement, 'pause');
- });
- player.addEvent('finish', function() {
- playerState = 0;
- createEvent(player, pluginMediaElement, 'ended');
- });
- player.addEvent('playProgress', function(e) {
- createEvent(player, pluginMediaElement, 'timeupdate', e);
- });
-
- player.addEvent('seek', function(e) {
- playerState = 3;
- createEvent(player, pluginMediaElement, 'seeked', e);
- });
-
- player.addEvent('loadProgress', function(e) {
- playerState = 3;
- createEvent(player, pluginMediaElement, 'progress', e);
- });
- pluginMediaElement.pluginElement = container;
- pluginMediaElement.pluginApi = player;
- pluginMediaElement.success(pluginMediaElement, pluginMediaElement.pluginElement);
- });
- }
- else {
- console.warn("You need to include froogaloop for vimeo to work");
- }
- break;
- }
- // hide original element
- htmlMediaElement.style.display = 'none';
- // prevent browser from autoplaying when using a plugin
- htmlMediaElement.removeAttribute('autoplay');
-
- return pluginMediaElement;
- },
- updateNative: function(playback, options, autoplay, preload) {
-
- var htmlMediaElement = playback.htmlMediaElement,
- m;
-
-
- // add methods to video object to bring it into parity with Flash Object
- for (m in mejs.HtmlMediaElement) {
- htmlMediaElement[m] = mejs.HtmlMediaElement[m];
- }
- /*
- Chrome now supports preload="none"
- if (mejs.MediaFeatures.isChrome) {
-
- // special case to enforce preload attribute (Chrome doesn't respect this)
- if (preload === 'none' && !autoplay) {
-
- // forces the browser to stop loading (note: fails in IE9)
- htmlMediaElement.src = '';
- htmlMediaElement.load();
- htmlMediaElement.canceledPreload = true;
- htmlMediaElement.addEventListener('play',function() {
- if (htmlMediaElement.canceledPreload) {
- htmlMediaElement.src = playback.url;
- htmlMediaElement.load();
- htmlMediaElement.play();
- htmlMediaElement.canceledPreload = false;
- }
- }, false);
- // for some reason Chrome forgets how to autoplay sometimes.
- } else if (autoplay) {
- htmlMediaElement.load();
- htmlMediaElement.play();
- }
- }
- */
- // fire success code
- options.success(htmlMediaElement, htmlMediaElement);
-
- return htmlMediaElement;
- }
- };
- /*
- - test on IE (object vs. embed)
- - determine when to use iframe (Firefox, Safari, Mobile) vs. Flash (Chrome, IE)
- - fullscreen?
- */
- // YouTube Flash and Iframe API
- mejs.YouTubeApi = {
- isIframeStarted: false,
- isIframeLoaded: false,
- loadIframeApi: function(yt) {
- if (!this.isIframeStarted) {
- var tag = document.createElement('script');
- tag.src = yt.scheme + "www.youtube.com/player_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- this.isIframeStarted = true;
- }
- },
- iframeQueue: [],
- enqueueIframe: function(yt) {
-
- if (this.isLoaded) {
- this.createIframe(yt);
- } else {
- this.loadIframeApi(yt);
- this.iframeQueue.push(yt);
- }
- },
- createIframe: function(settings) {
- var
- pluginMediaElement = settings.pluginMediaElement,
- defaultVars = {controls:0, wmode:'transparent'},
- player = new YT.Player(settings.containerId, {
- height: settings.height,
- width: settings.width,
- videoId: settings.videoId,
- playerVars: mejs.$.extend({}, defaultVars, settings.variables),
- events: {
- 'onReady': function(e) {
-
- // wrapper to match
- player.setVideoSize = function(width, height) {
- player.setSize(width, height);
- };
-
- // hook up iframe object to MEjs
- settings.pluginMediaElement.pluginApi = player;
- settings.pluginMediaElement.pluginElement = document.getElementById(settings.containerId);
-
- // init mejs
- pluginMediaElement.success(pluginMediaElement, pluginMediaElement.pluginElement);
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'canplay');
-
- // create timer
- setInterval(function() {
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'timeupdate');
- }, 250);
- if (typeof pluginMediaElement.attributes.autoplay !== 'undefined') {
- player.playVideo();
- }
- },
- 'onStateChange': function(e) {
-
- mejs.YouTubeApi.handleStateChange(e.data, player, pluginMediaElement);
-
- }
- }
- });
- },
-
- createEvent: function (player, pluginMediaElement, eventName) {
- var event = {
- type: eventName,
- target: pluginMediaElement
- };
- if (player && player.getDuration) {
-
- // time
- pluginMediaElement.currentTime = event.currentTime = player.getCurrentTime();
- pluginMediaElement.duration = event.duration = player.getDuration();
-
- // state
- event.paused = pluginMediaElement.paused;
- event.ended = pluginMediaElement.ended;
-
- // sound
- event.muted = player.isMuted();
- event.volume = player.getVolume() / 100;
-
- // progress
- event.bytesTotal = player.getVideoBytesTotal();
- event.bufferedBytes = player.getVideoBytesLoaded();
-
- // fake the W3C buffered TimeRange
- var bufferedTime = event.bufferedBytes / event.bytesTotal * event.duration;
-
- event.target.buffered = event.buffered = {
- start: function(index) {
- return 0;
- },
- end: function (index) {
- return bufferedTime;
- },
- length: 1
- };
- }
-
- // send event up the chain
- pluginMediaElement.dispatchEvent(event);
- },
-
- iFrameReady: function() {
-
- this.isLoaded = true;
- this.isIframeLoaded = true;
-
- while (this.iframeQueue.length > 0) {
- var settings = this.iframeQueue.pop();
- this.createIframe(settings);
- }
- },
-
- // FLASH!
- flashPlayers: {},
- createFlash: function(settings) {
-
- this.flashPlayers[settings.pluginId] = settings;
-
- /*
- settings.container.innerHTML =
- '<object type="application/x-shockwave-flash" id="' + settings.pluginId + '" data="' + settings.scheme + 'www.youtube.com/apiplayer?enablejsapi=1&playerapiid=' + settings.pluginId + '&version=3&autoplay=0&controls=0&modestbranding=1&loop=0" ' +
- 'width="' + settings.width + '" height="' + settings.height + '" style="visibility: visible; " class="mejs-shim">' +
- '<param name="allowScriptAccess" value="sameDomain">' +
- '<param name="wmode" value="transparent">' +
- '</object>';
- */
- var specialIEContainer,
- youtubeUrl = settings.scheme + 'www.youtube.com/apiplayer?enablejsapi=1&playerapiid=' + settings.pluginId + '&version=3&autoplay=0&controls=0&modestbranding=1&loop=0';
-
- if (mejs.MediaFeatures.isIE) {
-
- specialIEContainer = document.createElement('div');
- settings.container.appendChild(specialIEContainer);
- specialIEContainer.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + settings.scheme + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" ' +
- 'id="' + settings.pluginId + '" width="' + settings.width + '" height="' + settings.height + '" class="mejs-shim">' +
- '<param name="movie" value="' + youtubeUrl + '" />' +
- '<param name="wmode" value="transparent" />' +
- '<param name="allowScriptAccess" value="' + options.flashScriptAccess + '" />' +
- '<param name="allowFullScreen" value="true" />' +
- '</object>';
- } else {
- settings.container.innerHTML =
- '<object type="application/x-shockwave-flash" id="' + settings.pluginId + '" data="' + youtubeUrl + '" ' +
- 'width="' + settings.width + '" height="' + settings.height + '" style="visibility: visible; " class="mejs-shim">' +
- '<param name="allowScriptAccess" value="' + options.flashScriptAccess + '">' +
- '<param name="wmode" value="transparent">' +
- '</object>';
- }
-
- },
-
- flashReady: function(id) {
- var
- settings = this.flashPlayers[id],
- player = document.getElementById(id),
- pluginMediaElement = settings.pluginMediaElement;
-
- // hook up and return to MediaELementPlayer.success
- pluginMediaElement.pluginApi =
- pluginMediaElement.pluginElement = player;
-
- settings.success(pluginMediaElement, pluginMediaElement.pluginElement);
-
- // load the youtube video
- player.cueVideoById(settings.videoId);
-
- var callbackName = settings.containerId + '_callback';
-
- window[callbackName] = function(e) {
- mejs.YouTubeApi.handleStateChange(e, player, pluginMediaElement);
- };
-
- player.addEventListener('onStateChange', callbackName);
-
- setInterval(function() {
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'timeupdate');
- }, 250);
-
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'canplay');
- },
-
- handleStateChange: function(youTubeState, player, pluginMediaElement) {
- switch (youTubeState) {
- case -1: // not started
- pluginMediaElement.paused = true;
- pluginMediaElement.ended = true;
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'loadedmetadata');
- //createYouTubeEvent(player, pluginMediaElement, 'loadeddata');
- break;
- case 0:
- pluginMediaElement.paused = false;
- pluginMediaElement.ended = true;
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'ended');
- break;
- case 1:
- pluginMediaElement.paused = false;
- pluginMediaElement.ended = false;
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'play');
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'playing');
- break;
- case 2:
- pluginMediaElement.paused = true;
- pluginMediaElement.ended = false;
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'pause');
- break;
- case 3: // buffering
- mejs.YouTubeApi.createEvent(player, pluginMediaElement, 'progress');
- break;
- case 5:
- // cued?
- break;
-
- }
-
- }
- }
- // IFRAME
- window.onYouTubePlayerAPIReady = function() {
- mejs.YouTubeApi.iFrameReady();
- };
- // FLASH
- window.onYouTubePlayerReady = function(id) {
- mejs.YouTubeApi.flashReady(id);
- };
- window.mejs = mejs;
- window.MediaElement = mejs.MediaElement;
- /**
- * Localize strings
- *
- * Include translations from JS files and method to pluralize properly strings.
- *
- */
- (function (doc, win, mejs, undefined) {
- var i18n = {
- /**
- * @type {String}
- */
- 'default': 'en',
- /**
- * @type {String[]}
- */
- locale: {
- language: (mejs.i18n && mejs.i18n.locale.language) || '',
- strings: (mejs.i18n && mejs.i18n.locale.strings) || {}
- },
- /**
- * Filters for available languages.
- *
- * This plural forms are grouped in family groups based on
- * https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
- * with some additions and corrections according to the Localization Guide list
- * (http://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html)
- *
- * Arguments are dynamic following the structure:
- * - argument1 : Number to determine form
- * - argument2...argumentN: Possible matches
- *
- * @type {Function[]}
- */
- pluralForms: [
- // 0: Chinese, Japanese, Korean, Persian, Turkish, Thai, Lao, Aymará,
- // Tibetan, Chiga, Dzongkha, Indonesian, Lojban, Georgian, Kazakh, Khmer, Kyrgyz, Malay,
- // Burmese, Yakut, Sundanese, Tatar, Uyghur, Vietnamese, Wolof
- function () {
- return arguments[1];
- },
- // 1: Danish, Dutch, English, Faroese, Frisian, German, Norwegian, Swedish, Estonian, Finnish,
- // Hungarian, Basque, Greek, Hebrew, Italian, Portuguese, Spanish, Catalan, Afrikaans,
- // Angika, Assamese, Asturian, Azerbaijani, Bulgarian, Bengali, Bodo, Aragonese, Dogri,
- // Esperanto, Argentinean Spanish, Fulah, Friulian, Galician, Gujarati, Hausa,
- // Hindi, Chhattisgarhi, Armenian, Interlingua, Greenlandic, Kannada, Kurdish, Letzeburgesch,
- // Maithili, Malayalam, Mongolian, Manipuri, Marathi, Nahuatl, Neapolitan, Norwegian Bokmal,
- // Nepali, Norwegian Nynorsk, Norwegian (old code), Northern Sotho, Oriya, Punjabi, Papiamento,
- // Piemontese, Pashto, Romansh, Kinyarwanda, Santali, Scots, Sindhi, Northern Sami, Sinhala,
- // Somali, Songhay, Albanian, Swahili, Tamil, Telugu, Turkmen, Urdu, Yoruba
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else {
- return args[2];
- }
- },
- // 2: French, Brazilian Portuguese, Acholi, Akan, Amharic, Mapudungun, Breton, Filipino,
- // Gun, Lingala, Mauritian Creole, Malagasy, Maori, Occitan, Tajik, Tigrinya, Uzbek, Walloon
- function () {
- var args = arguments;
- if ([0, 1].indexOf(args[0]) > -1) {
- return args[1];
- } else {
- return args[2];
- }
- },
- // 3: Latvian
- function () {
- var args = arguments;
- if (args[0] % 10 === 1 && args[0] % 100 !== 11) {
- return args[1];
- } else if (args[0] !== 0) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 4: Scottish Gaelic
- function () {
- var args = arguments;
- if (args[0] === 1 || args[0] === 11) {
- return args[1];
- } else if (args[0] === 2 || args[0] === 12) {
- return args[2];
- } else if (args[0] > 2 && args[0] < 20) {
- return args[3];
- } else {
- return args[4];
- }
- },
- // 5: Romanian
- function () {
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] === 0 || (args[0] % 100 > 0 && args[0] % 100 < 20)) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 6: Lithuanian
- function () {
- var args = arguments;
- if (args[0] % 10 === 1 && args[0] % 100 !== 11) {
- return args[1];
- } else if (args[0] % 10 >= 2 && (args[0] % 100 < 10 || args[0] % 100 >= 20)) {
- return args[2];
- } else {
- return [3];
- }
- },
- // 7: Belarusian, Bosnian, Croatian, Serbian, Russian, Ukrainian
- function () {
- var args = arguments;
- if (args[0] % 10 === 1 && args[0] % 100 !== 11) {
- return args[1];
- } else if (args[0] % 10 >= 2 && args[0] % 10 <= 4 && (args[0] % 100 < 10 || args[0] % 100 >= 20)) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 8: Slovak, Czech
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] >= 2 && args[0] <= 4) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 9: Polish
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] % 10 >= 2 && args[0] % 10 <= 4 && (args[0] % 100 < 10 || args[0] % 100 >= 20)) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 10: Slovenian
- function () {
- var args = arguments;
- if (args[0] % 100 === 1) {
- return args[2];
- } else if (args[0] % 100 === 2) {
- return args[3];
- } else if (args[0] % 100 === 3 || args[0] % 100 === 4) {
- return args[4];
- } else {
- return args[1];
- }
- },
- // 11: Irish Gaelic
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] === 2) {
- return args[2];
- } else if (args[0] > 2 && args[0] < 7) {
- return args[3];
- } else if (args[0] > 6 && args[0] < 11) {
- return args[4];
- } else {
- return args[5];
- }
- },
- // 12: Arabic
- function () {
- var args = arguments;
- if (args[0] === 0) {
- return args[1];
- } else if (args[0] === 1) {
- return args[2];
- } else if (args[0] === 2) {
- return args[3];
- } else if (args[0] % 100 >= 3 && args[0] % 100 <= 10) {
- return args[4];
- } else if (args[0] % 100 >= 11) {
- return args[5];
- } else {
- return args[6];
- }
- },
- // 13: Maltese
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] === 0 || (args[0] % 100 > 1 && args[0] % 100 < 11)) {
- return args[2];
- } else if (args[0] % 100 > 10 && args[0] % 100 < 20) {
- return args[3];
- } else {
- return args[4];
- }
- },
- // 14: Macedonian
- function () {
- var args = arguments;
- if (args[0] % 10 === 1) {
- return args[1];
- } else if (args[0] % 10 === 2) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 15: Icelandic
- function () {
- var args = arguments;
- if (args[0] !== 11 && args[0] % 10 === 1) {
- return args[1];
- } else {
- return args[2];
- }
- },
- // New additions
- // 16: Kashubian
- // Note: in https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
- // Breton is listed as #16 but in the Localization Guide it belongs to the group 2
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] % 10 >= 2 && args[0] % 10 <= 4 && (args[0] % 100 < 10 || args[0] % 100 >= 20)) {
- return args[2];
- } else {
- return args[3];
- }
- },
- // 17: Welsh
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] === 2) {
- return args[2];
- } else if (args[0] !== 8 && args[0] !== 11) {
- return args[3];
- } else {
- return args[4];
- }
- },
- // 18: Javanese
- function () {
- var args = arguments;
- if (args[0] === 0) {
- return args[1];
- } else {
- return args[2];
- }
- },
- // 19: Cornish
- function () {
- var args = arguments;
- if (args[0] === 1) {
- return args[1];
- } else if (args[0] === 2) {
- return args[2];
- } else if (args[0] === 3) {
- return args[3];
- } else {
- return args[4];
- }
- },
- // 20: Mandinka
- function () {
- var args = arguments;
- if (args[0] === 0) {
- return args[1];
- } else if (args[0] === 1) {
- return args[2];
- } else {
- return args[3];
- }
- }
- ],
- /**
- * Get specified language
- *
- */
- getLanguage: function () {
- var language = i18n.locale.language || i18n['default'];
- return /^(x\-)?[a-z]{2,}(\-\w{2,})?(\-\w{2,})?$/.exec(language) ? language : i18n['default'];
- },
- /**
- * Translate a string to a specified language, including optionally a number to pluralize translation
- *
- * @param {String} message
- * @param {Number} pluralParam
- * @return {String}
- */
- t: function (message, pluralParam) {
- if (typeof message === 'string' && message.length) {
- var
- language = i18n.getLanguage(),
- str,
- pluralForm,
- /**
- * Modify string using algorithm to detect plural forms.
- *
- * @private
- * @see http://stackoverflow.com/questions/1353408/messageformat-in-javascript-parameters-in-localized-ui-strings
- * @param {String|String[]} input - String or array of strings to pick the plural form
- * @param {Number} number - Number to determine the proper plural form
- * @param {Number} form - Number of language family to apply plural form
- * @return {String}
- */
- plural = function (input, number, form) {
- if (typeof input !== 'object' || typeof number !== 'number' || typeof form !== 'number') {
- return input;
- }
- if (typeof input === 'string') {
- return input;
- }
- // Perform plural form or return original text
- return i18n.pluralForms[form].apply(null, [number].concat(input));
- },
- /**
- *
- * @param {String} input
- * @return {String}
- */
- escapeHTML = function (input) {
- var map = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '"'
- };
- return input.replace(/[&<>"]/g, function(c) {
- return map[c];
- });
- }
- ;
- // Fetch the localized version of the string
- if (i18n.locale.strings && i18n.locale.strings[language]) {
- str = i18n.locale.strings[language][message];
- if (typeof pluralParam === 'number') {
- pluralForm = i18n.locale.strings[language]['mejs.plural-form'];
- str = plural.apply(null, [str, pluralParam, pluralForm]);
- }
- }
- // Fallback to default language if requested uid is not translated
- if (!str && i18n.locale.strings && i18n.locale.strings[i18n['default']]) {
- str = i18n.locale.strings[i18n['default']][message];
- if (typeof pluralParam === 'number') {
- pluralForm = i18n.locale.strings[i18n['default']]['mejs.plural-form'];
- str = plural.apply(null, [str, pluralParam, pluralForm]);
- }
- }
- // As a last resort, use the requested uid, to mimic original behavior of i18n utils (in which uid was the english text)
- str = str || message;
- // Replace token
- if (typeof pluralParam === 'number') {
- str = str.replace('%1', pluralParam);
- }
- return escapeHTML(str);
- }
- return message;
- }
- };
- // i18n fixes for compatibility with WordPress
- if (typeof mejsL10n !== 'undefined') {
- i18n.locale.language = mejsL10n.language;
- }
- // Register variable
- mejs.i18n = i18n;
- }(document, window, mejs));
- // i18n fixes for compatibility with WordPress
- ;(function (mejs, undefined) {
- "use strict";
- if (typeof mejsL10n !== 'undefined') {
- mejs[mejsL10n.language] = mejsL10n.strings;
- }
- }(mejs.i18n.locale.strings));
- /*!
- * This is a i18n.locale language object.
- *
- * English; This can serve as a template for other languages to translate
- *
- * @author
- * TBD
- * Sascha Greuel (Twitter: @SoftCreatR)
- *
- * @see
- * me-i18n.js
- *
- * @params
- * - exports - CommonJS, window ..
- */
- (function (exports) {
- "use strict";
- if (exports.en === undefined) {
- exports.en = {
- "mejs.plural-form": 1,
- // me-shim
- "mejs.download-file": "Download File",
- // mep-feature-contextmenu
- "mejs.fullscreen-off": "Turn off Fullscreen",
- "mejs.fullscreen-on": "Go Fullscreen",
- "mejs.download-video": "Download Video",
- // mep-feature-fullscreen
- "mejs.fullscreen": "Fullscreen",
- // mep-feature-jumpforward
- "mejs.time-jump-forward": ["Jump forward 1 second", "Jump forward %1 seconds"],
- // mep-feature-playpause
- "mejs.play": "Play",
- "mejs.pause": "Pause",
- // mep-feature-postroll
- "mejs.close": "Close",
- // mep-feature-progress
- "mejs.time-slider": "Time Slider",
- "mejs.time-help-text": "Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.",
- // mep-feature-skipback
- "mejs.time-skip-back": ["Skip back 1 second", "Skip back %1 seconds"],
- // mep-feature-tracks
- "mejs.captions-subtitles": "Captions/Subtitles",
- "mejs.none": "None",
- // mep-feature-volume
- "mejs.mute-toggle": "Mute Toggle",
- "mejs.volume-help-text": "Use Up/Down Arrow keys to increase or decrease volume.",
- "mejs.unmute": "Unmute",
- "mejs.mute": "Mute",
- "mejs.volume-slider": "Volume Slider",
- // mep-player
- "mejs.video-player": "Video Player",
- "mejs.audio-player": "Audio Player",
- // mep-feature-ads
- "mejs.ad-skip": "Skip ad",
- "mejs.ad-skip-info": ["Skip in 1 second", "Skip in %1 seconds"],
- // mep-feature-sourcechooser
- "mejs.source-chooser": "Source Chooser"
- };
- }
- }(mejs.i18n.locale.strings));
- /*!
- *
- * MediaElementPlayer
- * http://mediaelementjs.com/
- *
- * Creates a controller bar for HTML5 <video> add <audio> tags
- * using jQuery and MediaElement.js (HTML5 Flash/Silverlight wrapper)
- *
- * Copyright 2010-2013, John Dyer (http://j.hn/)
- * License: MIT
- *
- */
- if (typeof jQuery != 'undefined') {
- mejs.$ = jQuery;
- } else if (typeof Zepto != 'undefined') {
- mejs.$ = Zepto;
- // define `outerWidth` method which has not been realized in Zepto
- Zepto.fn.outerWidth = function(includeMargin) {
- var width = $(this).width();
- if (includeMargin) {
- width += parseInt($(this).css('margin-right'), 10);
- width += parseInt($(this).css('margin-left'), 10);
- }
- return width
- }
- } else if (typeof ender != 'undefined') {
- mejs.$ = ender;
- }
- (function ($) {
- // default player values
- mejs.MepDefaults = {
- // url to poster (to fix iOS 3.x)
- poster: '',
- // When the video is ended, we can show the poster.
- showPosterWhenEnded: false,
- // default if the <video width> is not specified
- defaultVideoWidth: 480,
- // default if the <video height> is not specified
- defaultVideoHeight: 270,
- // if set, overrides <video width>
- videoWidth: -1,
- // if set, overrides <video height>
- videoHeight: -1,
- // default if the user doesn't specify
- defaultAudioWidth: 400,
- // default if the user doesn't specify
- defaultAudioHeight: 30,
- // default amount to move back when back key is pressed
- defaultSeekBackwardInterval: function(media) {
- return (media.duration * 0.05);
- },
- // default amount to move forward when forward key is pressed
- defaultSeekForwardInterval: function(media) {
- return (media.duration * 0.05);
- },
- // set dimensions via JS instead of CSS
- setDimensions: true,
- // width of audio player
- audioWidth: -1,
- // height of audio player
- audioHeight: -1,
- // initial volume when the player starts (overrided by user cookie)
- startVolume: 0.8,
- // useful for <audio> player loops
- loop: false,
- // rewind to beginning when media ends
- autoRewind: true,
- // resize to media dimensions
- enableAutosize: true,
- /*
- * Time format to use. Default: 'mm:ss'
- * Supported units:
- * h: hour
- * m: minute
- * s: second
- * f: frame count
- * When using 'hh', 'mm', 'ss' or 'ff' we always display 2 digits.
- * If you use 'h', 'm', 's' or 'f' we display 1 digit if possible.
- *
- * Example to display 75 seconds:
- * Format 'mm:ss': 01:15
- * Format 'm:ss': 1:15
- * Format 'm:s': 1:15
- */
- timeFormat: '',
- // forces the hour marker (##:00:00)
- alwaysShowHours: false,
- // show framecount in timecode (##:00:00:00)
- showTimecodeFrameCount: false,
- // used when showTimecodeFrameCount is set to true
- framesPerSecond: 25,
- // automatically calculate the width of the progress bar based on the sizes of other elements
- autosizeProgress : true,
- // Hide controls when playing and mouse is not over the video
- alwaysShowControls: false,
- // Display the video control
- hideVideoControlsOnLoad: false,
- // Enable click video element to toggle play/pause
- clickToPlayPause: true,
- // Time in ms to hide controls
- controlsTimeoutDefault: 1500,
- // Time in ms to trigger the timer when mouse moves
- controlsTimeoutMouseEnter: 2500,
- // Time in ms to trigger the timer when mouse leaves
- controlsTimeoutMouseLeave: 1000,
- // force iPad's native controls
- iPadUseNativeControls: false,
- // force iPhone's native controls
- iPhoneUseNativeControls: false,
- // force Android's native controls
- AndroidUseNativeControls: false,
- // features to show
- features: ['playpause','current','progress','duration','tracks','volume','fullscreen'],
- // only for dynamic
- isVideo: true,
- // stretching modes (auto, fill, responsive, none)
- stretching: 'auto',
- // turns keyboard support on and off for this instance
- enableKeyboard: true,
- // when this player starts, it will pause other players
- pauseOtherPlayers: true,
- // array of keyboard actions such as play pause
- keyActions: [
- {
- keys: [
- 32, // SPACE
- 179 // GOOGLE play/pause button
- ],
- action: function(player, media, key, event) {
- if (!mejs.MediaFeatures.isFirefox) {
- if (media.paused || media.ended) {
- media.play();
- } else {
- media.pause();
- }
- }
- }
- },
- {
- keys: [38], // UP
- action: function(player, media, key, event) {
- player.container.find('.mejs-volume-slider').css('display','block');
- if (player.isVideo) {
- player.showControls();
- player.startControlsTimer();
- }
- var newVolume = Math.min(media.volume + 0.1, 1);
- media.setVolume(newVolume);
- }
- },
- {
- keys: [40], // DOWN
- action: function(player, media, key, event) {
- player.container.find('.mejs-volume-slider').css('display','block');
- if (player.isVideo) {
- player.showControls();
- player.startControlsTimer();
- }
- var newVolume = Math.max(media.volume - 0.1, 0);
- media.setVolume(newVolume);
- }
- },
- {
- keys: [
- 37, // LEFT
- 227 // Google TV rewind
- ],
- action: function(player, media, key, event) {
- if (!isNaN(media.duration) && media.duration > 0) {
- if (player.isVideo) {
- player.showControls();
- player.startControlsTimer();
- }
- // 5%
- var newTime = Math.max(media.currentTime - player.options.defaultSeekBackwardInterval(media), 0);
- media.setCurrentTime(newTime);
- }
- }
- },
- {
- keys: [
- 39, // RIGHT
- 228 // Google TV forward
- ],
- action: function(player, media, key, event) {
- if (!isNaN(media.duration) && media.duration > 0) {
- if (player.isVideo) {
- player.showControls();
- player.startControlsTimer();
- }
- // 5%
- var newTime = Math.min(media.currentTime + player.options.defaultSeekForwardInterval(media), media.duration);
- media.setCurrentTime(newTime);
- }
- }
- },
- {
- keys: [70], // F
- action: function(player, media, key, event) {
- if (typeof player.enterFullScreen != 'undefined') {
- if (player.isFullScreen) {
- player.exitFullScreen();
- } else {
- player.enterFullScreen();
- }
- }
- }
- },
- {
- keys: [77], // M
- action: function(player, media, key, event) {
- player.container.find('.mejs-volume-slider').css('display','block');
- if (player.isVideo) {
- player.showControls();
- player.startControlsTimer();
- }
- if (player.media.muted) {
- player.setMuted(false);
- } else {
- player.setMuted(true);
- }
- }
- }
- ]
- };
- mejs.mepIndex = 0;
- mejs.players = {};
- // wraps a MediaElement object in player controls
- mejs.MediaElementPlayer = function(node, o) {
- // enforce object, even without "new" (via John Resig)
- if ( !(this instanceof mejs.MediaElementPlayer) ) {
- return new mejs.MediaElementPlayer(node, o);
- }
- var t = this;
- // these will be reset after the MediaElement.success fires
- t.$media = t.$node = $(node);
- t.node = t.media = t.$media[0];
- if(!t.node) {
- return;
- }
- // check for existing player
- if (typeof t.node.player != 'undefined') {
- return t.node.player;
- }
- // try to get options from data-mejsoptions
- if (typeof o == 'undefined') {
- o = t.$node.data('mejsoptions');
- }
- // extend default options
- t.options = $.extend({},mejs.MepDefaults,o);
- if (!t.options.timeFormat) {
- // Generate the time format according to options
- t.options.timeFormat = 'mm:ss';
- if (t.options.alwaysShowHours) {
- t.options.timeFormat = 'hh:mm:ss';
- }
- if (t.options.showTimecodeFrameCount) {
- t.options.timeFormat += ':ff';
- }
- }
- mejs.Utility.calculateTimeFormat(0, t.options, t.options.framesPerSecond || 25);
- // unique ID
- t.id = 'mep_' + mejs.mepIndex++;
- // add to player array (for focus events)
- mejs.players[t.id] = t;
- // start up
- t.init();
- return t;
- };
- // actual player
- mejs.MediaElementPlayer.prototype = {
- hasFocus: false,
- controlsAreVisible: true,
- init: function() {
- var
- t = this,
- mf = mejs.MediaFeatures,
- // options for MediaElement (shim)
- meOptions = $.extend(true, {}, t.options, {
- success: function(media, domNode) { t.meReady(media, domNode); },
- error: function(e) { t.handleError(e);}
- }),
- tagName = t.media.tagName.toLowerCase();
- t.isDynamic = (tagName !== 'audio' && tagName !== 'video');
- if (t.isDynamic) {
- // get video from src or href?
- t.isVideo = t.options.isVideo;
- } else {
- t.isVideo = (tagName !== 'audio' && t.options.isVideo);
- }
- // use native controls in iPad, iPhone, and Android
- if ((mf.isiPad && t.options.iPadUseNativeControls) || (mf.isiPhone && t.options.iPhoneUseNativeControls)) {
- // add controls and stop
- t.$media.attr('controls', 'controls');
- // attempt to fix iOS 3 bug
- //t.$media.removeAttr('poster');
- // no Issue found on iOS3 -ttroxell
- // override Apple's autoplay override for iPads
- if (mf.isiPad && t.media.getAttribute('autoplay') !== null) {
- t.play();
- }
- } else if (mf.isAndroid && t.options.AndroidUseNativeControls) {
- // leave default player
- } else if (t.isVideo || (!t.isVideo && t.options.features.length)) {
- // DESKTOP: use MediaElementPlayer controls
- // remove native controls
- t.$media.removeAttr('controls');
- var videoPlayerTitle = t.isVideo ?
- mejs.i18n.t('mejs.video-player') : mejs.i18n.t('mejs.audio-player');
- // insert description for screen readers
- $('<span class="mejs-offscreen">' + videoPlayerTitle + '</span>').insertBefore(t.$media);
- // build container
- t.container =
- $('<div id="' + t.id + '" class="mejs-container ' + (mejs.MediaFeatures.svgAsImg ? 'svg' : 'no-svg') +
- '" tabindex="0" role="application" aria-label="' + videoPlayerTitle + '">'+
- '<div class="mejs-inner">'+
- '<div class="mejs-mediaelement"></div>'+
- '<div class="mejs-layers"></div>'+
- '<div class="mejs-controls"></div>'+
- '<div class="mejs-clear"></div>'+
- '</div>' +
- '</div>')
- .addClass(t.$media[0].className)
- .insertBefore(t.$media)
- .focus(function ( e ) {
- if( !t.controlsAreVisible && !t.hasFocus && t.controlsEnabled) {
- t.showControls(true);
- // In versions older than IE11, the focus causes the playbar to be displayed
- // if user clicks on the Play/Pause button in the control bar once it attempts
- // to hide it
- if (!t.hasMsNativeFullScreen) {
- // If e.relatedTarget appears before container, send focus to play button,
- // else send focus to last control button.
- var btnSelector = '.mejs-playpause-button > button';
- if (mejs.Utility.isNodeAfter(e.relatedTarget, t.container[0])) {
- btnSelector = '.mejs-controls .mejs-button:last-child > button';
- }
- var button = t.container.find(btnSelector);
- button.focus();
- }
- }
- });
- // When no elements in controls, hide bar completely
- if (!t.options.features.length) {
- t.container.css('background', 'transparent').find('.mejs-controls').hide();
- }
-
- if (t.isVideo && t.options.stretching === 'fill' && !t.container.parent('mejs-fill-container').length) {
- // outer container
- t.outerContainer = t.$media.parent();
- t.container.wrap('<div class="mejs-fill-container"/>');
- }
- // add classes for user and content
- t.container.addClass(
- (mf.isAndroid ? 'mejs-android ' : '') +
- (mf.isiOS ? 'mejs-ios ' : '') +
- (mf.isiPad ? 'mejs-ipad ' : '') +
- (mf.isiPhone ? 'mejs-iphone ' : '') +
- (t.isVideo ? 'mejs-video ' : 'mejs-audio ')
- );
- // move the <video/video> tag into the right spot
- t.container.find('.mejs-mediaelement').append(t.$media);
- // needs to be assigned here, after iOS remap
- t.node.player = t;
- // find parts
- t.controls = t.container.find('.mejs-controls');
- t.layers = t.container.find('.mejs-layers');
- // determine the size
- /* size priority:
- (1) videoWidth (forced),
- (2) style="width;height;"
- (3) width attribute,
- (4) defaultVideoWidth (for unspecified cases)
- */
- var tagType = (t.isVideo ? 'video' : 'audio'),
- capsTagName = tagType.substring(0,1).toUpperCase() + tagType.substring(1);
- if (t.options[tagType + 'Width'] > 0 || t.options[tagType + 'Width'].toString().indexOf('%') > -1) {
- t.width = t.options[tagType + 'Width'];
- } else if (t.media.style.width !== '' && t.media.style.width !== null) {
- t.width = t.media.style.width;
- } else if (t.media.getAttribute('width') !== null) {
- t.width = t.$media.attr('width');
- } else {
- t.width = t.options['default' + capsTagName + 'Width'];
- }
- if (t.options[tagType + 'Height'] > 0 || t.options[tagType + 'Height'].toString().indexOf('%') > -1) {
- t.height = t.options[tagType + 'Height'];
- } else if (t.media.style.height !== '' && t.media.style.height !== null) {
- t.height = t.media.style.height;
- } else if (t.$media[0].getAttribute('height') !== null) {
- t.height = t.$media.attr('height');
- } else {
- t.height = t.options['default' + capsTagName + 'Height'];
- }
- // set the size, while we wait for the plugins to load below
- t.setPlayerSize(t.width, t.height);
- // create MediaElementShim
- meOptions.pluginWidth = t.width;
- meOptions.pluginHeight = t.height;
- }
- // Hide media completely for audio that doesn't have any features
- else if (!t.isVideo && !t.options.features.length) {
- t.$media.hide();
- }
- // create MediaElement shim
- mejs.MediaElement(t.$media[0], meOptions);
- if (typeof(t.container) !== 'undefined' && t.options.features.length && t.controlsAreVisible) {
- // controls are shown when loaded
- t.container.trigger('controlsshown');
- }
- },
- showControls: function(doAnimation) {
- var t = this;
- doAnimation = typeof doAnimation == 'undefined' || doAnimation;
- if (t.controlsAreVisible)
- return;
- if (doAnimation) {
- t.controls
- .removeClass('mejs-offscreen')
- .stop(true, true).fadeIn(200, function() {
- t.controlsAreVisible = true;
- t.container.trigger('controlsshown');
- });
- // any additional controls people might add and want to hide
- t.container.find('.mejs-control')
- .removeClass('mejs-offscreen')
- .stop(true, true).fadeIn(200, function() {t.controlsAreVisible = true;});
- } else {
- t.controls
- .removeClass('mejs-offscreen')
- .css('display','block');
- // any additional controls people might add and want to hide
- t.container.find('.mejs-control')
- .removeClass('mejs-offscreen')
- .css('display','block');
- t.controlsAreVisible = true;
- t.container.trigger('controlsshown');
- }
- t.setControlsSize();
- },
- hideControls: function(doAnimation) {
- var t = this;
- doAnimation = typeof doAnimation == 'undefined' || doAnimation;
- if (!t.controlsAreVisible || t.options.alwaysShowControls || t.keyboardAction || t.media.paused || t.media.ended)
- return;
- if (doAnimation) {
- // fade out main controls
- t.controls.stop(true, true).fadeOut(200, function() {
- $(this)
- .addClass('mejs-offscreen')
- .css('display','block');
- t.controlsAreVisible = false;
- t.container.trigger('controlshidden');
- });
- // any additional controls people might add and want to hide
- t.container.find('.mejs-control').stop(true, true).fadeOut(200, function() {
- $(this)
- .addClass('mejs-offscreen')
- .css('display','block');
- });
- } else {
- // hide main controls
- t.controls
- .addClass('mejs-offscreen')
- .css('display','block');
- // hide others
- t.container.find('.mejs-control')
- .addClass('mejs-offscreen')
- .css('display','block');
- t.controlsAreVisible = false;
- t.container.trigger('controlshidden');
- }
- },
- controlsTimer: null,
- startControlsTimer: function(timeout) {
- var t = this;
- timeout = typeof timeout != 'undefined' ? timeout : t.options.controlsTimeoutDefault;
- t.killControlsTimer('start');
- t.controlsTimer = setTimeout(function() {
- //
- t.hideControls();
- t.killControlsTimer('hide');
- }, timeout);
- },
- killControlsTimer: function(src) {
- var t = this;
- if (t.controlsTimer !== null) {
- clearTimeout(t.controlsTimer);
- delete t.controlsTimer;
- t.controlsTimer = null;
- }
- },
- controlsEnabled: true,
- disableControls: function() {
- var t= this;
- t.killControlsTimer();
- t.hideControls(false);
- this.controlsEnabled = false;
- },
- enableControls: function() {
- var t= this;
- t.showControls(false);
- t.controlsEnabled = true;
- },
- // Sets up all controls and events
- meReady: function(media, domNode) {
-
- var
- t = this,
- mf = mejs.MediaFeatures,
- autoplayAttr = domNode.getAttribute('autoplay'),
- autoplay = !(typeof autoplayAttr == 'undefined' || autoplayAttr === null || autoplayAttr === 'false'),
- featureIndex,
- feature;
- // make sure it can't create itself again if a plugin reloads
- if (t.created) {
- return;
- } else {
- t.created = true;
- }
- t.media = media;
- t.domNode = domNode;
- if (!(mf.isAndroid && t.options.AndroidUseNativeControls) && !(mf.isiPad && t.options.iPadUseNativeControls) && !(mf.isiPhone && t.options.iPhoneUseNativeControls)) {
- // In the event that no features are specified for audio,
- // create only MediaElement instance rather than
- // doing all the work to create a full player
- if (!t.isVideo && !t.options.features.length) {
- // force autoplay for HTML5
- if (autoplay && media.pluginType == 'native') {
- t.play();
- }
- if (t.options.success) {
- if (typeof t.options.success == 'string') {
- window[t.options.success](t.media, t.domNode, t);
- } else {
- t.options.success(t.media, t.domNode, t);
- }
- }
- return;
- }
- // two built in features
- t.buildposter(t, t.controls, t.layers, t.media);
- t.buildkeyboard(t, t.controls, t.layers, t.media);
- t.buildoverlays(t, t.controls, t.layers, t.media);
- // grab for use by features
- t.findTracks();
- // add user-defined features/controls
- for (featureIndex in t.options.features) {
- feature = t.options.features[featureIndex];
- if (t['build' + feature]) {
- try {
- t['build' + feature](t, t.controls, t.layers, t.media);
- } catch (e) {
- // TODO: report control error
- //throw e;
-
-
- }
- }
- }
- t.container.trigger('controlsready');
- // reset all layers and controls
- t.setPlayerSize(t.width, t.height);
- t.setControlsSize();
- // controls fade
- if (t.isVideo) {
- if (mejs.MediaFeatures.hasTouch && !t.options.alwaysShowControls) {
- // for touch devices (iOS, Android)
- // show/hide without animation on touch
- t.$media.bind('touchstart', function() {
- // toggle controls
- if (t.controlsAreVisible) {
- t.hideControls(false);
- } else {
- if (t.controlsEnabled) {
- t.showControls(false);
- }
- }
- });
- } else {
- // create callback here since it needs access to current
- // MediaElement object
- t.clickToPlayPauseCallback = function() {
- //
- if (t.options.clickToPlayPause) {
- if (t.media.paused) {
- t.play();
- } else {
- t.pause();
- }
- var button = t.$media.closest('.mejs-container').find('.mejs-overlay-button'),
- pressed = button.attr('aria-pressed');
- button.attr('aria-pressed', !pressed);
- }
- };
- // click to play/pause
- t.media.addEventListener('click', t.clickToPlayPauseCallback, false);
- // show/hide controls
- t.container
- .bind('mouseenter', function () {
- if (t.controlsEnabled) {
- if (!t.options.alwaysShowControls ) {
- t.killControlsTimer('enter');
- t.showControls();
- t.startControlsTimer(t.options.controlsTimeoutMouseEnter);
- }
- }
- })
- .bind('mousemove', function() {
- if (t.controlsEnabled) {
- if (!t.controlsAreVisible) {
- t.showControls();
- }
- if (!t.options.alwaysShowControls) {
- t.startControlsTimer(t.options.controlsTimeoutMouseEnter);
- }
- }
- })
- .bind('mouseleave', function () {
- if (t.controlsEnabled) {
- if (!t.media.paused && !t.options.alwaysShowControls) {
- t.startControlsTimer(t.options.controlsTimeoutMouseLeave);
- }
- }
- });
- }
- if(t.options.hideVideoControlsOnLoad) {
- t.hideControls(false);
- }
- // check for autoplay
- if (autoplay && !t.options.alwaysShowControls) {
- t.hideControls();
- }
- // resizer
- if (t.options.enableAutosize) {
- t.media.addEventListener('loadedmetadata', function(e) {
- // if the <video height> was not set and the options.videoHeight was not set
- // then resize to the real dimensions
- if (t.options.videoHeight <= 0 && t.domNode.getAttribute('height') === null && !isNaN(e.target.videoHeight)) {
- t.setPlayerSize(e.target.videoWidth, e.target.videoHeight);
- t.setControlsSize();
- t.media.setVideoSize(e.target.videoWidth, e.target.videoHeight);
- }
- }, false);
- }
- }
- // EVENTS
- // FOCUS: when a video starts playing, it takes focus from other players (possibly pausing them)
- t.media.addEventListener('play', function() {
- var playerIndex;
- // go through all other players
- for (playerIndex in mejs.players) {
- var p = mejs.players[playerIndex];
- if (p.id != t.id && t.options.pauseOtherPlayers && !p.paused && !p.ended) {
- p.pause();
- }
- p.hasFocus = false;
- }
- t.hasFocus = true;
- },false);
- // ended for all
- t.media.addEventListener('ended', function (e) {
- if(t.options.autoRewind) {
- try{
- t.media.setCurrentTime(0);
- // Fixing an Android stock browser bug, where "seeked" isn't fired correctly after ending the video and jumping to the beginning
- window.setTimeout(function(){
- $(t.container).find('.mejs-overlay-loading').parent().hide();
- }, 20);
- } catch (exp) {
- }
- }
- if (t.media.pluginType === 'youtube') {
- t.media.stop();
- } else {
- t.media.pause();
- }
- if (t.setProgressRail) {
- t.setProgressRail();
- }
- if (t.setCurrentRail) {
- t.setCurrentRail();
- }
- if (t.options.loop) {
- t.play();
- } else if (!t.options.alwaysShowControls && t.controlsEnabled) {
- t.showControls();
- }
- }, false);
- // resize on the first play
- t.media.addEventListener('loadedmetadata', function() {
- mejs.Utility.calculateTimeFormat(t.duration, t.options, t.options.framesPerSecond || 25);
- if (t.updateDuration) {
- t.updateDuration();
- }
- if (t.updateCurrent) {
- t.updateCurrent();
- }
- if (!t.isFullScreen) {
- t.setPlayerSize(t.width, t.height);
- t.setControlsSize();
- }
- }, false);
- // Only change the time format when necessary
- var duration = null;
- t.media.addEventListener('timeupdate',function() {
- if (duration !== this.duration) {
- duration = this.duration;
- mejs.Utility.calculateTimeFormat(duration, t.options, t.options.framesPerSecond || 25);
-
- // make sure to fill in and resize the controls (e.g., 00:00 => 01:13:15
- if (t.updateDuration) {
- t.updateDuration();
- }
- if (t.updateCurrent) {
- t.updateCurrent();
- }
- t.setControlsSize();
-
- }
- }, false);
- t.container.focusout(function (e) {
- if( e.relatedTarget ) { //FF is working on supporting focusout https://bugzilla.mozilla.org/show_bug.cgi?id=687787
- var $target = $(e.relatedTarget);
- if (t.keyboardAction && $target.parents('.mejs-container').length === 0) {
- t.keyboardAction = false;
- if (t.isVideo && !t.options.alwaysShowControls) {
- t.hideControls(true);
- }
- }
- }
- });
- // webkit has trouble doing this without a delay
- setTimeout(function () {
- t.setPlayerSize(t.width, t.height);
- t.setControlsSize();
- }, 50);
- // adjust controls whenever window sizes (used to be in fullscreen only)
- t.globalBind('resize', function() {
- // don't resize for fullscreen mode
- if ( !(t.isFullScreen || (mejs.MediaFeatures.hasTrueNativeFullScreen && document.webkitIsFullScreen)) ) {
- t.setPlayerSize(t.width, t.height);
- }
- // always adjust controls
- t.setControlsSize();
- });
- // This is a work-around for a bug in the YouTube iFrame player, which means
- // we can't use the play() API for the initial playback on iOS or Android;
- // user has to start playback directly by tapping on the iFrame.
- if (t.media.pluginType == 'youtube' && ( mf.isiOS || mf.isAndroid ) ) {
- t.container.find('.mejs-overlay-play').hide();
- t.container.find('.mejs-poster').hide();
- }
- }
- // force autoplay for HTML5
- if (autoplay && media.pluginType == 'native') {
- t.play();
- }
- if (t.options.success) {
- if (typeof t.options.success == 'string') {
- window[t.options.success](t.media, t.domNode, t);
- } else {
- t.options.success(t.media, t.domNode, t);
- }
- }
- },
- handleError: function(e) {
- var t = this;
- if (t.controls) {
- t.controls.hide();
- }
- // Tell user that the file cannot be played
- if (t.options.error) {
- t.options.error(e);
- }
- },
- setPlayerSize: function(width,height) {
- var t = this;
- if( !t.options.setDimensions ) {
- return false;
- }
- if (typeof width != 'undefined') {
- t.width = width;
- }
- if (typeof height != 'undefined') {
- t.height = height;
- }
-
- // check stretching modes
- switch (t.options.stretching) {
- case 'fill':
- // The 'fill' effect only makes sense on video; for audio we will set the dimensions
- if (t.isVideo) {
- this.setFillMode();
- } else {
- this.setDimensions(t.width, t.height);
- }
- break;
- case 'responsive':
- this.setResponsiveMode();
- break;
- case 'none':
- this.setDimensions(t.width, t.height);
- break;
- // This is the 'auto' mode
- default:
- if (this.hasFluidMode() === true) {
- this.setResponsiveMode();
- } else {
- this.setDimensions(t.width, t.height);
- }
- break;
- }
- },
-
- hasFluidMode: function() {
- var t = this;
-
- // detect 100% mode - use currentStyle for IE since css() doesn't return percentages
- return (t.height.toString().indexOf('%') > 0 || (t.$node.css('max-width') !== 'none' && t.$node.css('max-width') !== 't.width') || (t.$node[0].currentStyle && t.$node[0].currentStyle.maxWidth === '100%'));
- },
-
- setResponsiveMode: function() {
- var t = this;
-
- // do we have the native dimensions yet?
- var nativeWidth = (function() {
- if (t.isVideo) {
- if (t.media.videoWidth && t.media.videoWidth > 0) {
- return t.media.videoWidth;
- } else if (t.media.getAttribute('width') !== null) {
- return t.media.getAttribute('width');
- } else {
- return t.options.defaultVideoWidth;
- }
- } else {
- return t.options.defaultAudioWidth;
- }
- })();
-
- var nativeHeight = (function() {
- if (t.isVideo) {
- if (t.media.videoHeight && t.media.videoHeight > 0) {
- return t.media.videoHeight;
- } else if (t.media.getAttribute('height') !== null) {
- return t.media.getAttribute('height');
- } else {
- return t.options.defaultVideoHeight;
- }
- } else {
- return t.options.defaultAudioHeight;
- }
- })();
-
- var parentWidth = t.container.parent().closest(':visible').width(),
- parentHeight = t.container.parent().closest(':visible').height(),
- newHeight = t.isVideo || !t.options.autosizeProgress ? parseInt(parentWidth * nativeHeight/nativeWidth, 10) : nativeHeight;
-
- // When we use percent, the newHeight can't be calculated so we get the container height
- if (isNaN(newHeight) || ( parentHeight !== 0 && newHeight > parentHeight && parentHeight > nativeHeight)) {
- newHeight = parentHeight;
- }
-
- if (t.container.parent().length > 0 && t.container.parent()[0].tagName.toLowerCase() === 'body') { // && t.container.siblings().count == 0) {
- parentWidth = $(window).width();
- newHeight = $(window).height();
- }
-
- if ( newHeight && parentWidth ) {
-
- // set outer container size
- t.container
- .width(parentWidth)
- .height(newHeight);
-
- // set native <video> or <audio> and shims
- t.$media.add(t.container.find('.mejs-shim'))
- .width('100%')
- .height('100%');
-
- // if shim is ready, send the size to the embeded plugin
- if (t.isVideo) {
- if (t.media.setVideoSize) {
- t.media.setVideoSize(parentWidth, newHeight);
- }
- }
-
- // set the layers
- t.layers.children('.mejs-layer')
- .width('100%')
- .height('100%');
- }
- },
-
- setFillMode: function() {
- var t = this,
- parent = t.outerContainer;
-
- if (!parent.width()) {
- parent.height(t.$media.width());
- }
-
- if (!parent.height()) {
- parent.height(t.$media.height());
- }
-
- var parentWidth = parent.width(),
- parentHeight = parent.height();
-
- t.setDimensions('100%', '100%');
-
- // This prevents an issue when displaying poster
- t.container.find('.mejs-poster img').css('display', 'block');
-
- targetElement = t.container.find('object, embed, iframe, video');
-
- // calculate new width and height
- var initHeight = t.height,
- initWidth = t.width,
- // scale to the target width
- scaleX1 = parentWidth,
- scaleY1 = (initHeight * parentWidth) / initWidth,
- // scale to the target height
- scaleX2 = (initWidth * parentHeight) / initHeight,
- scaleY2 = parentHeight,
- // now figure out which one we should use
- bScaleOnWidth = !(scaleX2 > parentWidth),
- finalWidth = bScaleOnWidth ? Math.floor(scaleX1) : Math.floor(scaleX2),
- finalHeight = bScaleOnWidth ? Math.floor(scaleY1) : Math.floor(scaleY2);
-
- if (bScaleOnWidth) {
- targetElement.height(finalHeight).width(parentWidth);
- if (t.media.setVideoSize) {
- t.media.setVideoSize(parentWidth, finalHeight);
- }
- } else {
- targetElement.height(parentHeight).width(finalWidth);
- if (t.media.setVideoSize) {
- t.media.setVideoSize(finalWidth, parentHeight);
- }
- }
-
- targetElement.css({
- 'margin-left': Math.floor((parentWidth - finalWidth) / 2),
- 'margin-top': 0
- });
- },
-
- setDimensions: function(width, height) {
- var t = this;
-
- t.container
- .width(width)
- .height(height);
-
- t.layers.children('.mejs-layer')
- .width(width)
- .height(height);
- },
- setControlsSize: function() {
- var t = this,
- usedWidth = 0,
- railWidth = 0,
- rail = t.controls.find('.mejs-time-rail'),
- total = t.controls.find('.mejs-time-total'),
- others = rail.siblings(),
- lastControl = others.last(),
- lastControlPosition = null,
- avoidAutosizeProgress = t.options && !t.options.autosizeProgress;
- // skip calculation if hidden
- if (!t.container.is(':visible') || !rail.length || !rail.is(':visible')) {
- return;
- }
- // allow the size to come from custom CSS
- if (avoidAutosizeProgress) {
- // Also, frontends devs can be more flexible
- // due the opportunity of absolute positioning.
- railWidth = parseInt(rail.css('width'), 10);
- }
- // attempt to autosize
- if (railWidth === 0 || !railWidth) {
- // find the size of all the other controls besides the rail
- others.each(function() {
- var $this = $(this);
- if ($this.css('position') != 'absolute' && $this.is(':visible')) {
- usedWidth += $(this).outerWidth(true);
- }
- });
- // fit the rail into the remaining space
- railWidth = t.controls.width() - usedWidth - (rail.outerWidth(true) - rail.width());
- }
- // resize the rail,
- // but then check if the last control (say, the fullscreen button) got pushed down
- // this often happens when zoomed
- do {
- // outer area
- // we only want to set an inline style with the width of the rail
- // if we're trying to autosize.
- if (!avoidAutosizeProgress) {
- rail.width(railWidth);
- }
- // dark space
- total.width(railWidth - (total.outerWidth(true) - total.width()));
- if (lastControl.css('position') != 'absolute') {
- lastControlPosition = lastControl.length ? lastControl.position() : null;
- railWidth--;
- }
- } while (lastControlPosition !== null && lastControlPosition.top.toFixed(2) > 0 && railWidth > 0);
- t.container.trigger('controlsresize');
- },
- buildposter: function(player, controls, layers, media) {
- var t = this,
- poster =
- $('<div class="mejs-poster mejs-layer">' +
- '</div>')
- .appendTo(layers),
- posterUrl = player.$media.attr('poster');
- // prioriy goes to option (this is useful if you need to support iOS 3.x (iOS completely fails with poster)
- if (player.options.poster !== '') {
- posterUrl = player.options.poster;
- }
- // second, try the real poster
- if ( posterUrl ) {
- t.setPoster(posterUrl);
- } else {
- poster.hide();
- }
- media.addEventListener('play',function() {
- poster.hide();
- }, false);
- if(player.options.showPosterWhenEnded && player.options.autoRewind){
- media.addEventListener('ended',function() {
- poster.show();
- }, false);
- }
- },
- setPoster: function(url) {
- var t = this,
- posterDiv = t.container.find('.mejs-poster'),
- posterImg = posterDiv.find('img');
- if (posterImg.length === 0) {
- posterImg = $('<img width="100%" height="100%" alt="" />').appendTo(posterDiv);
- }
- posterImg.attr('src', url);
- posterDiv.css({'background-image' : 'url(' + url + ')'});
- },
- buildoverlays: function(player, controls, layers, media) {
- var t = this;
- if (!player.isVideo)
- return;
- var
- loading =
- $('<div class="mejs-overlay mejs-layer">'+
- '<div class="mejs-overlay-loading"><span></span></div>'+
- '</div>')
- .hide() // start out hidden
- .appendTo(layers),
- error =
- $('<div class="mejs-overlay mejs-layer">'+
- '<div class="mejs-overlay-error"></div>'+
- '</div>')
- .hide() // start out hidden
- .appendTo(layers),
- // this needs to come last so it's on top
- bigPlay =
- $('<div class="mejs-overlay mejs-layer mejs-overlay-play">'+
- '<div class="mejs-overlay-button" role="button" aria-label="' + mejs.i18n.t('mejs.play') + '" aria-pressed="false"></div>'+
- '</div>')
- .appendTo(layers)
- .bind('click', function() { // Removed 'touchstart' due issues on Samsung Android devices where a tap on bigPlay started and immediately stopped the video
- if (t.options.clickToPlayPause) {
- if (media.paused) {
- media.play();
- }
- var button = $(this).find('.mejs-overlay-button'),
- pressed = button.attr('aria-pressed');
- button.attr('aria-pressed', !!pressed);
- }
- });
- /*
- if (mejs.MediaFeatures.isiOS || mejs.MediaFeatures.isAndroid) {
- bigPlay.remove();
- loading.remove();
- }
- */
- // show/hide big play button
- media.addEventListener('play',function() {
- bigPlay.hide();
- loading.hide();
- controls.find('.mejs-time-buffering').hide();
- error.hide();
- }, false);
- media.addEventListener('playing', function() {
- bigPlay.hide();
- loading.hide();
- controls.find('.mejs-time-buffering').hide();
- error.hide();
- }, false);
- media.addEventListener('seeking', function() {
- loading.show();
- controls.find('.mejs-time-buffering').show();
- }, false);
- media.addEventListener('seeked', function() {
- loading.hide();
- controls.find('.mejs-time-buffering').hide();
- }, false);
- media.addEventListener('pause',function() {
- if (!mejs.MediaFeatures.isiPhone) {
- bigPlay.show();
- }
- }, false);
- media.addEventListener('waiting', function() {
- loading.show();
- controls.find('.mejs-time-buffering').show();
- }, false);
- // show/hide loading
- media.addEventListener('loadeddata',function() {
- // for some reason Chrome is firing this event
- //if (mejs.MediaFeatures.isChrome && media.getAttribute && media.getAttribute('preload') === 'none')
- // return;
- loading.show();
- controls.find('.mejs-time-buffering').show();
- // Firing the 'canplay' event after a timeout which isn't getting fired on some Android 4.1 devices (https://github.com/johndyer/mediaelement/issues/1305)
- if (mejs.MediaFeatures.isAndroid) {
- media.canplayTimeout = window.setTimeout(
- function() {
- if (document.createEvent) {
- var evt = document.createEvent('HTMLEvents');
- evt.initEvent('canplay', true, true);
- return media.dispatchEvent(evt);
- }
- }, 300
- );
- }
- }, false);
- media.addEventListener('canplay',function() {
- loading.hide();
- controls.find('.mejs-time-buffering').hide();
- clearTimeout(media.canplayTimeout); // Clear timeout inside 'loadeddata' to prevent 'canplay' to fire twice
- }, false);
- // error handling
- media.addEventListener('error',function(e) {
- t.handleError(e);
- loading.hide();
- bigPlay.hide();
- error.show();
- error.find('.mejs-overlay-error').html("Error loading this resource");
- }, false);
- media.addEventListener('keydown', function(e) {
- t.onkeydown(player, media, e);
- }, false);
- },
- buildkeyboard: function(player, controls, layers, media) {
- var t = this;
- t.container.keydown(function () {
- t.keyboardAction = true;
- });
- // listen for key presses
- t.globalBind('keydown', function(event) {
- player.hasFocus = $(event.target).closest('.mejs-container').length !== 0
- && $(event.target).closest('.mejs-container').attr('id') === player.$media.closest('.mejs-container').attr('id');
- return t.onkeydown(player, media, event);
- });
- // check if someone clicked outside a player region, then kill its focus
- t.globalBind('click', function(event) {
- player.hasFocus = $(event.target).closest('.mejs-container').length !== 0;
- });
- },
- onkeydown: function(player, media, e) {
- if (player.hasFocus && player.options.enableKeyboard) {
- // find a matching key
- for (var i = 0, il = player.options.keyActions.length; i < il; i++) {
- var keyAction = player.options.keyActions[i];
- for (var j = 0, jl = keyAction.keys.length; j < jl; j++) {
- if (e.keyCode == keyAction.keys[j]) {
- if (typeof(e.preventDefault) == "function") e.preventDefault();
- keyAction.action(player, media, e.keyCode, e);
- return false;
- }
- }
- }
- }
- return true;
- },
- findTracks: function() {
- var t = this,
- tracktags = t.$media.find('track');
- // store for use by plugins
- t.tracks = [];
- tracktags.each(function(index, track) {
- track = $(track);
- t.tracks.push({
- srclang: (track.attr('srclang')) ? track.attr('srclang').toLowerCase() : '',
- src: track.attr('src'),
- kind: track.attr('kind'),
- label: track.attr('label') || '',
- entries: [],
- isLoaded: false
- });
- });
- },
- changeSkin: function(className) {
- this.container[0].className = 'mejs-container ' + className;
- this.setPlayerSize(this.width, this.height);
- this.setControlsSize();
- },
- play: function() {
- this.load();
- this.media.play();
- },
- pause: function() {
- try {
- this.media.pause();
- } catch (e) {}
- },
- load: function() {
- if (!this.isLoaded) {
- this.media.load();
- }
- this.isLoaded = true;
- },
- setMuted: function(muted) {
- this.media.setMuted(muted);
- },
- setCurrentTime: function(time) {
- this.media.setCurrentTime(time);
- },
- getCurrentTime: function() {
- return this.media.currentTime;
- },
- setVolume: function(volume) {
- this.media.setVolume(volume);
- },
- getVolume: function() {
- return this.media.volume;
- },
- setSrc: function(src) {
- var
- t = this;
- // If using YouTube, its API is different to load a specific source
- if (t.media.pluginType === 'youtube') {
- var videoId;
- if (typeof src !== 'string') {
- var i, media;
- for (i=0; i<src.length; i++) {
- media = src[i];
- if (this.canPlayType(media.type)) {
- src = media.src;
- break;
- }
- }
- }
- // youtu.be url from share button
- if (src.lastIndexOf('youtu.be') !== -1) {
- videoId = src.substr(src.lastIndexOf('/') + 1);
- if (videoId.indexOf('?') !== -1) {
- videoId = videoId.substr(0, videoId.indexOf('?'));
- }
- } else {
- // https://www.youtube.com/watch?v=
- var videoIdMatch = src.match(/[?&]v=([^&#]+)|&|#|$/);
- if (videoIdMatch) {
- videoId = videoIdMatch[1];
- }
- }
- if (t.media.getAttribute('autoplay') !== null) {
- t.media.pluginApi.loadVideoById(videoId);
- } else {
- t.media.pluginApi.cueVideoById(videoId);
- }
- }
- else {
- t.media.setSrc(src);
- }
- },
- remove: function() {
- var t = this, featureIndex, feature;
- t.container.prev('.mejs-offscreen').remove();
- // invoke features cleanup
- for (featureIndex in t.options.features) {
- feature = t.options.features[featureIndex];
- if (t['clean' + feature]) {
- try {
- t['clean' + feature](t);
- } catch (e) {
- // TODO: report control error
- //throw e;
- //
- //
- }
- }
- }
- // grab video and put it back in place
- if (!t.isDynamic) {
- t.$media.prop('controls', true);
- // detach events from the video
- // TODO: detach event listeners better than this;
- // also detach ONLY the events attached by this plugin!
- t.$node.clone().insertBefore(t.container).show();
- t.$node.remove();
- } else {
- t.$node.insertBefore(t.container);
- }
- if (t.media.pluginType !== 'native') {
- t.media.remove();
- }
- // Remove the player from the mejs.players object so that pauseOtherPlayers doesn't blow up when trying to pause a non existance flash api.
- delete mejs.players[t.id];
- if (typeof t.container == 'object') {
- t.container.remove();
- }
- t.globalUnbind();
- delete t.node.player;
- },
- rebuildtracks: function(){
- var t = this;
- t.findTracks();
- t.buildtracks(t, t.controls, t.layers, t.media);
- },
- resetSize: function(){
- var t = this;
- // webkit has trouble doing this without a delay
- setTimeout(function () {
- //
- t.setPlayerSize(t.width, t.height);
- t.setControlsSize();
- }, 50);
- }
- };
- (function(){
- var rwindow = /^((after|before)print|(before)?unload|hashchange|message|o(ff|n)line|page(hide|show)|popstate|resize|storage)\b/;
- function splitEvents(events, id) {
- // add player ID as an event namespace so it's easier to unbind them all later
- var ret = {d: [], w: []};
- $.each((events || '').split(' '), function(k, v){
- var eventname = v + '.' + id;
- if (eventname.indexOf('.') === 0) {
- ret.d.push(eventname);
- ret.w.push(eventname);
- }
- else {
- ret[rwindow.test(v) ? 'w' : 'd'].push(eventname);
- }
- });
- ret.d = ret.d.join(' ');
- ret.w = ret.w.join(' ');
- return ret;
- }
- mejs.MediaElementPlayer.prototype.globalBind = function(events, data, callback) {
- var t = this;
- var doc = t.node ? t.node.ownerDocument : document;
- events = splitEvents(events, t.id);
- if (events.d) $(doc).bind(events.d, data, callback);
- if (events.w) $(window).bind(events.w, data, callback);
- };
- mejs.MediaElementPlayer.prototype.globalUnbind = function(events, callback) {
- var t = this;
- var doc = t.node ? t.node.ownerDocument : document;
- events = splitEvents(events, t.id);
- if (events.d) $(doc).unbind(events.d, callback);
- if (events.w) $(window).unbind(events.w, callback);
- };
- })();
- // turn into jQuery plugin
- if (typeof $ != 'undefined') {
- $.fn.mediaelementplayer = function (options) {
- if (options === false) {
- this.each(function () {
- var player = $(this).data('mediaelementplayer');
- if (player) {
- player.remove();
- }
- $(this).removeData('mediaelementplayer');
- });
- }
- else {
- this.each(function () {
- $(this).data('mediaelementplayer', new mejs.MediaElementPlayer(this, options));
- });
- }
- return this;
- };
- $(document).ready(function() {
- // auto enable using JSON attribute
- $('.mejs-player').mediaelementplayer();
- });
- }
- // push out to window
- window.MediaElementPlayer = mejs.MediaElementPlayer;
- })(mejs.$);
- (function($) {
- $.extend(mejs.MepDefaults, {
- playText: '',
- pauseText: ''
- });
- // PLAY/pause BUTTON
- $.extend(MediaElementPlayer.prototype, {
- buildplaypause: function(player, controls, layers, media) {
- var
- t = this,
- op = t.options,
- playTitle = op.playText ? op.playText : mejs.i18n.t('mejs.play'),
- pauseTitle = op.pauseText ? op.pauseText : mejs.i18n.t('mejs.pause'),
- play =
- $('<div class="mejs-button mejs-playpause-button mejs-play" >' +
- '<button type="button" aria-controls="' + t.id + '" title="' + playTitle + '" aria-label="' + pauseTitle + '"></button>' +
- '</div>')
- .appendTo(controls)
- .click(function(e) {
- e.preventDefault();
-
- if (media.paused) {
- media.play();
- } else {
- media.pause();
- }
-
- return false;
- }),
- play_btn = play.find('button');
- function togglePlayPause(which) {
- if ('play' === which) {
- play.removeClass('mejs-play').addClass('mejs-pause');
- play_btn.attr({
- 'title': pauseTitle,
- 'aria-label': pauseTitle
- });
- } else {
- play.removeClass('mejs-pause').addClass('mejs-play');
- play_btn.attr({
- 'title': playTitle,
- 'aria-label': playTitle
- });
- }
- };
- togglePlayPause('pse');
- media.addEventListener('play',function() {
- togglePlayPause('play');
- }, false);
- media.addEventListener('playing',function() {
- togglePlayPause('play');
- }, false);
- media.addEventListener('pause',function() {
- togglePlayPause('pse');
- }, false);
- media.addEventListener('paused',function() {
- togglePlayPause('pse');
- }, false);
- }
- });
-
- })(mejs.$);
- (function($) {
- $.extend(mejs.MepDefaults, {
- stopText: 'Stop'
- });
- // STOP BUTTON
- $.extend(MediaElementPlayer.prototype, {
- buildstop: function(player, controls, layers, media) {
- var t = this;
- $('<div class="mejs-button mejs-stop-button mejs-stop">' +
- '<button type="button" aria-controls="' + t.id + '" title="' + t.options.stopText + '" aria-label="' + t.options.stopText + '"></button>' +
- '</div>')
- .appendTo(controls)
- .click(function() {
- if (!media.paused) {
- media.pause();
- }
- if (media.currentTime > 0) {
- media.setCurrentTime(0);
- media.pause();
- controls.find('.mejs-time-current').width('0px');
- controls.find('.mejs-time-handle').css('left', '0px');
- controls.find('.mejs-time-float-current').html( mejs.Utility.secondsToTimeCode(0, player.options));
- controls.find('.mejs-currenttime').html( mejs.Utility.secondsToTimeCode(0, player.options));
- layers.find('.mejs-poster').show();
- }
- });
- }
- });
-
- })(mejs.$);
- (function($) {
- $.extend(mejs.MepDefaults, {
- // Enable tooltip that shows time in progress bar
- enableProgressTooltip: true,
- progressHelpText: ''
- });
- // progress/loaded bar
- $.extend(MediaElementPlayer.prototype, {
- buildprogress: function(player, controls, layers, media) {
- var
- t = this,
- mouseIsDown = false,
- mouseIsOver = false,
- lastKeyPressTime = 0,
- startedPaused = false,
- autoRewindInitial = player.options.autoRewind,
- progressTitle = t.options.progressHelpText ? t.options.progressHelpText : mejs.i18n.t('mejs.time-help-text'),
- tooltip = player.options.enableProgressTooltip ? '<span class="mejs-time-float">' +
- '<span class="mejs-time-float-current">00:00</span>' +
- '<span class="mejs-time-float-corner"></span>' +
- '</span>' : "";
- $('<div class="mejs-time-rail">' +
- '<span class="mejs-time-total mejs-time-slider">' +
- //'<span class="mejs-offscreen">' + progressTitle + '</span>' +
- '<span class="mejs-time-buffering"></span>' +
- '<span class="mejs-time-loaded"></span>' +
- '<span class="mejs-time-current"></span>' +
- '<span class="mejs-time-handle"></span>' +
- tooltip +
- '</span>' +
- '</div>')
- .appendTo(controls);
- controls.find('.mejs-time-buffering').hide();
- t.total = controls.find('.mejs-time-total');
- t.loaded = controls.find('.mejs-time-loaded');
- t.current = controls.find('.mejs-time-current');
- t.handle = controls.find('.mejs-time-handle');
- t.timefloat = controls.find('.mejs-time-float');
- t.timefloatcurrent = controls.find('.mejs-time-float-current');
- t.slider = controls.find('.mejs-time-slider');
- var handleMouseMove = function (e) {
- var offset = t.total.offset(),
- width = t.total.width(),
- percentage = 0,
- newTime = 0,
- pos = 0,
- x;
- // mouse or touch position relative to the object
- if (e.originalEvent && e.originalEvent.changedTouches) {
- x = e.originalEvent.changedTouches[0].pageX;
- } else if (e.changedTouches) { // for Zepto
- x = e.changedTouches[0].pageX;
- } else {
- x = e.pageX;
- }
- if (media.duration) {
- if (x < offset.left) {
- x = offset.left;
- } else if (x > width + offset.left) {
- x = width + offset.left;
- }
- pos = x - offset.left;
- percentage = (pos / width);
- newTime = (percentage <= 0.02) ? 0 : percentage * media.duration;
- // seek to where the mouse is
- if (mouseIsDown && newTime !== media.currentTime) {
- media.setCurrentTime(newTime);
- }
- // position floating time box
- if (!mejs.MediaFeatures.hasTouch) {
- t.timefloat.css('left', pos);
- t.timefloatcurrent.html( mejs.Utility.secondsToTimeCode(newTime, player.options) );
- t.timefloat.show();
- }
- }
- },
- // Accessibility for slider
- updateSlider = function (e) {
- var seconds = media.currentTime,
- timeSliderText = mejs.i18n.t('mejs.time-slider'),
- time = mejs.Utility.secondsToTimeCode(seconds, player.options),
- duration = media.duration;
- t.slider.attr({
- 'aria-label': timeSliderText,
- 'aria-valuemin': 0,
- 'aria-valuemax': duration,
- 'aria-valuenow': seconds,
- 'aria-valuetext': time,
- 'role': 'slider',
- 'tabindex': 0
- });
- },
- restartPlayer = function () {
- var now = new Date();
- if (now - lastKeyPressTime >= 1000) {
- media.play();
- }
- };
- t.slider.bind('focus', function (e) {
- player.options.autoRewind = false;
- });
- t.slider.bind('blur', function (e) {
- player.options.autoRewind = autoRewindInitial;
- });
- t.slider.bind('keydown', function (e) {
- if ((new Date() - lastKeyPressTime) >= 1000) {
- startedPaused = media.paused;
- }
- var keyCode = e.keyCode,
- duration = media.duration,
- seekTime = media.currentTime,
- seekForward = player.options.defaultSeekForwardInterval(media),
- seekBackward = player.options.defaultSeekBackwardInterval(media);
- switch (keyCode) {
- case 37: // left
- case 40: // Down
- seekTime -= seekBackward;
- break;
- case 39: // Right
- case 38: // Up
- seekTime += seekForward;
- break;
- case 36: // Home
- seekTime = 0;
- break;
- case 35: // end
- seekTime = duration;
- break;
- case 32: // space
- case 13: // enter
- media.paused ? media.play() : media.pause();
- return;
- default:
- return;
- }
- seekTime = seekTime < 0 ? 0 : (seekTime >= duration ? duration : Math.floor(seekTime));
- lastKeyPressTime = new Date();
- if (!startedPaused) {
- media.pause();
- }
- if (seekTime < media.duration && !startedPaused) {
- setTimeout(restartPlayer, 1100);
- }
- media.setCurrentTime(seekTime);
- e.preventDefault();
- e.stopPropagation();
- return false;
- });
- // handle clicks
- //controls.find('.mejs-time-rail').delegate('span', 'click', handleMouseMove);
- t.total
- .bind('mousedown touchstart', function (e) {
- // only handle left clicks or touch
- if (e.which === 1 || e.which === 0) {
- mouseIsDown = true;
- handleMouseMove(e);
- t.globalBind('mousemove.dur touchmove.dur', function(e) {
- handleMouseMove(e);
- });
- t.globalBind('mouseup.dur touchend.dur', function (e) {
- mouseIsDown = false;
- if (typeof t.timefloat !== 'undefined') {
- t.timefloat.hide();
- }
- t.globalUnbind('.dur');
- });
- }
- })
- .bind('mouseenter', function(e) {
- mouseIsOver = true;
- t.globalBind('mousemove.dur', function(e) {
- handleMouseMove(e);
- });
- if (typeof t.timefloat !== 'undefined' && !mejs.MediaFeatures.hasTouch) {
- t.timefloat.show();
- }
- })
- .bind('mouseleave',function(e) {
- mouseIsOver = false;
- if (!mouseIsDown) {
- t.globalUnbind('.dur');
- if (typeof t.timefloat !== 'undefined') {
- t.timefloat.hide();
- }
- }
- });
- // loading
- media.addEventListener('progress', function (e) {
- player.setProgressRail(e);
- player.setCurrentRail(e);
- }, false);
- // current time
- media.addEventListener('timeupdate', function(e) {
- player.setProgressRail(e);
- player.setCurrentRail(e);
- updateSlider(e);
- }, false);
- t.container.on('controlsresize', function(e) {
- player.setProgressRail(e);
- player.setCurrentRail(e);
- });
- },
- setProgressRail: function(e) {
- var
- t = this,
- target = (e !== undefined) ? e.target : t.media,
- percent = null;
- // newest HTML5 spec has buffered array (FF4, Webkit)
- if (target && target.buffered && target.buffered.length > 0 && target.buffered.end && target.duration) {
- // account for a real array with multiple values - always read the end of the last buffer
- percent = target.buffered.end(target.buffered.length - 1) / target.duration;
- }
- // Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
- // to be anything other than 0. If the byte count is available we use this instead.
- // Browsers that support the else if do not seem to have the bufferedBytes value and
- // should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
- else if (target && target.bytesTotal !== undefined && target.bytesTotal > 0 && target.bufferedBytes !== undefined) {
- percent = target.bufferedBytes / target.bytesTotal;
- }
- // Firefox 3 with an Ogg file seems to go this way
- else if (e && e.lengthComputable && e.total !== 0) {
- percent = e.loaded / e.total;
- }
- // finally update the progress bar
- if (percent !== null) {
- percent = Math.min(1, Math.max(0, percent));
- // update loaded bar
- if (t.loaded && t.total) {
- t.loaded.width(t.total.width() * percent);
- }
- }
- },
- setCurrentRail: function() {
- var t = this;
-
- if (t.media.currentTime !== undefined && t.media.duration) {
- // update bar and handle
- if (t.total && t.handle) {
- var
- newWidth = Math.round(t.total.width() * t.media.currentTime / t.media.duration),
- handlePos = newWidth - Math.round(t.handle.outerWidth(true) / 2);
- t.current.width(newWidth);
- t.handle.css('left', handlePos);
- }
- }
- }
- });
- })(mejs.$);
- (function($) {
-
- // options
- $.extend(mejs.MepDefaults, {
- duration: -1,
- timeAndDurationSeparator: '<span> | </span>'
- });
- // current and duration 00:00 / 00:00
- $.extend(MediaElementPlayer.prototype, {
- buildcurrent: function(player, controls, layers, media) {
- var t = this;
-
- $('<div class="mejs-time" role="timer" aria-live="off">' +
- '<span class="mejs-currenttime">' +
- mejs.Utility.secondsToTimeCode(0, player.options) +
- '</span>'+
- '</div>')
- .appendTo(controls);
-
- t.currenttime = t.controls.find('.mejs-currenttime');
- media.addEventListener('timeupdate',function() {
- if (t.controlsAreVisible) {
- player.updateCurrent();
- }
- }, false);
- },
- buildduration: function(player, controls, layers, media) {
- var t = this;
-
- if (controls.children().last().find('.mejs-currenttime').length > 0) {
- $(t.options.timeAndDurationSeparator +
- '<span class="mejs-duration">' +
- mejs.Utility.secondsToTimeCode(t.options.duration, t.options) +
- '</span>')
- .appendTo(controls.find('.mejs-time'));
- } else {
- // add class to current time
- controls.find('.mejs-currenttime').parent().addClass('mejs-currenttime-container');
-
- $('<div class="mejs-time mejs-duration-container">'+
- '<span class="mejs-duration">' +
- mejs.Utility.secondsToTimeCode(t.options.duration, t.options) +
- '</span>' +
- '</div>')
- .appendTo(controls);
- }
-
- t.durationD = t.controls.find('.mejs-duration');
- media.addEventListener('timeupdate',function() {
- if (t.controlsAreVisible) {
- player.updateDuration();
- }
- }, false);
- },
-
- updateCurrent: function() {
- var t = this;
-
- var currentTime = t.media.currentTime;
-
- if (isNaN(currentTime)) {
- currentTime = 0;
- }
- if (t.currenttime) {
- t.currenttime.html(mejs.Utility.secondsToTimeCode(currentTime, t.options));
- }
- },
-
- updateDuration: function() {
- var t = this;
-
- var duration = t.media.duration;
- if (t.options.duration > 0) {
- duration = t.options.duration;
- }
-
- if (isNaN(duration)) {
- duration = 0;
- }
- //Toggle the long video class if the video is longer than an hour.
- t.container.toggleClass("mejs-long-video", duration > 3600);
-
- if (t.durationD && duration > 0) {
- t.durationD.html(mejs.Utility.secondsToTimeCode(duration, t.options));
- }
- }
- });
- })(mejs.$);
- (function ($) {
- $.extend(mejs.MepDefaults, {
- muteText: mejs.i18n.t('mejs.mute-toggle'),
- allyVolumeControlText: mejs.i18n.t('mejs.volume-help-text'),
- hideVolumeOnTouchDevices: true,
- audioVolume: 'horizontal',
- videoVolume: 'vertical'
- });
- $.extend(MediaElementPlayer.prototype, {
- buildvolume: function (player, controls, layers, media) {
- // Android and iOS don't support volume controls
- if ((mejs.MediaFeatures.isAndroid || mejs.MediaFeatures.isiOS) && this.options.hideVolumeOnTouchDevices)
- return;
- var t = this,
- mode = (t.isVideo) ? t.options.videoVolume : t.options.audioVolume,
- mute = (mode == 'horizontal') ?
- // horizontal version
- $('<div class="mejs-button mejs-volume-button mejs-mute">' +
- '<button type="button" aria-controls="' + t.id +
- '" title="' + t.options.muteText +
- '" aria-label="' + t.options.muteText +
- '"></button>' +
- '</div>' +
- '<a href="javascript:void(0);" class="mejs-horizontal-volume-slider">' + // outer background
- '<span class="mejs-offscreen">' + t.options.allyVolumeControlText + '</span>' +
- '<div class="mejs-horizontal-volume-total"></div>' + // line background
- '<div class="mejs-horizontal-volume-current"></div>' + // current volume
- '<div class="mejs-horizontal-volume-handle"></div>' + // handle
- '</a>'
- )
- .appendTo(controls) :
- // vertical version
- $('<div class="mejs-button mejs-volume-button mejs-mute">' +
- '<button type="button" aria-controls="' + t.id +
- '" title="' + t.options.muteText +
- '" aria-label="' + t.options.muteText +
- '"></button>' +
- '<a href="javascript:void(0);" class="mejs-volume-slider">' + // outer background
- '<span class="mejs-offscreen">' + t.options.allyVolumeControlText + '</span>' +
- '<div class="mejs-volume-total"></div>' + // line background
- '<div class="mejs-volume-current"></div>' + // current volume
- '<div class="mejs-volume-handle"></div>' + // handle
- '</a>' +
- '</div>')
- .appendTo(controls),
- volumeSlider = t.container.find('.mejs-volume-slider, .mejs-horizontal-volume-slider'),
- volumeTotal = t.container.find('.mejs-volume-total, .mejs-horizontal-volume-total'),
- volumeCurrent = t.container.find('.mejs-volume-current, .mejs-horizontal-volume-current'),
- volumeHandle = t.container.find('.mejs-volume-handle, .mejs-horizontal-volume-handle'),
- positionVolumeHandle = function (volume, secondTry) {
- if (!volumeSlider.is(':visible') && typeof secondTry == 'undefined') {
- volumeSlider.show();
- positionVolumeHandle(volume, true);
- volumeSlider.hide();
- return;
- }
- // correct to 0-1
- volume = Math.max(0, volume);
- volume = Math.min(volume, 1);
- // adjust mute button style
- if (volume === 0) {
- mute.removeClass('mejs-mute').addClass('mejs-unmute');
- mute.children('button').attr('title', mejs.i18n.t('mejs.unmute')).attr('aria-label', mejs.i18n.t('mejs.unmute'));
- } else {
- mute.removeClass('mejs-unmute').addClass('mejs-mute');
- mute.children('button').attr('title', mejs.i18n.t('mejs.mute')).attr('aria-label', mejs.i18n.t('mejs.mute'));
- }
- // top/left of full size volume slider background
- var totalPosition = volumeTotal.position();
- // position slider
- if (mode == 'vertical') {
- var
- // height of the full size volume slider background
- totalHeight = volumeTotal.height(),
- // the new top position based on the current volume
- // 70% volume on 100px height == top:30px
- newTop = totalHeight - (totalHeight * volume);
- // handle
- volumeHandle.css('top', Math.round(totalPosition.top + newTop - (volumeHandle.height() / 2)));
- // show the current visibility
- volumeCurrent.height(totalHeight - newTop);
- volumeCurrent.css('top', totalPosition.top + newTop);
- } else {
- var
- // height of the full size volume slider background
- totalWidth = volumeTotal.width(),
- // the new left position based on the current volume
- newLeft = totalWidth * volume;
- // handle
- volumeHandle.css('left', Math.round(totalPosition.left + newLeft - (volumeHandle.width() / 2)));
- // rezize the current part of the volume bar
- volumeCurrent.width(Math.round(newLeft));
- }
- },
- handleVolumeMove = function (e) {
- var volume = null,
- totalOffset = volumeTotal.offset();
- // calculate the new volume based on the moust position
- if (mode === 'vertical') {
- var
- railHeight = volumeTotal.height(),
- newY = e.pageY - totalOffset.top;
- volume = (railHeight - newY) / railHeight;
- // the controls just hide themselves (usually when mouse moves too far up)
- if (totalOffset.top === 0 || totalOffset.left === 0) {
- return;
- }
- } else {
- var
- railWidth = volumeTotal.width(),
- newX = e.pageX - totalOffset.left;
- volume = newX / railWidth;
- }
- // ensure the volume isn't outside 0-1
- volume = Math.max(0, volume);
- volume = Math.min(volume, 1);
- // position the slider and handle
- positionVolumeHandle(volume);
- // set the media object (this will trigger the volumechanged event)
- if (volume === 0) {
- media.setMuted(true);
- } else {
- media.setMuted(false);
- }
- media.setVolume(volume);
- },
- mouseIsDown = false,
- mouseIsOver = false;
- // SLIDER
- mute
- .hover(function () {
- volumeSlider.show();
- mouseIsOver = true;
- }, function () {
- mouseIsOver = false;
- if (!mouseIsDown && mode == 'vertical') {
- volumeSlider.hide();
- }
- });
- var updateVolumeSlider = function (e) {
- var volume = Math.floor(media.volume * 100);
- volumeSlider.attr({
- 'aria-label': mejs.i18n.t('mejs.volume-slider'),
- 'aria-valuemin': 0,
- 'aria-valuemax': 100,
- 'aria-valuenow': volume,
- 'aria-valuetext': volume + '%',
- 'role': 'slider',
- 'tabindex': 0
- });
- };
- volumeSlider
- .bind('mouseover', function () {
- mouseIsOver = true;
- })
- .bind('mousedown', function (e) {
- handleVolumeMove(e);
- t.globalBind('mousemove.vol', function (e) {
- handleVolumeMove(e);
- });
- t.globalBind('mouseup.vol', function () {
- mouseIsDown = false;
- t.globalUnbind('.vol');
- if (!mouseIsOver && mode == 'vertical') {
- volumeSlider.hide();
- }
- });
- mouseIsDown = true;
- return false;
- })
- .bind('keydown', function (e) {
- var keyCode = e.keyCode;
- var volume = media.volume;
- switch (keyCode) {
- case 38: // Up
- volume = Math.min(volume + 0.1, 1);
- break;
- case 40: // Down
- volume = Math.max(0, volume - 0.1);
- break;
- default:
- return true;
- }
- mouseIsDown = false;
- positionVolumeHandle(volume);
- media.setVolume(volume);
- return false;
- });
- // MUTE button
- mute.find('button').click(function () {
- media.setMuted(!media.muted);
- });
- //Keyboard input
- mute.find('button').bind('focus', function () {
- volumeSlider.show();
- });
- // listen for volume change events from other sources
- media.addEventListener('volumechange', function (e) {
- if (!mouseIsDown) {
- if (media.muted) {
- positionVolumeHandle(0);
- mute.removeClass('mejs-mute').addClass('mejs-unmute');
- } else {
- positionVolumeHandle(media.volume);
- mute.removeClass('mejs-unmute').addClass('mejs-mute');
- }
- }
- updateVolumeSlider(e);
- }, false);
- // mutes the media and sets the volume icon muted if the initial volume is set to 0
- if (player.options.startVolume === 0) {
- media.setMuted(true);
- }
- // shim gets the startvolume as a parameter, but we have to set it on the native <video> and <audio> elements
- if (media.pluginType === 'native') {
- media.setVolume(player.options.startVolume);
- }
- t.container.on('controlsresize', function () {
- if (media.muted) {
- positionVolumeHandle(0);
- mute.removeClass('mejs-mute').addClass('mejs-unmute');
- } else {
- positionVolumeHandle(media.volume);
- mute.removeClass('mejs-unmute').addClass('mejs-mute');
- }
- });
- }
- });
- })(mejs.$);
- (function($) {
- $.extend(mejs.MepDefaults, {
- usePluginFullScreen: true,
- newWindowCallback: function() { return '';},
- fullscreenText: ''
- });
- $.extend(MediaElementPlayer.prototype, {
- isFullScreen: false,
- isNativeFullScreen: false,
- isInIframe: false,
-
- // Possible modes
- // (1) 'native-native' HTML5 video + browser fullscreen (IE10+, etc.)
- // (2) 'plugin-native' plugin video + browser fullscreen (fails in some versions of Firefox)
- // (3) 'fullwindow' Full window (retains all UI)
- // usePluginFullScreen = true
- // (4) 'plugin-click' Flash 1 - click through with pointer events
- // (5) 'plugin-hover' Flash 2 - hover popup in flash (IE6-8)
- fullscreenMode: '',
- buildfullscreen: function(player, controls, layers, media) {
- if (!player.isVideo)
- return;
-
- player.isInIframe = (window.location != window.parent.location);
-
- // detect on start
- media.addEventListener('loadstart', function() { player.detectFullscreenMode(); });
-
- // build button
- var t = this,
- hideTimeout = null,
- fullscreenTitle = t.options.fullscreenText ? t.options.fullscreenText : mejs.i18n.t('mejs.fullscreen'),
- fullscreenBtn =
- $('<div class="mejs-button mejs-fullscreen-button">' +
- '<button type="button" aria-controls="' + t.id + '" title="' + fullscreenTitle + '" aria-label="' + fullscreenTitle + '"></button>' +
- '</div>')
- .appendTo(controls)
- .on('click', function() {
-
- // toggle fullscreen
- var isFullScreen = (mejs.MediaFeatures.hasTrueNativeFullScreen && mejs.MediaFeatures.isFullScreen()) || player.isFullScreen;
-
- if (isFullScreen) {
- player.exitFullScreen();
- } else {
- player.enterFullScreen();
- }
- })
- .on('mouseover', function() {
-
- // very old browsers with a plugin
- if (t.fullscreenMode == 'plugin-hover') {
- if (hideTimeout !== null) {
- clearTimeout(hideTimeout);
- delete hideTimeout;
- }
-
- var buttonPos = fullscreenBtn.offset(),
- containerPos = player.container.offset();
-
- media.positionFullscreenButton(buttonPos.left - containerPos.left, buttonPos.top - containerPos.top, true);
- }
- })
- .on('mouseout', function() {
- if (t.fullscreenMode == 'plugin-hover') {
- if (hideTimeout !== null) {
- clearTimeout(hideTimeout);
- delete hideTimeout;
- }
-
- hideTimeout = setTimeout(function() {
- media.hideFullscreenButton();
- }, 1500);
- }
- });
-
- player.fullscreenBtn = fullscreenBtn;
- t.globalBind('keydown',function (e) {
- if (e.keyCode == 27 && ((mejs.MediaFeatures.hasTrueNativeFullScreen && mejs.MediaFeatures.isFullScreen()) || t.isFullScreen)) {
- player.exitFullScreen();
- }
- });
-
- t.normalHeight = 0;
- t.normalWidth = 0;
-
- // setup native fullscreen event
- if (mejs.MediaFeatures.hasTrueNativeFullScreen) {
- // chrome doesn't alays fire this in an iframe
- var fullscreenChanged = function(e) {
- if (player.isFullScreen) {
- if (mejs.MediaFeatures.isFullScreen()) {
- player.isNativeFullScreen = true;
- // reset the controls once we are fully in full screen
- player.setControlsSize();
- } else {
- player.isNativeFullScreen = false;
- // when a user presses ESC
- // make sure to put the player back into place
- player.exitFullScreen();
- }
- }
- };
- player.globalBind(mejs.MediaFeatures.fullScreenEventName, fullscreenChanged);
- }
- },
-
- detectFullscreenMode: function() {
-
- var t = this,
- mode = '',
- features = mejs.MediaFeatures;
-
- if (features.hasTrueNativeFullScreen && t.media.pluginType === 'native') {
- mode = 'native-native';
- } else if (features.hasTrueNativeFullScreen && t.media.pluginType !== 'native' && !features.hasFirefoxPluginMovingProblem) {
- mode = 'plugin-native';
- } else if (t.usePluginFullScreen) {
- if (mejs.MediaFeatures.supportsPointerEvents) {
- mode = 'plugin-click';
- // this needs some special setup
- t.createPluginClickThrough();
- } else {
- mode = 'plugin-hover';
- }
-
- } else {
- mode = 'fullwindow';
- }
-
-
- t.fullscreenMode = mode;
- return mode;
- },
-
- isPluginClickThroughCreated: false,
-
- createPluginClickThrough: function() {
-
- var t = this;
-
- // don't build twice
- if (t.isPluginClickThroughCreated) {
- return;
- }
- // allows clicking through the fullscreen button and controls down directly to Flash
- /*
- When a user puts his mouse over the fullscreen button, we disable the controls so that mouse events can go down to flash (pointer-events)
- We then put a divs over the video and on either side of the fullscreen button
- to capture mouse movement and restore the controls once the mouse moves outside of the fullscreen button
- */
- var fullscreenIsDisabled = false,
- restoreControls = function() {
- if (fullscreenIsDisabled) {
- // hide the hovers
- for (var i in hoverDivs) {
- hoverDivs[i].hide();
- }
- // restore the control bar
- t.fullscreenBtn.css('pointer-events', '');
- t.controls.css('pointer-events', '');
- // prevent clicks from pausing video
- t.media.removeEventListener('click', t.clickToPlayPauseCallback);
- // store for later
- fullscreenIsDisabled = false;
- }
- },
- hoverDivs = {},
- hoverDivNames = ['top', 'left', 'right', 'bottom'],
- i, len,
- positionHoverDivs = function() {
- var fullScreenBtnOffsetLeft = fullscreenBtn.offset().left - t.container.offset().left,
- fullScreenBtnOffsetTop = fullscreenBtn.offset().top - t.container.offset().top,
- fullScreenBtnWidth = fullscreenBtn.outerWidth(true),
- fullScreenBtnHeight = fullscreenBtn.outerHeight(true),
- containerWidth = t.container.width(),
- containerHeight = t.container.height();
- for (i in hoverDivs) {
- hoverDivs[i].css({position: 'absolute', top: 0, left: 0}); //, backgroundColor: '#f00'});
- }
- // over video, but not controls
- hoverDivs['top']
- .width( containerWidth )
- .height( fullScreenBtnOffsetTop );
- // over controls, but not the fullscreen button
- hoverDivs['left']
- .width( fullScreenBtnOffsetLeft )
- .height( fullScreenBtnHeight )
- .css({top: fullScreenBtnOffsetTop});
- // after the fullscreen button
- hoverDivs['right']
- .width( containerWidth - fullScreenBtnOffsetLeft - fullScreenBtnWidth )
- .height( fullScreenBtnHeight )
- .css({top: fullScreenBtnOffsetTop,
- left: fullScreenBtnOffsetLeft + fullScreenBtnWidth});
- // under the fullscreen button
- hoverDivs['bottom']
- .width( containerWidth )
- .height( containerHeight - fullScreenBtnHeight - fullScreenBtnOffsetTop )
- .css({top: fullScreenBtnOffsetTop + fullScreenBtnHeight});
- };
- t.globalBind('resize', function() {
- positionHoverDivs();
- });
- for (i = 0, len = hoverDivNames.length; i < len; i++) {
- hoverDivs[hoverDivNames[i]] = $('<div class="mejs-fullscreen-hover" />').appendTo(t.container).mouseover(restoreControls).hide();
- }
- // on hover, kill the fullscreen button's HTML handling, allowing clicks down to Flash
- fullscreenBtn.on('mouseover',function() {
- if (!t.isFullScreen) {
- var buttonPos = fullscreenBtn.offset(),
- containerPos = player.container.offset();
- // move the button in Flash into place
- media.positionFullscreenButton(buttonPos.left - containerPos.left, buttonPos.top - containerPos.top, false);
- // allows click through
- t.fullscreenBtn.css('pointer-events', 'none');
- t.controls.css('pointer-events', 'none');
- // restore click-to-play
- t.media.addEventListener('click', t.clickToPlayPauseCallback);
- // show the divs that will restore things
- for (i in hoverDivs) {
- hoverDivs[i].show();
- }
- positionHoverDivs();
- fullscreenIsDisabled = true;
- }
- });
- // restore controls anytime the user enters or leaves fullscreen
- media.addEventListener('fullscreenchange', function(e) {
- t.isFullScreen = !t.isFullScreen;
- // don't allow plugin click to pause video - messes with
- // plugin's controls
- if (t.isFullScreen) {
- t.media.removeEventListener('click', t.clickToPlayPauseCallback);
- } else {
- t.media.addEventListener('click', t.clickToPlayPauseCallback);
- }
- restoreControls();
- });
- // the mouseout event doesn't work on the fullscren button, because we already killed the pointer-events
- // so we use the document.mousemove event to restore controls when the mouse moves outside the fullscreen button
- t.globalBind('mousemove', function(e) {
- // if the mouse is anywhere but the fullsceen button, then restore it all
- if (fullscreenIsDisabled) {
- var fullscreenBtnPos = fullscreenBtn.offset();
- if (e.pageY < fullscreenBtnPos.top || e.pageY > fullscreenBtnPos.top + fullscreenBtn.outerHeight(true) ||
- e.pageX < fullscreenBtnPos.left || e.pageX > fullscreenBtnPos.left + fullscreenBtn.outerWidth(true)
- ) {
- fullscreenBtn.css('pointer-events', '');
- t.controls.css('pointer-events', '');
- fullscreenIsDisabled = false;
- }
- }
- });
- t.isPluginClickThroughCreated = true;
- },
- cleanfullscreen: function(player) {
- player.exitFullScreen();
- },
- containerSizeTimeout: null,
- enterFullScreen: function() {
- var t = this;
- if (mejs.MediaFeatures.isiOS && mejs.MediaFeatures.hasiOSFullScreen && typeof t.media.webkitEnterFullscreen === 'function') {
- t.media.webkitEnterFullscreen();
- return;
- }
- // set it to not show scroll bars so 100% will work
- $(document.documentElement).addClass('mejs-fullscreen');
- // store sizing
- t.normalHeight = t.container.height();
- t.normalWidth = t.container.width();
- // attempt to do true fullscreen
- if (t.fullscreenMode === 'native-native' || t.fullscreenMode === 'plugin-native') {
- mejs.MediaFeatures.requestFullScreen(t.container[0]);
- //return;
- if (t.isInIframe) {
- // sometimes exiting from fullscreen doesn't work
- // notably in Chrome <iframe>. Fixed in version 17
- setTimeout(function checkFullscreen() {
- if (t.isNativeFullScreen) {
- var percentErrorMargin = 0.002, // 0.2%
- windowWidth = $(window).width(),
- screenWidth = screen.width,
- absDiff = Math.abs(screenWidth - windowWidth),
- marginError = screenWidth * percentErrorMargin;
- // check if the video is suddenly not really fullscreen
- if (absDiff > marginError) {
- // manually exit
- t.exitFullScreen();
- } else {
- // test again
- setTimeout(checkFullscreen, 500);
- }
- }
-
- }, 1000);
- }
-
- } else if (t.fullscreeMode == 'fullwindow') {
- // move into position
-
- }
-
- // make full size
- t.container
- .addClass('mejs-container-fullscreen')
- .width('100%')
- .height('100%');
- //.css({position: 'fixed', left: 0, top: 0, right: 0, bottom: 0, overflow: 'hidden', width: '100%', height: '100%', 'z-index': 1000});
- // Only needed for safari 5.1 native full screen, can cause display issues elsewhere
- // Actually, it seems to be needed for IE8, too
- //if (mejs.MediaFeatures.hasTrueNativeFullScreen) {
- t.containerSizeTimeout = setTimeout(function() {
- t.container.css({width: '100%', height: '100%'});
- t.setControlsSize();
- }, 500);
- //}
- if (t.media.pluginType === 'native') {
- t.$media
- .width('100%')
- .height('100%');
- } else {
- t.container.find('.mejs-shim')
- .width('100%')
- .height('100%');
-
- setTimeout(function() {
- var win = $(window),
- winW = win.width(),
- winH = win.height();
-
- t.media.setVideoSize(winW,winH);
- }, 500);
- }
- t.layers.children('div')
- .width('100%')
- .height('100%');
- if (t.fullscreenBtn) {
- t.fullscreenBtn
- .removeClass('mejs-fullscreen')
- .addClass('mejs-unfullscreen');
- }
- t.setControlsSize();
- t.isFullScreen = true;
- var zoomFactor = Math.min(screen.width / t.width, screen.height / t.height);
- t.container.find('.mejs-captions-text').css('font-size', zoomFactor * 100 + '%');
- t.container.find('.mejs-captions-text').css('line-height', 'normal');
- t.container.find('.mejs-captions-position').css('bottom', '45px');
- t.container.trigger('enteredfullscreen');
- },
- exitFullScreen: function() {
- var t = this;
- // Prevent container from attempting to stretch a second time
- clearTimeout(t.containerSizeTimeout);
- // firefox can't adjust plugins
- /*
- if (t.media.pluginType !== 'native' && mejs.MediaFeatures.isFirefox) {
- t.media.setFullscreen(false);
- //player.isFullScreen = false;
- return;
- }
- */
- // come out of native fullscreen
- if (mejs.MediaFeatures.hasTrueNativeFullScreen && (mejs.MediaFeatures.isFullScreen() || t.isFullScreen)) {
- mejs.MediaFeatures.cancelFullScreen();
- }
- // restore scroll bars to document
- $(document.documentElement).removeClass('mejs-fullscreen');
- t.container
- .removeClass('mejs-container-fullscreen')
- .width(t.normalWidth)
- .height(t.normalHeight);
- if (t.media.pluginType === 'native') {
- t.$media
- .width(t.normalWidth)
- .height(t.normalHeight);
- } else {
- t.container.find('.mejs-shim')
- .width(t.normalWidth)
- .height(t.normalHeight);
- t.media.setVideoSize(t.normalWidth, t.normalHeight);
- }
- t.layers.children('div')
- .width(t.normalWidth)
- .height(t.normalHeight);
- t.fullscreenBtn
- .removeClass('mejs-unfullscreen')
- .addClass('mejs-fullscreen');
- t.setControlsSize();
- t.isFullScreen = false;
- t.container.find('.mejs-captions-text').css('font-size','');
- t.container.find('.mejs-captions-text').css('line-height', '');
- t.container.find('.mejs-captions-position').css('bottom', '');
- t.container.trigger('exitedfullscreen');
- }
- });
- })(mejs.$);
- (function($) {
- // Speed
- $.extend(mejs.MepDefaults, {
- // We also support to pass object like this:
- // [{name: 'Slow', value: '0.75'}, {name: 'Normal', value: '1.00'}, ...]
- speeds: ['2.00', '1.50', '1.25', '1.00', '0.75'],
- defaultSpeed: '1.00',
-
- speedChar: 'x'
- });
- $.extend(MediaElementPlayer.prototype, {
- buildspeed: function(player, controls, layers, media) {
- var t = this;
- if (t.media.pluginType == 'native') {
- var
- speedButton = null,
- speedSelector = null,
- playbackSpeed = null,
- inputId = null;
- var speeds = [];
- var defaultInArray = false;
- for (var i=0, len=t.options.speeds.length; i < len; i++) {
- var s = t.options.speeds[i];
- if (typeof(s) === 'string'){
- speeds.push({
- name: s + t.options.speedChar,
- value: s
- });
- if(s === t.options.defaultSpeed) {
- defaultInArray = true;
- }
- }
- else {
- speeds.push(s);
- if(s.value === t.options.defaultSpeed) {
- defaultInArray = true;
- }
- }
- }
- if (!defaultInArray) {
- speeds.push({
- name: t.options.defaultSpeed + t.options.speedChar,
- value: t.options.defaultSpeed
- });
- }
- speeds.sort(function(a, b) {
- return parseFloat(b.value) - parseFloat(a.value);
- });
- var getSpeedNameFromValue = function(value) {
- for(i=0,len=speeds.length; i <len; i++) {
- if (speeds[i].value === value) {
- return speeds[i].name;
- }
- }
- };
- var html = '<div class="mejs-button mejs-speed-button">' +
- '<button type="button">' + getSpeedNameFromValue(t.options.defaultSpeed) + '</button>' +
- '<div class="mejs-speed-selector">' +
- '<ul>';
- for (i = 0, il = speeds.length; i<il; i++) {
- inputId = t.id + '-speed-' + speeds[i].value;
- html += '<li>' +
- '<input type="radio" name="speed" ' +
- 'value="' + speeds[i].value + '" ' +
- 'id="' + inputId + '" ' +
- (speeds[i].value === t.options.defaultSpeed ? ' checked' : '') +
- ' />' +
- '<label for="' + inputId + '" ' +
- (speeds[i].value === t.options.defaultSpeed ? ' class="mejs-speed-selected"' : '') +
- '>' + speeds[i].name + '</label>' +
- '</li>';
- }
- html += '</ul></div></div>';
- speedButton = $(html).appendTo(controls);
- speedSelector = speedButton.find('.mejs-speed-selector');
- playbackSpeed = t.options.defaultSpeed;
- media.addEventListener('loadedmetadata', function(e) {
- if (playbackSpeed) {
- media.playbackRate = parseFloat(playbackSpeed);
- }
- }, true);
- speedSelector
- .on('click', 'input[type="radio"]', function() {
- var newSpeed = $(this).attr('value');
- playbackSpeed = newSpeed;
- media.playbackRate = parseFloat(newSpeed);
- speedButton.find('button').html(getSpeedNameFromValue(newSpeed));
- speedButton.find('.mejs-speed-selected').removeClass('mejs-speed-selected');
- speedButton.find('input[type="radio"]:checked').next().addClass('mejs-speed-selected');
- });
- speedButton
- .one( 'mouseenter focusin', function() {
- speedSelector
- .height(
- speedButton.find('.mejs-speed-selector ul').outerHeight(true) +
- speedButton.find('.mejs-speed-translations').outerHeight(true))
- .css('top', (-1 * speedSelector.height()) + 'px');
- });
- }
- }
- });
- })(mejs.$);
- (function($) {
- // add extra default options
- $.extend(mejs.MepDefaults, {
- // this will automatically turn on a <track>
- startLanguage: '',
- tracksText: '',
- // By default, no WAI-ARIA live region - don't make a
- // screen reader speak captions over an audio track.
- tracksAriaLive: false,
- // option to remove the [cc] button when no <track kind="subtitles"> are present
- hideCaptionsButtonWhenEmpty: true,
- // If true and we only have one track, change captions to popup
- toggleCaptionsButtonWhenOnlyOne: false,
- // #id or .class
- slidesSelector: ''
- });
- $.extend(MediaElementPlayer.prototype, {
- hasChapters: false,
- cleartracks: function(player, controls, layers, media){
- if(player) {
- if(player.captions) player.captions.remove();
- if(player.chapters) player.chapters.remove();
- if(player.captionsText) player.captionsText.remove();
- if(player.captionsButton) player.captionsButton.remove();
- }
- },
- buildtracks: function(player, controls, layers, media) {
- if (player.tracks.length === 0)
- return;
- var t = this,
- attr = t.options.tracksAriaLive ?
- 'role="log" aria-live="assertive" aria-atomic="false"' : '',
- tracksTitle = t.options.tracksText ? t.options.tracksText : mejs.i18n.t('mejs.captions-subtitles'),
- i,
- kind;
- if (t.domNode.textTracks) { // if browser will do native captions, prefer mejs captions, loop through tracks and hide
- for (i = t.domNode.textTracks.length - 1; i >= 0; i--) {
- t.domNode.textTracks[i].mode = "hidden";
- }
- }
- t.cleartracks(player, controls, layers, media);
- player.chapters =
- $('<div class="mejs-chapters mejs-layer"></div>')
- .prependTo(layers).hide();
- player.captions =
- $('<div class="mejs-captions-layer mejs-layer"><div class="mejs-captions-position mejs-captions-position-hover" ' +
- attr + '><span class="mejs-captions-text"></span></div></div>')
- .prependTo(layers).hide();
- player.captionsText = player.captions.find('.mejs-captions-text');
- player.captionsButton =
- $('<div class="mejs-button mejs-captions-button">'+
- '<button type="button" aria-controls="' + t.id + '" title="' + tracksTitle + '" aria-label="' + tracksTitle + '"></button>'+
- '<div class="mejs-captions-selector">'+
- '<ul>'+
- '<li>'+
- '<input type="radio" name="' + player.id + '_captions" id="' + player.id + '_captions_none" value="none" checked="checked" />' +
- '<label for="' + player.id + '_captions_none">' + mejs.i18n.t('mejs.none') +'</label>'+
- '</li>' +
- '</ul>'+
- '</div>'+
- '</div>')
- .appendTo(controls);
- var subtitleCount = 0;
- for (i=0; i<player.tracks.length; i++) {
- kind = player.tracks[i].kind;
- if (kind === 'subtitles' || kind === 'captions') {
- subtitleCount++;
- }
- }
- // if only one language then just make the button a toggle
- if (t.options.toggleCaptionsButtonWhenOnlyOne && subtitleCount == 1){
- // click
- player.captionsButton.on('click',function() {
- if (player.selectedTrack === null) {
- lang = player.tracks[0].srclang;
- } else {
- lang = 'none';
- }
- player.setTrack(lang);
- });
- } else {
- // hover or keyboard focus
- player.captionsButton.on( 'mouseenter focusin', function() {
- $(this).find('.mejs-captions-selector').removeClass('mejs-offscreen');
- })
- // handle clicks to the language radio buttons
- .on('click','input[type=radio]',function() {
- lang = this.value;
- player.setTrack(lang);
- });
- player.captionsButton.on( 'mouseleave focusout', function() {
- $(this).find(".mejs-captions-selector").addClass("mejs-offscreen");
- });
- }
- if (!player.options.alwaysShowControls) {
- // move with controls
- player.container
- .bind('controlsshown', function () {
- // push captions above controls
- player.container.find('.mejs-captions-position').addClass('mejs-captions-position-hover');
- })
- .bind('controlshidden', function () {
- if (!media.paused) {
- // move back to normal place
- player.container.find('.mejs-captions-position').removeClass('mejs-captions-position-hover');
- }
- });
- } else {
- player.container.find('.mejs-captions-position').addClass('mejs-captions-position-hover');
- }
- player.trackToLoad = -1;
- player.selectedTrack = null;
- player.isLoadingTrack = false;
- // add to list
- for (i=0; i<player.tracks.length; i++) {
- kind = player.tracks[i].kind;
- if (kind === 'subtitles' || kind === 'captions') {
- player.addTrackButton(player.tracks[i].srclang, player.tracks[i].label);
- }
- }
- // start loading tracks
- player.loadNextTrack();
- media.addEventListener('timeupdate',function() {
- player.displayCaptions();
- }, false);
- if (player.options.slidesSelector !== '') {
- player.slidesContainer = $(player.options.slidesSelector);
- media.addEventListener('timeupdate',function() {
- player.displaySlides();
- }, false);
- }
- media.addEventListener('loadedmetadata', function() {
- player.displayChapters();
- }, false);
- player.container.hover(
- function () {
- // chapters
- if (player.hasChapters) {
- player.chapters.removeClass('mejs-offscreen');
- player.chapters.fadeIn(200).height(player.chapters.find('.mejs-chapter').outerHeight());
- }
- },
- function () {
- if (player.hasChapters && !media.paused) {
- player.chapters.fadeOut(200, function() {
- $(this).addClass('mejs-offscreen');
- $(this).css('display','block');
- });
- }
- });
- t.container.on('controlsresize', function() {
- t.adjustLanguageBox();
- });
- // check for autoplay
- if (player.node.getAttribute('autoplay') !== null) {
- player.chapters.addClass('mejs-offscreen');
- }
- },
- setTrack: function(lang){
- var t = this,
- i;
- if (lang == 'none') {
- t.selectedTrack = null;
- t.captionsButton.removeClass('mejs-captions-enabled');
- } else {
- for (i=0; i<t.tracks.length; i++) {
- if (t.tracks[i].srclang == lang) {
- if (t.selectedTrack === null)
- t.captionsButton.addClass('mejs-captions-enabled');
- t.selectedTrack = t.tracks[i];
- t.captions.attr('lang', t.selectedTrack.srclang);
- t.displayCaptions();
- break;
- }
- }
- }
- },
- loadNextTrack: function() {
- var t = this;
- t.trackToLoad++;
- if (t.trackToLoad < t.tracks.length) {
- t.isLoadingTrack = true;
- t.loadTrack(t.trackToLoad);
- } else {
- // add done?
- t.isLoadingTrack = false;
- t.checkForTracks();
- }
- },
- loadTrack: function(index){
- var
- t = this,
- track = t.tracks[index],
- after = function() {
- track.isLoaded = true;
- t.enableTrackButton(track.srclang, track.label);
- t.loadNextTrack();
- };
- if (track.src !== undefined || track.src !== "") {
- $.ajax({
- url: track.src,
- dataType: "text",
- success: function(d) {
- // parse the loaded file
- if (typeof d == "string" && (/<tt\s+xml/ig).exec(d)) {
- track.entries = mejs.TrackFormatParser.dfxp.parse(d);
- } else {
- track.entries = mejs.TrackFormatParser.webvtt.parse(d);
- }
- after();
- if (track.kind == 'chapters') {
- t.media.addEventListener('play', function() {
- if (t.media.duration > 0) {
- t.displayChapters(track);
- }
- }, false);
- }
- if (track.kind == 'slides') {
- t.setupSlides(track);
- }
- },
- error: function() {
- t.removeTrackButton(track.srclang);
- t.loadNextTrack();
- }
- });
- }
- },
- enableTrackButton: function(lang, label) {
- var t = this;
- if (label === '') {
- label = mejs.language.codes[lang] || lang;
- }
- t.captionsButton
- .find('input[value=' + lang + ']')
- .prop('disabled',false)
- .siblings('label')
- .html( label );
- // auto select
- if (t.options.startLanguage == lang) {
- $('#' + t.id + '_captions_' + lang).prop('checked', true).trigger('click');
- }
- t.adjustLanguageBox();
- },
- removeTrackButton: function(lang) {
- var t = this;
- t.captionsButton.find('input[value=' + lang + ']').closest('li').remove();
- t.adjustLanguageBox();
- },
- addTrackButton: function(lang, label) {
- var t = this;
- if (label === '') {
- label = mejs.language.codes[lang] || lang;
- }
- t.captionsButton.find('ul').append(
- $('<li>'+
- '<input type="radio" name="' + t.id + '_captions" id="' + t.id + '_captions_' + lang + '" value="' + lang + '" disabled="disabled" />' +
- '<label for="' + t.id + '_captions_' + lang + '">' + label + ' (loading)' + '</label>'+
- '</li>')
- );
- t.adjustLanguageBox();
- // remove this from the dropdownlist (if it exists)
- t.container.find('.mejs-captions-translations option[value=' + lang + ']').remove();
- },
- adjustLanguageBox:function() {
- var t = this;
- // adjust the size of the outer box
- t.captionsButton.find('.mejs-captions-selector').height(
- t.captionsButton.find('.mejs-captions-selector ul').outerHeight(true) +
- t.captionsButton.find('.mejs-captions-translations').outerHeight(true)
- );
- },
- checkForTracks: function() {
- var
- t = this,
- hasSubtitles = false;
- // check if any subtitles
- if (t.options.hideCaptionsButtonWhenEmpty) {
- for (var i=0; i<t.tracks.length; i++) {
- var kind = t.tracks[i].kind;
- if ((kind === 'subtitles' || kind === 'captions') && t.tracks[i].isLoaded) {
- hasSubtitles = true;
- break;
- }
- }
- if (!hasSubtitles) {
- t.captionsButton.hide();
- t.setControlsSize();
- }
- }
- },
- displayCaptions: function() {
- if (typeof this.tracks == 'undefined')
- return;
- var
- t = this,
- i,
- track = t.selectedTrack;
- if (track !== null && track.isLoaded) {
- for (i=0; i<track.entries.times.length; i++) {
- if (t.media.currentTime >= track.entries.times[i].start && t.media.currentTime <= track.entries.times[i].stop) {
- // Set the line before the timecode as a class so the cue can be targeted if needed
- t.captionsText.html(track.entries.text[i]).attr('class', 'mejs-captions-text ' + (track.entries.times[i].identifier || ''));
- t.captions.show().height(0);
- return; // exit out if one is visible;
- }
- }
- t.captions.hide();
- } else {
- t.captions.hide();
- }
- },
- setupSlides: function(track) {
- var t = this;
- t.slides = track;
- t.slides.entries.imgs = [t.slides.entries.text.length];
- t.showSlide(0);
- },
- showSlide: function(index) {
- if (typeof this.tracks == 'undefined' || typeof this.slidesContainer == 'undefined') {
- return;
- }
- var t = this,
- url = t.slides.entries.text[index],
- img = t.slides.entries.imgs[index];
- if (typeof img == 'undefined' || typeof img.fadeIn == 'undefined') {
- t.slides.entries.imgs[index] = img = $('<img src="' + url + '">')
- .on('load', function() {
- img.appendTo(t.slidesContainer)
- .hide()
- .fadeIn()
- .siblings(':visible')
- .fadeOut();
- });
- } else {
- if (!img.is(':visible') && !img.is(':animated')) {
- //
- img.fadeIn()
- .siblings(':visible')
- .fadeOut();
- }
- }
- },
- displaySlides: function() {
- if (typeof this.slides == 'undefined')
- return;
- var
- t = this,
- slides = t.slides,
- i;
- for (i=0; i<slides.entries.times.length; i++) {
- if (t.media.currentTime >= slides.entries.times[i].start && t.media.currentTime <= slides.entries.times[i].stop){
- t.showSlide(i);
- return; // exit out if one is visible;
- }
- }
- },
- displayChapters: function() {
- var
- t = this,
- i;
- for (i=0; i<t.tracks.length; i++) {
- if (t.tracks[i].kind == 'chapters' && t.tracks[i].isLoaded) {
- t.drawChapters(t.tracks[i]);
- t.hasChapters = true;
- break;
- }
- }
- },
- drawChapters: function(chapters) {
- var
- t = this,
- i,
- dur,
- //width,
- //left,
- percent = 0,
- usedPercent = 0;
- t.chapters.empty();
- for (i=0; i<chapters.entries.times.length; i++) {
- dur = chapters.entries.times[i].stop - chapters.entries.times[i].start;
- percent = Math.floor(dur / t.media.duration * 100);
- if (percent + usedPercent > 100 || // too large
- i == chapters.entries.times.length-1 && percent + usedPercent < 100) // not going to fill it in
- {
- percent = 100 - usedPercent;
- }
- //width = Math.floor(t.width * dur / t.media.duration);
- //left = Math.floor(t.width * chapters.entries.times[i].start / t.media.duration);
- //if (left + width > t.width) {
- // width = t.width - left;
- //}
- t.chapters.append( $(
- '<div class="mejs-chapter" rel="' + chapters.entries.times[i].start + '" style="left: ' + usedPercent.toString() + '%;width: ' + percent.toString() + '%;">' +
- '<div class="mejs-chapter-block' + ((i==chapters.entries.times.length-1) ? ' mejs-chapter-block-last' : '') + '">' +
- '<span class="ch-title">' + chapters.entries.text[i] + '</span>' +
- '<span class="ch-time">' + mejs.Utility.secondsToTimeCode(chapters.entries.times[i].start, t.options) + '–' + mejs.Utility.secondsToTimeCode(chapters.entries.times[i].stop, t.options) + '</span>' +
- '</div>' +
- '</div>'));
- usedPercent += percent;
- }
- t.chapters.find('div.mejs-chapter').click(function() {
- t.media.setCurrentTime( parseFloat( $(this).attr('rel') ) );
- if (t.media.paused) {
- t.media.play();
- }
- });
- t.chapters.show();
- }
- });
- mejs.language = {
- codes: {
- af:'Afrikaans',
- sq:'Albanian',
- ar:'Arabic',
- be:'Belarusian',
- bg:'Bulgarian',
- ca:'Catalan',
- zh:'Chinese',
- 'zh-cn':'Chinese Simplified',
- 'zh-tw':'Chinese Traditional',
- hr:'Croatian',
- cs:'Czech',
- da:'Danish',
- nl:'Dutch',
- en:'English',
- et:'Estonian',
- fl:'Filipino',
- fi:'Finnish',
- fr:'French',
- gl:'Galician',
- de:'German',
- el:'Greek',
- ht:'Haitian Creole',
- iw:'Hebrew',
- hi:'Hindi',
- hu:'Hungarian',
- is:'Icelandic',
- id:'Indonesian',
- ga:'Irish',
- it:'Italian',
- ja:'Japanese',
- ko:'Korean',
- lv:'Latvian',
- lt:'Lithuanian',
- mk:'Macedonian',
- ms:'Malay',
- mt:'Maltese',
- no:'Norwegian',
- fa:'Persian',
- pl:'Polish',
- pt:'Portuguese',
- // 'pt-pt':'Portuguese (Portugal)',
- ro:'Romanian',
- ru:'Russian',
- sr:'Serbian',
- sk:'Slovak',
- sl:'Slovenian',
- es:'Spanish',
- sw:'Swahili',
- sv:'Swedish',
- tl:'Tagalog',
- th:'Thai',
- tr:'Turkish',
- uk:'Ukrainian',
- vi:'Vietnamese',
- cy:'Welsh',
- yi:'Yiddish'
- }
- };
- /*
- Parses WebVTT format which should be formatted as
- ================================
- WEBVTT
- 1
- 00:00:01,1 --> 00:00:05,000
- A line of text
- 2
- 00:01:15,1 --> 00:02:05,000
- A second line of text
- ===============================
- Adapted from: http://www.delphiki.com/html5/playr
- */
- mejs.TrackFormatParser = {
- webvtt: {
- pattern_timecode: /^((?:[0-9]{1,2}:)?[0-9]{2}:[0-9]{2}([,.][0-9]{1,3})?) --\> ((?:[0-9]{1,2}:)?[0-9]{2}:[0-9]{2}([,.][0-9]{3})?)(.*)$/,
- parse: function(trackText) {
- var
- i = 0,
- lines = mejs.TrackFormatParser.split2(trackText, /\r?\n/),
- entries = {text:[], times:[]},
- timecode,
- text,
- identifier;
- for(; i<lines.length; i++) {
- timecode = this.pattern_timecode.exec(lines[i]);
- if (timecode && i<lines.length) {
- if ((i - 1) >= 0 && lines[i - 1] !== '') {
- identifier = lines[i - 1];
- }
- i++;
- // grab all the (possibly multi-line) text that follows
- text = lines[i];
- i++;
- while(lines[i] !== '' && i<lines.length){
- text = text + '\n' + lines[i];
- i++;
- }
- text = $.trim(text).replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, "<a href='$1' target='_blank'>$1</a>");
- // Text is in a different array so I can use .join
- entries.text.push(text);
- entries.times.push(
- {
- identifier: identifier,
- start: (mejs.Utility.convertSMPTEtoSeconds(timecode[1]) === 0) ? 0.200 : mejs.Utility.convertSMPTEtoSeconds(timecode[1]),
- stop: mejs.Utility.convertSMPTEtoSeconds(timecode[3]),
- settings: timecode[5]
- });
- }
- identifier = '';
- }
- return entries;
- }
- },
- // Thanks to Justin Capella: https://github.com/johndyer/mediaelement/pull/420
- dfxp: {
- parse: function(trackText) {
- trackText = $(trackText).filter("tt");
- var
- i = 0,
- container = trackText.children("div").eq(0),
- lines = container.find("p"),
- styleNode = trackText.find("#" + container.attr("style")),
- styles,
- text,
- entries = {text:[], times:[]};
- if (styleNode.length) {
- var attributes = styleNode.removeAttr("id").get(0).attributes;
- if (attributes.length) {
- styles = {};
- for (i = 0; i < attributes.length; i++) {
- styles[attributes[i].name.split(":")[1]] = attributes[i].value;
- }
- }
- }
- for(i = 0; i<lines.length; i++) {
- var style;
- var _temp_times = {
- start: null,
- stop: null,
- style: null
- };
- if (lines.eq(i).attr("begin")) _temp_times.start = mejs.Utility.convertSMPTEtoSeconds(lines.eq(i).attr("begin"));
- if (!_temp_times.start && lines.eq(i-1).attr("end")) _temp_times.start = mejs.Utility.convertSMPTEtoSeconds(lines.eq(i-1).attr("end"));
- if (lines.eq(i).attr("end")) _temp_times.stop = mejs.Utility.convertSMPTEtoSeconds(lines.eq(i).attr("end"));
- if (!_temp_times.stop && lines.eq(i+1).attr("begin")) _temp_times.stop = mejs.Utility.convertSMPTEtoSeconds(lines.eq(i+1).attr("begin"));
- if (styles) {
- style = "";
- for (var _style in styles) {
- style += _style + ":" + styles[_style] + ";";
- }
- }
- if (style) _temp_times.style = style;
- if (_temp_times.start === 0) _temp_times.start = 0.200;
- entries.times.push(_temp_times);
- text = $.trim(lines.eq(i).html()).replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, "<a href='$1' target='_blank'>$1</a>");
- entries.text.push(text);
- }
- return entries;
- }
- },
- split2: function (text, regex) {
- // normal version for compliant browsers
- // see below for IE fix
- return text.split(regex);
- }
- };
- // test for browsers with bad String.split method.
- if ('x\n\ny'.split(/\n/gi).length != 3) {
- // add super slow IE8 and below version
- mejs.TrackFormatParser.split2 = function(text, regex) {
- var
- parts = [],
- chunk = '',
- i;
- for (i=0; i<text.length; i++) {
- chunk += text.substring(i,i+1);
- if (regex.test(chunk)) {
- parts.push(chunk.replace(regex, ''));
- chunk = '';
- }
- }
- parts.push(chunk);
- return parts;
- };
- }
- })(mejs.$);
- // Source Chooser Plugin
- (function($) {
- $.extend(mejs.MepDefaults, {
- sourcechooserText: ''
- });
- $.extend(MediaElementPlayer.prototype, {
- buildsourcechooser: function(player, controls, layers, media) {
- var
- t = this,
- sourceTitle = t.options.sourcechooserText ? t.options.sourcechooserText : mejs.i18n.t('mejs.source-chooser'),
- hoverTimeout
- ;
- player.sourcechooserButton =
- $('<div class="mejs-button mejs-sourcechooser-button">'+
- '<button type="button" role="button" aria-haspopup="true" aria-owns="' + t.id + '" title="' + sourceTitle + '" aria-label="' + sourceTitle + '"></button>'+
- '<div class="mejs-sourcechooser-selector mejs-offscreen" role="menu" aria-expanded="false" aria-hidden="true">'+
- '<ul>'+
- '</ul>'+
- '</div>'+
- '</div>')
- .appendTo(controls)
- // hover
- .hover(function() {
- clearTimeout(hoverTimeout);
- player.showSourcechooserSelector();
- }, function() {
- var self = $(this);
- hoverTimeout = setTimeout(function () {
- player.hideSourcechooserSelector();
- }, 500);
- })
- // keyboard menu activation
- .on('keydown', function (e) {
- var keyCode = e.keyCode;
- switch (keyCode) {
- case 32: // space
- if (!mejs.MediaFeatures.isFirefox) { // space sends the click event in Firefox
- player.showSourcechooserSelector();
- }
- $(this).find('.mejs-sourcechooser-selector')
- .find('input[type=radio]:checked').first().focus();
- break;
- case 13: // enter
- player.showSourcechooserSelector();
- $(this).find('.mejs-sourcechooser-selector')
- .find('input[type=radio]:checked').first().focus();
- break;
- case 27: // esc
- player.hideSourcechooserSelector();
- $(this).find('button').focus();
- break;
- default:
- return true;
- }
- })
- // close menu when tabbing away
- .on('focusout', mejs.Utility.debounce(function (e) { // Safari triggers focusout multiple times
- // Firefox does NOT support e.relatedTarget to see which element
- // just lost focus, so wait to find the next focused element
- setTimeout(function () {
- var parent = $(document.activeElement).closest('.mejs-sourcechooser-selector');
- if (!parent.length) {
- // focus is outside the control; close menu
- player.hideSourcechooserSelector();
- }
- }, 0);
- }, 100))
- // handle clicks to the source radio buttons
- .delegate('input[type=radio]', 'click', function() {
- // set aria states
- $(this).attr('aria-selected', true).attr('checked', 'checked');
- $(this).closest('.mejs-sourcechooser-selector').find('input[type=radio]').not(this).attr('aria-selected', 'false').removeAttr('checked');
- var src = this.value;
- if (media.currentSrc != src) {
- var currentTime = media.currentTime;
- var paused = media.paused;
- media.pause();
- media.setSrc(src);
- media.addEventListener('loadedmetadata', function(e) {
- media.currentTime = currentTime;
- }, true);
- var canPlayAfterSourceSwitchHandler = function(e) {
- if (!paused) {
- media.play();
- }
- media.removeEventListener("canplay", canPlayAfterSourceSwitchHandler, true);
- };
- media.addEventListener('canplay', canPlayAfterSourceSwitchHandler, true);
- media.load();
- }
- })
- // Handle click so that screen readers can toggle the menu
- .delegate('button', 'click', function (e) {
- if ($(this).siblings('.mejs-sourcechooser-selector').hasClass('mejs-offscreen')) {
- player.showSourcechooserSelector();
- $(this).siblings('.mejs-sourcechooser-selector').find('input[type=radio]:checked').first().focus();
- } else {
- player.hideSourcechooserSelector();
- }
- });
- // add to list
- for (var i in this.node.children) {
- var src = this.node.children[i];
- if (src.nodeName === 'SOURCE' && (media.canPlayType(src.type) == 'probably' || media.canPlayType(src.type) == 'maybe')) {
- player.addSourceButton(src.src, src.title, src.type, media.src == src.src);
- }
- }
- },
- addSourceButton: function(src, label, type, isCurrent) {
- var t = this;
- if (label === '' || label == undefined) {
- label = src;
- }
- type = type.split('/')[1];
- t.sourcechooserButton.find('ul').append(
- $('<li>'+
- '<input type="radio" name="' + t.id + '_sourcechooser" id="' + t.id + '_sourcechooser_' + label + type + '" role="menuitemradio" value="' + src + '" ' + (isCurrent ? 'checked="checked"' : '') + 'aria-selected="' + isCurrent + '"' + ' />'+
- '<label for="' + t.id + '_sourcechooser_' + label + type + '" aria-hidden="true">' + label + ' (' + type + ')</label>'+
- '</li>')
- );
- t.adjustSourcechooserBox();
- },
- adjustSourcechooserBox: function() {
- var t = this;
- // adjust the size of the outer box
- t.sourcechooserButton.find('.mejs-sourcechooser-selector').height(
- t.sourcechooserButton.find('.mejs-sourcechooser-selector ul').outerHeight(true)
- );
- },
- hideSourcechooserSelector: function () {
- this.sourcechooserButton.find('.mejs-sourcechooser-selector')
- .addClass('mejs-offscreen')
- .attr('aria-expanded', 'false')
- .attr('aria-hidden', 'true')
- .find('input[type=radio]') // make radios not fucusable
- .attr('tabindex', '-1');
- },
- showSourcechooserSelector: function () {
- this.sourcechooserButton.find('.mejs-sourcechooser-selector')
- .removeClass('mejs-offscreen')
- .attr('aria-expanded', 'true')
- .attr('aria-hidden', 'false')
- .find('input[type=radio]')
- .attr('tabindex', '0');
- }
- });
- })(mejs.$);
- /*
- * ContextMenu Plugin
- *
- *
- */
- (function($) {
- $.extend(mejs.MepDefaults,
- { 'contextMenuItems': [
- // demo of a fullscreen option
- {
- render: function(player) {
-
- // check for fullscreen plugin
- if (typeof player.enterFullScreen == 'undefined')
- return null;
-
- if (player.isFullScreen) {
- return mejs.i18n.t('mejs.fullscreen-off');
- } else {
- return mejs.i18n.t('mejs.fullscreen-on');
- }
- },
- click: function(player) {
- if (player.isFullScreen) {
- player.exitFullScreen();
- } else {
- player.enterFullScreen();
- }
- }
- }
- ,
- // demo of a mute/unmute button
- {
- render: function(player) {
- if (player.media.muted) {
- return mejs.i18n.t('mejs.unmute');
- } else {
- return mejs.i18n.t('mejs.mute');
- }
- },
- click: function(player) {
- if (player.media.muted) {
- player.setMuted(false);
- } else {
- player.setMuted(true);
- }
- }
- },
- // separator
- {
- isSeparator: true
- }
- ,
- // demo of simple download video
- {
- render: function(player) {
- return mejs.i18n.t('mejs.download-video');
- },
- click: function(player) {
- window.location.href = player.media.currentSrc;
- }
- }
- ]}
- );
- $.extend(MediaElementPlayer.prototype, {
- buildcontextmenu: function(player, controls, layers, media) {
-
- // create context menu
- player.contextMenu = $('<div class="mejs-contextmenu"></div>')
- .appendTo($('body'))
- .hide();
-
- // create events for showing context menu
- player.container.bind('contextmenu', function(e) {
- if (player.isContextMenuEnabled) {
- e.preventDefault();
- player.renderContextMenu(e.clientX-1, e.clientY-1);
- return false;
- }
- });
- player.container.bind('click', function() {
- player.contextMenu.hide();
- });
- player.contextMenu.bind('mouseleave', function() {
- //
- player.startContextMenuTimer();
-
- });
- },
- cleancontextmenu: function(player) {
- player.contextMenu.remove();
- },
-
- isContextMenuEnabled: true,
- enableContextMenu: function() {
- this.isContextMenuEnabled = true;
- },
- disableContextMenu: function() {
- this.isContextMenuEnabled = false;
- },
-
- contextMenuTimeout: null,
- startContextMenuTimer: function() {
- //
-
- var t = this;
-
- t.killContextMenuTimer();
-
- t.contextMenuTimer = setTimeout(function() {
- t.hideContextMenu();
- t.killContextMenuTimer();
- }, 750);
- },
- killContextMenuTimer: function() {
- var timer = this.contextMenuTimer;
-
- //
-
- if (timer != null) {
- clearTimeout(timer);
- delete timer;
- timer = null;
- }
- },
-
- hideContextMenu: function() {
- this.contextMenu.hide();
- },
-
- renderContextMenu: function(x,y) {
-
- // alway re-render the items so that things like "turn fullscreen on" and "turn fullscreen off" are always written correctly
- var t = this,
- html = '',
- items = t.options.contextMenuItems;
-
- for (var i=0, il=items.length; i<il; i++) {
-
- if (items[i].isSeparator) {
- html += '<div class="mejs-contextmenu-separator"></div>';
- } else {
-
- var rendered = items[i].render(t);
-
- // render can return null if the item doesn't need to be used at the moment
- if (rendered != null) {
- html += '<div class="mejs-contextmenu-item" data-itemindex="' + i + '" id="element-' + (Math.random()*1000000) + '">' + rendered + '</div>';
- }
- }
- }
-
- // position and show the context menu
- t.contextMenu
- .empty()
- .append($(html))
- .css({top:y, left:x})
- .show();
-
- // bind events
- t.contextMenu.find('.mejs-contextmenu-item').each(function() {
-
- // which one is this?
- var $dom = $(this),
- itemIndex = parseInt( $dom.data('itemindex'), 10 ),
- item = t.options.contextMenuItems[itemIndex];
-
- // bind extra functionality?
- if (typeof item.show != 'undefined')
- item.show( $dom , t);
-
- // bind click action
- $dom.click(function() {
- // perform click action
- if (typeof item.click != 'undefined')
- item.click(t);
-
- // close
- t.contextMenu.hide();
- });
- });
-
- // stop the controls from hiding
- setTimeout(function() {
- t.killControlsTimer('rev3');
- }, 100);
-
- }
- });
-
- })(mejs.$);
- (function($) {
- // skip back button
- $.extend(mejs.MepDefaults, {
- skipBackInterval: 30,
- // %1 will be replaced with skipBackInterval in this string
- skipBackText: ''
- });
- $.extend(MediaElementPlayer.prototype, {
- buildskipback: function(player, controls, layers, media) {
- var
- t = this,
- defaultTitle = mejs.i18n.t('mejs.time-skip-back', t.options.skipBackInterval),
- skipTitle = t.options.skipBackText ? t.options.skipBackText : defaultTitle,
- // create the loop button
- loop =
- $('<div class="mejs-button mejs-skip-back-button">' +
- '<button type="button" aria-controls="' + t.id + '" title="' + skipTitle + '" aria-label="' + skipTitle + '">' + t.options.skipBackInterval + '</button>' +
- '</div>')
- // append it to the toolbar
- .appendTo(controls)
- // add a click toggle event
- .click(function() {
- media.setCurrentTime(Math.max(media.currentTime - t.options.skipBackInterval, 0));
- $(this).find('button').blur();
- });
- }
- });
- })(mejs.$);
- /**
- * Postroll plugin
- */
- (function($) {
- $.extend(mejs.MepDefaults, {
- postrollCloseText: ''
- });
- // Postroll
- $.extend(MediaElementPlayer.prototype, {
- buildpostroll: function(player, controls, layers, media) {
- var
- t = this,
- postrollTitle = t.options.postrollCloseText ? t.options.postrollCloseText : mejs.i18n.t('mejs.close'),
- postrollLink = t.container.find('link[rel="postroll"]').attr('href');
- if (typeof postrollLink !== 'undefined') {
- player.postroll =
- $('<div class="mejs-postroll-layer mejs-layer"><a class="mejs-postroll-close" onclick="$(this).parent().hide();return false;">' + postrollTitle + '</a><div class="mejs-postroll-layer-content"></div></div>').prependTo(layers).hide();
- t.media.addEventListener('ended', function (e) {
- $.ajax({
- dataType: 'html',
- url: postrollLink,
- success: function (data, textStatus) {
- layers.find('.mejs-postroll-layer-content').html(data);
- }
- });
- player.postroll.show();
- }, false);
- }
- }
- });
- })(mejs.$);
- /*
- MediaElement-Markers is a MediaElement.js plugin that lets you add Visual Cues in the progress time rail.
- This plugin also lets you register a custom callback function that will be called everytime the play position reaches a marker.
- Marker position and a reference to the MediaElement Player object is passed to the registered callback function for any post processing. Marker color is configurable.
- */
- (function ($) {
- // markers
- $.extend(mejs.MepDefaults, {
- markerColor: '#E9BC3D', //default marker color
- markers: [],
- markerCallback: function () {
- }
- });
- $.extend(MediaElementPlayer.prototype, {
- buildmarkers: function (player, controls, layers, media) {
- var t = this,
- i = 0,
- currentPos = -1,
- currentMarker = -1,
- lastPlayPos = -1, //Track backward seek
- lastMarkerCallBack = -1; //Prevents successive firing of callbacks
- for (i = 0; i < player.options.markers.length; ++i) {
- controls.find('.mejs-time-total').append('<span class="mejs-time-marker"></span>');
- }
- media.addEventListener('durationchange', function (e) {
- player.setmarkers(controls);
- });
- media.addEventListener('timeupdate', function (e) {
- currentPos = Math.floor(media.currentTime);
- if (lastPlayPos > currentPos) {
- if (lastMarkerCallBack > currentPos) {
- lastMarkerCallBack = -1;
- }
- } else {
- lastPlayPos = currentPos;
- }
- for (i = 0; i < player.options.markers.length; ++i) {
- currentMarker = Math.floor(player.options.markers[i]);
- if (currentPos === currentMarker && currentMarker !== lastMarkerCallBack) {
- player.options.markerCallback(media, media.currentTime); //Fires the callback function
- lastMarkerCallBack = currentMarker;
- }
- }
- }, false);
- },
- setmarkers: function (controls) {
- var t = this,
- i = 0,
- left;
- for (i = 0; i < t.options.markers.length; ++i) {
- if (Math.floor(t.options.markers[i]) <= t.media.duration && Math.floor(t.options.markers[i]) >= 0) {
- left = 100 * Math.floor(t.options.markers[i]) / t.media.duration;
- $(controls.find('.mejs-time-marker')[i]).css({
- "width": "1px",
- "left": left+"%",
- "background": t.options.markerColor
- });
- }
- }
- }
- });
- })(mejs.$);
|