/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠAlex ey ĠK ras il nik ov Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġme . kr as il nik ov . pace assistant . audio Ċ Ċ import Ġandroid . annotation . Target Api Ċ import Ġandroid . content . Context Ċ import Ġandroid . media . Audio Focus Request Ċ import Ġandroid . media . Audio Manager Ċ import Ġandroid . os . Build Ċ import Ġandroidx . annotation . Requires Api Ċ Ċ interface ĠAudio Focus Ġ{ ĊĠĠĠ Ġsuspend Ġfun Ġwith Focus ( block : Ġsuspend Ġ() Ġ-> ĠUnit ) Ċ } Ċ Ċ @ Requires Api ( Build . VERSION _ CODES . O ) Ċ class ĠAudio Focus 2 6 ( context : ĠContext ) Ġ: ĠAudio Focus Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġaudio Manager Ġ= Ġcontext . getSystem Service ( Context . AUDIO _ SERVICE ) Ġas ĠAudio Manager ĊĠĠĠ Ġprivate Ġval Ġfocus Request Ġ= ĊĠĠĠĠĠĠĠ ĠAudio Focus Request . Builder ( Audio Manager . AUDIO FOCUS _ GAIN _ TRAN SI ENT _ MAY _ DU CK ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Accept s Delayed Focus Gain ( false ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Audio Attributes ( Audio . audio Attributes ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġwith Focus ( block : Ġsuspend Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( audio Manager . request Audio Focus ( focus Request ) Ġ!= ĠAudio Manager . AUDIO FOCUS _ REQUEST _ GRAN TED ) Ġreturn ĊĊĠĠĠĠĠĠĠ Ġblock () ĊĊĠĠĠĠĠĠĠ Ġaudio Manager . ab and on Audio Focus Request ( focus Request ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Suppress (" DE PREC ATION ") Ċ @ Target Api ( Build . VERSION _ CODES . LO L LI POP ) Ċ class ĠAudio Focus 8 ( context : ĠContext ) Ġ: ĠAudio Focus Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġaudio Manager Ġ= Ġcontext . getSystem Service ( Context . AUDIO _ SERVICE ) Ġas ĠAudio Manager ĊĠĠĠ Ġprivate Ġval Ġlistener Ġ= ĠAudio Manager . On Audio Focus ChangeListener Ġ{ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġwith Focus ( block : Ġsuspend Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġaudio Manager . request Audio Focus ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAudio Manager . STREAM _ M US IC , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAudio Manager . AUDIO FOCUS _ GAIN _ TRAN SI ENT _ MAY _ DU CK ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( result Ġ!= ĠAudio Manager . AUDIO FOCUS _ REQUEST _ GRAN TED ) Ġreturn ĊĊĠĠĠĠĠĠĠ Ġblock () ĊĊĠĠĠĠĠĠĠ Ġaudio Manager . ab and on Audio Focus ( listener ) ĊĠĠĠ Ġ} Ċ } Ċ