package Ġus . nin ew orld s . ser en ity . ui . video . player Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Intent Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Handler Ċ import Ġandroid . view . KeyEvent Ċ import Ġbutter knife . BindView Ċ import Ġbutter knife . B utter Kn ife . bind Ċ import Ġcom . are l lo mobile . mvp . presenter . Inject Presenter Ċ import Ġcom . are l lo mobile . mvp . presenter . Provide Presenter Ċ import Ġcom . google . android . ex op layer 2 . Exo Player Factory Ċ import Ġcom . google . android . ex op layer 2 . Simple Exo Player Ċ import Ġcom . google . android . ex op layer 2 . extractor . Default Extract ors Factory Ċ import Ġcom . google . android . ex op layer 2 . source . Extractor Media Source Ċ import Ġcom . google . android . ex op layer 2 . source . Media Source Ċ import Ġcom . google . android . ex op layer 2 . track selection . Mapping Track Selector Ċ import Ġcom . google . android . ex op layer 2 . ui . Simple Exo Player View Ċ import Ġcom . google . android . ex op layer 2 . upstream . DataSource Ċ import Ġus . nin ew orld s . ser en ity . R Ċ import Ġus . nin ew orld s . ser en ity . common . annotations . Open ForTesting Ċ import Ġus . nin ew orld s . ser en ity . core . logger . Logger Ċ import Ġus . nin ew orld s . ser en ity . injection . Video Player Handler Ċ import Ġus . nin ew orld s . ser en ity . ui . activity . Ser en ity Activity Ċ import Ġus . nin ew orld s . ser en ity . ui . util . Display Utils . over scan Comp ensation Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Provider Ċ Ċ @ Open ForTesting Ċ class ĠEx op layer Video Activity Ġ: ĠSer en ity Activity (), ĠEx op layer Contract . Ex op layer View Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġmedia DataSource Factory : ĠDataSource . Factory ĊĊĠ Ġ@ field :[ Inject ĠVideo Player Handler ] ĊĠ Ġlateinit Ġvar Ġvideo Player Handler : ĠHandler ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġtrack Selector : ĠMapping Track Selector ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġevent Logger : ĠEvent Logger ĊĊĠ Ġ@ Inject Presenter ĊĠ Ġlateinit Ġvar Ġpresenter : ĠEx op layer Presenter ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġpresenter Provider : ĠProvider < Ex op layer Presenter > ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġlog : ĠLogger ĊĊĠ Ġ@ BindView ( R . id . player _ view ) ĊĠ Ġinternal Ġlateinit Ġvar Ġplayer View : ĠSimple Exo Player View ĊĊĠ Ġlateinit Ġvar Ġplayer : ĠSimple Exo Player ĊĊĠ Ġprivate Ġval Ġprogress Reporting handler Ġ= ĠHandler () ĊĠ Ġprivate Ġval Ġprogress Runnable Ġ= ĠProgress Runnable () ĊĠ Ġprivate Ġvar Ġvideo Key Handler : ĠVideo KeyCode Handler Delegate ? Ġ= Ġnull ĊĊĠ Ġinternal Ġval ĠPROG RESS _ UPDATE _ DELAY Ġ= Ġ 5 0 0 0 L ĊĊĠ Ġ@ Provide Presenter ĊĠ Ġfun Ġprovide Presenter (): ĠEx op layer Presenter Ġ= Ġpresenter Provider . get () ĊĊĠ Ġoverride Ġfun Ġcreate Side Menu () Ġ{ ĊĠĠĠ Ġ// ĠDo ĠNothing Ġas Ġa Ġside Ġmenu Ġisn 't Ġneeded Ġin Ġthis Ġactivity ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ ex op layer _ video ) ĊĠĠĠ Ġbind ( this ) ĊĠĠĠ Ġover scan Comp ensation ( this , Ġwindow . decor View ) ĊĠ Ġ} ĊĊĠ Ġpublic Ġoverride Ġfun ĠonStart () Ġ{ ĊĠĠĠ Ġsuper . onStart () ĊĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ> ĠBuild . VERSION _ CODES . M ) Ġ{ ĊĠĠĠĠĠ Ġpresenter . play Back From Video Queue () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġpublic Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠ Ġsuper . on Resume () ĊĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ<= ĠBuild . VERSION _ CODES . M ) Ġ{ ĊĠĠĠĠĠ Ġpresenter . play Back From Video Queue () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġpublic Ġoverride Ġfun Ġon Pause () Ġ{ ĊĠĠĠ Ġsuper . on Pause () ĊĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ<= ĠBuild . VERSION _ CODES . M ) Ġ{ ĊĠĠĠĠĠ Ġrelease Player () ĊĠĠĠĠĠ Ġprogress Reporting handler . remove Callbacks ( progress Runnable ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġpublic Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠ Ġsuper . on Stop () ĊĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ> ĠBuild . VERSION _ CODES . M ) Ġ{ ĊĠĠĠĠĠ Ġrelease Player () ĊĠĠĠĠĠ Ġprogress Reporting handler . remove Callbacks ( progress Runnable ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġfinish () Ġ{ ĊĠĠĠ Ġset Exit ResultCode Finished () ĊĠĠĠ Ġprogress Reporting handler . remove Callbacks ( progress Runnable ) ĊĠĠĠ Ġsuper . finish () ĊĠ Ġ} ĊĊĠ Ġpublic Ġoverride Ġfun Ġon New Intent ( intent : ĠIntent ?) Ġ{ ĊĠĠĠ Ġrelease Player () ĊĠĠĠ Ġset Intent ( intent ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon KeyDown ( keyCode : ĠInt , Ġevent : ĠKeyEvent ?): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( video Key Handler !!. on KeyDown ( keyCode , Ġevent )) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġsuper . on KeyDown ( keyCode , Ġevent ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġplay () Ġ{ ĊĠĠĠ Ġplayer . play When Ready Ġ= Ġtrue ĊĠĠĠ Ġprogress Reporting handler . post Delayed ( progress Runnable , ĠPROG RESS _ UPDATE _ DELAY . to Long ()) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġpause () Ġ{ ĊĠĠĠ Ġplayer . play When Ready Ġ= Ġfalse ĊĠĠĠ Ġprogress Reporting handler . remove Callbacks ( progress Runnable ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġinitialize Player ( video Url : ĠString , Ġoffset : ĠInt ) Ġ{ ĊĠĠĠ Ġlog . debug (" P lex ĠDirect ĠPlay ĠURL : Ġ" Ġ+ Ġvideo Url ) ĊĠĠĠ Ġplayer Ġ= Ġcreate Simple Ex op layer () ĊĠĠĠ Ġplayer . addListener ( event Logger ) ĊĠĠĠ Ġplayer . addListener ( presenter ) ĊĠĠĠ Ġplayer . set Audio Debug Listener ( event Logger ) ĊĠĠĠ Ġplayer . set Video Debug Listener ( event Logger ) ĊĠĠĠ Ġplayer . set Metadata Output ( event Logger ) ĊĠĠĠ Ġif Ġ( offset Ġ> Ġ 0 ) Ġ{ ĊĠĠĠĠĠ Ġplayer . seek To ( offset . to Long ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġplayer View . player Ġ= Ġplayer ĊĠĠĠ Ġplayer View . set Controller Visibility Listener ( presenter ) ĊĊĠĠĠ Ġplayer View . player . play When Ready Ġ= Ġtrue ĊĊĠĠĠ Ġval Ġmedia Source : ĠMedia Source Ġ= Ġbuild Media Source ( Uri . parse ( video Url )) ĊĠĠĠ Ġplayer . prepare ( media Source ) ĊĊĠĠĠ Ġvideo Key Handler Ġ= ĠVideo KeyCode Handler Delegate ( player , Ġthis , Ġpresenter ) ĊĠĠĠ Ġprogress Reporting handler . post Delayed ( progress Runnable , ĠPROG RESS _ UPDATE _ DELAY . to Long ()) ĊĠ Ġ} ĊĊĠ Ġinternal Ġfun Ġcreate Simple Ex op layer () Ġ= ĠEx o Player Factory . new Simple Instance ( this , Ġtrack Selector ) ĊĊĠ Ġinternal Ġfun Ġbuild Media Source ( uri : ĠUri ): ĠMedia Source Ġ= ĠExtract or Media Source ( uri , Ġmedia DataSource Factory , ĊĠĠĠĠĠ ĠDefault Extract ors Factory (), ĊĠĠĠĠĠ Ġvideo Player Handler , Ġevent Logger ) ĊĊĠ Ġinternal Ġfun Ġrelease Player () Ġ{ ĊĠĠĠ Ġplayer . release () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Controller () Ġ{ ĊĠĠĠ Ġplayer View . hide Controller () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Controller () Ġ{ ĊĠĠĠ Ġplayer View . show Controller () ĊĠ Ġ} ĊĊĠ Ġprotected Ġfun Ġset Exit ResultCode Finished () Ġ{ ĊĠĠĠ Ġval Ġreturn Intent Ġ= ĠIntent () ĊĠĠĠ Ġreturn Intent . putExtra (" position ", Ġplayer . current Position . toInt ()) ĊĠĠĠ Ġif Ġ( parent Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġset Result ( Activity . RESULT _ OK , Ġreturn Intent ) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġparent . set Result ( Activity . RESULT _ OK , Ġreturn Intent ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprotected Ġinner Ġclass ĠProgress Runnable Ġ: ĠRunnable Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġrun () Ġ{ ĊĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! player . play When Ready ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġpercentage Ġ= Ġplayer . current Position . toFloat () Ġ/ Ġplayer . get Duration (). toFloat () ĊĠĠĠĠĠĠĠ Ġif Ġ( percentage Ġ<= Ġ 9 0 f ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġpresenter . update Server Playback Position ( player . current Position ) ĊĠĠĠĠĠĠĠĠĠ Ġprogress Reporting handler . post Delayed ( this , ĠPROG RESS _ UPDATE _ DELAY ) ĊĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġpresenter . update W atched Status () ĊĠĠĠĠĠ Ġ} Ġcatch Ġ( ex : ĠIllegalStateException ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . error (" Illegal state Ġexception Ġoccurred Ġdur ring Ġprogress Ġupdate . ĠNo Ġfurther Ġupdates Ġwill Ġoccur .", Ġex ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } ĊĊ