This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
built_in:service [2018/12/29 03:28] 114.125.22.195 [Links] |
built_in:service [2018/12/29 16:47] (current) |
||
---|---|---|---|
Line 142: | Line 142: | ||
} | } | ||
</ | </ | ||
- | //Called when service is started. | + | ==== Links ==== |
- | function OnStart() | + | There is another background |
- | { | + | |
- | 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( " | + | |
- | } | + |