package Ġme . h uf man . android aut oid rive . music Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Handler Ċ import Ġme . h uf man . android aut oid rive . R Ċ Ċ class ĠSee king Controller ( val Ġcontext : ĠContext , Ġval Ġhandler : ĠHandler , Ġval Ġcontroller : ĠMusic Controller ) Ġ{ Ċ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ // Ġhow Ġmany Ġmilliseconds Ġper Ġhalf - second Ġinterval Ġto Ġseek , Ġat Ġeach Ġbutton - hold Ġtime Ġthreshold Ċĉ ĉ private Ġval ĠSEEK _ THRESH OL DS Ġ= ĠlistOf ( Ċĉĉĉĉ 0 Ġto Ġ 4 0 0 0 , Ċĉĉĉĉ 2 0 0 0 Ġto Ġ 7 0 0 0 , Ċĉĉĉĉ 5 0 0 0 Ġto Ġ 1 3 0 0 0 , Ċĉĉĉĉ 8 0 0 0 Ġto Ġ 3 0 0 0 0 Ċĉ ĉ ) Ċ ĉ } Ċ ĉ var Ġtime Provider : Ġ() Ġ-> ĠLong Ġ= Ġ{ ĠSystem . currentTimeMillis () Ġ} ĠĠ Ġ// Ġfor Ġunit Ġtests ĊĊ ĉ private Ġvar Ġstarted Seek ing Time : ĠLong Ġ= Ġ 0 ĠĠĠ Ġ// Ġdetermine Ġhow Ġlong Ġthe Ġuser Ġhas Ġbeen Ġholding Ġthe Ġseek Ġbutton Ċ ĉ private Ġvar Ġsee king Direction Forward Ġ= Ġtrue Ċ ĉ private Ġval Ġsee king Runnable Ġ= Ġobject Ġ: ĠRunnable Ġ{ Ċĉ ĉ override Ġfun Ġrun () Ġ{ Ċĉĉ ĉ if Ġ( started Seek ing Time Ġ> Ġ 0 ) Ġ{ Ċĉĉĉ ĉ val Ġhold Time Ġ= Ġtime Provider () Ġ- Ġstarted Seek ing Time Ċĉĉĉ ĉ hold Seek ( hold Time ) Ċĉĉĉ ĉ if Ġ( started Seek ing Time Ġ> Ġ 0 ) Ġ{ Ċĉĉĉĉ ĉ handler . post Delayed ( this , Ġ 3 0 0 ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ val Ġsee king Actions Ġ= ĠlistOf ( Ċĉ ĉ Custom Action D well (" me . h uf man . android aut oid rive ", Ġ" M US IC _ ACTION _ SEEK _ BACK _ 6 0 ", ĠL . M US IC _ ACTION _ SEEK _ BACK _ 6 0 , Ċĉĉĉĉ 0 , Ġcontext . get Drawable ( R . drawable . music _ seek _ back _ heavy ) Ġ, Ġnull , Ġnull ), Ċĉ ĉ Custom Action D well (" me . h uf man . android aut oid rive ", Ġ" M US IC _ ACTION _ SEEK _ BACK _ 1 0 ", ĠL . M US IC _ ACTION _ SEEK _ BACK _ 1 0 , Ċĉĉĉĉ 0 , Ġcontext . get Drawable ( R . drawable . music _ seek _ back ), Ġnull , Ġnull ), Ċĉ ĉ Custom Action D well (" me . h uf man . android aut oid rive ", Ġ" M US IC _ ACTION _ SEEK _ FORWARD _ 1 0 ", ĠL . M US IC _ ACTION _ SEEK _ FORWARD _ 1 0 , Ċĉĉĉĉ 0 , Ġcontext . get Drawable ( R . drawable . music _ seek _ forward ), Ġnull , Ġnull ), Ċĉ ĉ Custom Action D well (" me . h uf man . android aut oid rive ", Ġ" M US IC _ ACTION _ SEEK _ FORWARD _ 6 0 ", ĠL . M US IC _ ACTION _ SEEK _ FORWARD _ 6 0 , Ċĉĉĉĉ 0 , Ġcontext . get Drawable ( R . drawable . music _ seek _ forward _ heavy ), Ġnull , Ġnull ) Ċ ĉ ) ĊĊ ĉ fun Ġstart Rew ind () Ġ{ Ċĉ ĉ started Seek ing Time Ġ= Ġtime Provider () Ċĉ ĉ see king Direction Forward Ġ= Ġfalse Ċĉ ĉ see king Runnable . run () Ċ ĉ } Ċ ĉ fun Ġstart Fast Forward () Ġ{ Ċĉ ĉ started Seek ing Time Ġ= Ġtime Provider () Ċĉ ĉ see king Direction Forward Ġ= Ġtrue Ċĉ ĉ see king Runnable . run () Ċ ĉ } Ċ ĉ fun Ġstop Seek ing () Ġ{ Ċĉ ĉ started Seek ing Time Ġ= Ġ 0 Ċĉ ĉ controller . play () Ċ ĉ } ĊĊ ĉ fun Ġseek Action ( action : ĠCustom Action ) Ġ{ Ċĉ ĉ if Ġ( see king Actions . contains ( action )) Ġ{ Ċĉĉ ĉ val Ġdirection Ġ= Ġif Ġ( action . action . contains (" SEEK _ BACK _ ")) Ġ{ Ġ- 1 Ġ} Ġelse Ġ{ Ġ 1 Ġ} Ċĉĉ ĉ val Ġdelta Ġ= Ġaction . action . split ("_ "). last (). toInt () Ġ* Ġ 1 0 0 0 Ġ* Ġdirection Ċĉĉ ĉ seek ( delta ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ fun Ġhold Seek ( hold Time : ĠLong ) Ġ{ Ċĉ ĉ val Ġseek Time Ġ= ĠSEEK _ THRESH OL DS . last OrNull Ġ{ Ġhold Time Ġ>= Ġit . first Ġ} ?. second Ġ?: Ġ 2 0 0 0 Ċĉ ĉ val Ġdelta Ġ= Ġif Ġ( see king Direction Forward ) Ġ{ Ġ 1 Ġ} Ġelse Ġ{ Ġ- 1 Ġ} Ġ* Ġseek Time Ċĉ ĉ seek ( delta ) Ċ ĉ } ĊĊ ĉ fun Ġseek ( delta : ĠInt ) Ġ{ Ċĉ ĉ val Ġcur Pos Ġ= Ġcontroller . get Playback Position (). getPosition () Ċĉ ĉ val Ġnew Pos Ġ= Ġcur Pos Ġ+ Ġdelta Ċĉ ĉ // Ġhandle Ġsee king Ġpast Ġbeginning Ġof Ġsong Ċĉ ĉ if Ġ( new Pos Ġ< Ġ 0 ) Ġ{ Ċĉĉ ĉ controller . skip To Previous () Ċĉĉ ĉ started Seek ing Time Ġ= Ġ 0 Ġ Ġ// Ġcancel Ġsee king , Ġbecause Ġskip To Previous Ġstarts Ġat Ġthe Ġbeginning Ġof Ġthe Ġprevious Ġsong Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ controller . seek To ( new Pos ) Ċĉ ĉ } Ċ ĉ } Ċ }