package Ġru . ne vd ok im of . aut op layer . view models Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Build Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġru . ne vd ok im of . aut op layer . Auto Player Service Ċ import Ġru . ne vd ok im of . aut op layer . model . Service Status Ċ Ċ class ĠAuto Player Service ViewModel ( app : ĠApplication ) Ġ: ĠAndroid ViewModel ( app ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġauto Player Service Intent Ġ= ĊĠĠĠĠĠĠĠ ĠIntent ( getApplication (), ĠAuto Player Service :: class . java ) ĊĠĠĠ Ġval Ġauto Player Service Status Ġ= ĠAuto Player Service . service Status ĊĊĠĠĠ Ġfun Ġchange Auto Player Service State () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen ( auto Player Service Status . value ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠService Status . RUNNING Ġ-> Ġstop Auto Player Service () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠService Status . DOWN , Ġnull Ġ-> Ġstart Auto Player Service () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstop Auto Player Service () Ġ{ ĊĠĠĠĠĠĠĠ Ġget Application < Application >(). stop Service ( auto Player Service Intent ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstart Auto Player Service () Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Application < Application >(). start Foreground Service ( auto Player Service Intent ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Application < Application >(). start Service ( auto Player Service Intent ) ĊĠĠĠ Ġ} Ċ }