DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:service

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
built_in:service [2018/12/29 03:28]
114.125.22.195 [Links]
built_in:service [2018/12/29 08:47] (current)
administrator old revision restored (2015/12/17 17:08)
Line 142: Line 142:
 } }
 </​code>​ </​code>​
-//Called when service is started. +==== Links ==== 
-function OnStart() +There is another background ​service ​sample at [[sample_code:​file_service|Web file service]]
-+
-app.ShowPopup( "Hello from Service!"​ ); +
-  +
-//Create media player. +
-player ​app.CreateMediaPlayer();​ +
-player.SetOnReady( player_OnReady ); +
-player.SetOnComplete( player_OnComplete ); +
-  +
-//Query media store for a nice long track. +
-media app.CreateMediaStore();​ +
-media.SetOnMediaResult( media_OnMediaResult ); +
-media.QueryMedia( "​duration > 120000",​ "",​ "​external"​ ); +
-+
-  +
-//Handle media query results. +
-function media_OnMediaResult( result ) +
-+
-if( result.length==0 ) return; +
-  +
-//Play first file found. +
-track result[51];​ +
-player.SetFile( track.uri ); +
-  +
-//Get album art. +
-var img app.CreateImage( null, 0.1, 0.1 ); +
-var gotArt ​media.GetAlbumArt( img, track.albumId,​ "​external"​ ); +
-  +
-//Show a notification with album art if available. +
-notify ​app.CreateNotification( "​Ongoing"​ ); +
-notify.SetMessage( track.title,​ track.title,​ track.album );  +
-if( gotArt ) notify.SetLargeImage( img ); +
-notify.Notify( "​my_player_id"​ );  +
-+
-  +
-//Called when we get a service ​message. +
-function OnMessage( msg ) +
-+
-//Show debug in WiFi IDE. +
-console.log( msg ); +
-  +
-//Handle commands from main App. +
-if( msg=="​play"​ ) player.Play();​ +
-else if( msg=="​pause"​ ) player.Pause();​ +
-else if( msg=="​quit"​ ) notify.Cancel( "​my_player_id"​ ); +
-+
-  +
-//Called when player is ready to play. +
-function player_OnReady() +
-+
-player.Play();​ +
-+
-  +
-//Called when playback has finished. +
-function player_OnComplete() +
-+
-notify.SetMessage( "Track Finished!",​ track.title,​ track.album );  +
-notify.Notify( "​my_player_id"​ ); +
-}+
built_in/service.txt · Last modified: 2018/12/29 08:47 by administrator