//Called when application is started. function OnStart() { //Create a layout. lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a 'Play' button. btn = app.CreateButton( "Play", 0.6, 0.1 ); btn.SetMargins( 0, 0.05, 0, 0 ); lay.AddChild( btn ); btn.SetOnTouch( btn_OnTouchPlay ); //Create a 'Pause' button. btn = app.CreateButton( "Pause", 0.6, 0.1 ); btn.SetMargins( 0, 0.05, 0, 0 ); lay.AddChild( btn ); btn.SetOnTouch( btn_OnTouchPause ); //Create a 'Stop Service' button. btn = app.CreateButton( "Stop Service", 0.6, 0.1 ); btn.SetMargins( 0, 0.05, 0, 0 ); lay.AddChild( btn ); btn.SetOnTouch( btn_OnTouchStop ); //Add layout to app. app.AddLayout( lay ); //Start/connect to our service. svc = app.CreateService( "this","this", OnServiceReady ); //This will cause your service to start at boot. app.SetAutoBoot( "Service" ); } //Called after our service has started. function OnServiceReady() { console.log( "Service Ready" ); } function btn_OnTouchStop() { //Tell service we are quitting. svc.SendMessage( "quit" ); //Stop the service. svc.Stop(); } function btn_OnTouchPlay() { //Tell service to play music. svc.SendMessage( "play" ); } function btn_OnTouchPause() { //Tell service to pause music. svc.SendMessage( "pause" ); }