This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
built_in:service [2015/12/17 17:08] stevegarman add links |
built_in:service [2018/12/29 03:28] 114.125.22.195 [Links] |
||
---|---|---|---|
Line 142: | Line 142: | ||
} | } | ||
</ | </ | ||
- | ==== Links ==== | + | //Called when service is started. |
- | There is another background | + | function OnStart() |
+ | { | ||
+ | app.ShowPopup( "Hello from Service!" | ||
+ | |||
+ | //Create media player. | ||
+ | player | ||
+ | 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( " | ||
+ | } | ||
+ | |||
+ | //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 | ||
+ | |||
+ | //Show a notification with album art if available. | ||
+ | notify | ||
+ | notify.SetMessage( track.title, | ||
+ | if( gotArt ) notify.SetLargeImage( img ); | ||
+ | notify.Notify( " | ||
+ | } | ||
+ | |||
+ | //Called when we get a service | ||
+ | function OnMessage( msg ) | ||
+ | { | ||
+ | //Show debug in WiFi IDE. | ||
+ | console.log( msg ); | ||
+ | |||
+ | //Handle commands from main App. | ||
+ | if( msg==" | ||
+ | else if( msg==" | ||
+ | else if( msg==" | ||
+ | } | ||
+ | |||
+ | //Called when player is ready to play. | ||
+ | function player_OnReady() | ||
+ | { | ||
+ | player.Play(); | ||
+ | } | ||
+ | |||
+ | //Called when playback has finished. | ||
+ | function player_OnComplete() | ||
+ | { | ||
+ | notify.SetMessage( "Track Finished!", | ||
+ | notify.Notify( " | ||
+ | } |