package Ġcom . illi arb . t mdb client . modules . video . widget Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . util . Attribute Set Ċ import Ġandroid . widget . Frame Layout Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġcom . illi arb . t mdb client . R Ċ import Ġcom . illi arb . t mdb client . databinding . Widget Y outube Player Binding Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . Player Constants Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . YouTube Player Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . listeners . Abstract YouTube Player Listener Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . listeners . YouTube Player Callback Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . Mutable State Flow Ċ import Ġkotlinx . coroutines . flow . map Ċ Ċ class ĠY outube Player Ġ@ Jvm Over loads Ġconstructor ( ĊĠ Ġcontext : ĠContext , ĊĠ Ġattrs : ĠAttributeSet ? Ġ= Ġnull , ĊĠ Ġdef Style Attr : ĠInt Ġ= Ġ 0 Ċ ) Ġ: ĠFrame Layout ( context , Ġattrs , Ġdef Style Attr ) Ġ{ ĊĊĠ Ġprivate Ġval Ġbinding : ĠWidget Y outube Player Binding Ġ= ĊĠĠĠ ĠWidget Y outube Player Binding . bind ( inflate ( context , ĠR . layout . widget _ youtube _ player , Ġthis )) ĊĊĠ Ġprivate Ġval Ġplayer State Ġ= ĠMutable State Flow ( Player Constants . Player State . UNKNOWN ) ĊĊĠ Ġprivate Ġval Ġis Playing : ĠBoolean ĊĠĠĠ Ġget () Ġ= Ġplayer State . value Ġ== ĠPlayer Constants . Player State . PLAY ING ĊĊĠ Ġinit Ġ{ ĊĠĠĠ Ġbinding . player View . add YouTube Player Listener ( object Ġ: ĠAbstract YouTube Player Listener () Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġon StateChange ( you Tube Player : ĠYouTube Player , Ġstate : ĠPlayer Constants . Player State ) Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer State . value Ġ= Ġstate ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġplaying State Changes (): ĠFlow < Boolean > Ġ= ĊĠĠĠ Ġplayer State . map Ġ{ Ġit Ġ== ĠPlayer Constants . Player State . PLAY ING Ġ} ĊĊĠ Ġfun Ġset Lifecycle Owner ( owner : ĠLifecycle Owner ) Ġ{ ĊĠĠĠ Ġowner . lifecycle . add Observer ( binding . player View ) ĊĠ Ġ} ĊĊĠ Ġfun Ġplay Video ( video Id : ĠString , Ġstart Seconds : ĠFloat Ġ= Ġ 0 f ) Ġ{ ĊĠĠĠ Ġwith Y outube Player Ġ{ Ġplayer Ġ-> ĊĠĠĠĠĠ Ġplayer . load Video ( video Id , Ġstart Seconds ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun ĠsetShow Controls ( show : ĠBoolean ) Ġ{ ĊĠĠĠ Ġbinding . player View . getPlayer Ui Controller (). show Ui ( show ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtoggle Video () Ġ{ ĊĠĠĠ Ġwith Y outube Player Ġ{ Ġplayer Ġ-> ĊĠĠĠĠĠ Ġif Ġ( is Playing ) Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer . pause () ĊĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġplayer . play () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġinline Ġfun Ġwith Y outube Player ( cross inline Ġblock : Ġ( YouTube Player ) Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġbinding . player View . get YouTube Player When Ready ( object Ġ: ĠYouTube Player Callback Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġon YouTube Player ( you Tube Player : ĠYouTube Player ) Ġ{ ĊĠĠĠĠĠĠĠ Ġblock ( you Tube Player ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} Ċ }