#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim httpC As HttpClient
Dim httpD As HttpClient
Dim mp As MediaPlayerStream
Dim Audio As AudioStreamer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim sv As ScrollView
Dim fontface As Typeface
Dim background As Panel
Dim statustop As Panel
' routine events
Dim startpacket As Timer
' statustop events
Dim statustitle As Label
Dim statusvalue As Label
' status images
Dim statusonline As ImageView
Dim statusoffline As ImageView
Dim onlineimage As Bitmap
Dim onlineimage_dull As Bitmap
Dim offlineimage As Bitmap
Dim offlineimage_dull As Bitmap
' player cover
Dim plr_image As Panel
Dim playerimage As ImageView
Dim imageplayer As Bitmap
' main player controls
Dim player_main As Panel
Dim lblPosition As Label
' feed stats
Dim player_feeds As Panel
Dim feed_title As Label
Dim feed_main_title As Label
Dim listeners As Label
Dim peaklisteners As Label
Dim genre As Label
Dim url As Label
Dim track As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("player")
' Load layout Interface
layoutui
' initiate the http client
httpC.Initialize("httpC")
' initiate timer
startpacket.Initialize("startpacket", 2000)
startpacket.Enabled = True
' initiate the player
mp.Initialize("mp")
' Audio.Initialize("Audio", 44100, False, 16, Audio.VOLUME_MUSIC)
mp.Load("http://46.18.33.24:9000")
End Sub
#Region Layout UI Code
Sub layoutui
' design permaeters for the activity
sv.Initialize(100%y)
Activity.AddView(sv, 0, 0, 100%x, 100%y)
' add custom font package into activity
fontface = Typeface.LoadFromAssets("playtime-webfont.TTF")
background.Initialize("background")
sv.Panel.AddView(background, 0, 0, 100%x, 100%y)
background.Color = Colors.RGB(50, 50, 47)
statustop.Initialize("statustop")
sv.Panel.AddView(statustop, 74%x, 0, 30%x, 20dip)
'statustop.Color = Colors.Red
statustitle.Initialize("statustitle")
statustop.AddView(statustitle, 0, 0, 45dip, 20dip)
statustitle.Text = "status:"
statustitle.Typeface = fontface
onlineimage.Initialize(File.DirAssets, "online.png")
onlineimage_dull.Initialize(File.DirAssets, "online_dull.png")
statusonline.Initialize("statusonline")
statustop.AddView(statusonline, 45dip, 3dip, 16dip, 16dip)
statusonline.Bitmap = onlineimage_dull
offlineimage.Initialize(File.DirAssets, "offline.png")
offlineimage_dull.Initialize(File.DirAssets, "offline_dull.png")
statusoffline.Initialize("statusoffline")
statustop.AddView(statusoffline, 65dip, 3dip, 16dip, 16dip)
statusoffline.Bitmap = offlineimage_dull
plr_image.Initialize("plr_image")
sv.Panel.AddView(plr_image, 0, 30dip, 200dip, 200dip)
plr_image.Left = (100%x - 200dip) / 2
imageplayer.Initialize(File.DirAssets, "player_image.png")
playerimage.Initialize("playerimage")
plr_image.AddView(playerimage, 0, 0, 200dip, 200dip)
playerimage.Bitmap = imageplayer
' title
feed_main_title.Initialize("feed_main_title")
sv.Panel.AddView(feed_main_title, 0, 235dip, 100%x, 20dip)
feed_main_title.Typeface = fontface
feed_main_title.Gravity = Gravity.CENTER_HORIZONTAL
'feed_main_title.Color = Colors.Blue
feed_main_title.TextColor = Colors.White
' player
player_main.Initialize("player_main")
sv.Panel.AddView(player_main, 0, 260dip, 100%x, 30dip)
player_main.Color = Colors.Red
' player feeds
player_feeds.Initialize("player_feeds")
sv.Panel.AddView(player_feeds, 5%x, 350dip, 90%x, 120dip)
'player_feeds.Color = Colors.Cyan
feed_title.Initialize("feed_title")
player_feeds.AddView(feed_title, 0, 0, 100%x, 12dip)
feed_title.TextColor = Colors.RGB(242, 216, 0)
feed_title.Typeface = fontface
feed_title.Text = "Server Statistics:"
feed_title.TextSize = 10
'feed_title.Color = Colors.DarkGray
listeners.Initialize("listeners")
player_feeds.AddView(listeners, 0, 16dip, 100%x, 16dip)
listeners.Typeface = fontface
'listeners.Color = Colors.Green
listeners.TextSize = 14
peaklisteners.Initialize("peaklisteners")
player_feeds.AddView(peaklisteners, 0, 36dip, 100%x, 16dip)
peaklisteners.Typeface = fontface
'peaklisteners.Color = Colors.Green
peaklisteners.TextSize = 14
genre.Initialize("genre")
player_feeds.AddView(genre, 0, 56dip, 100%x, 16dip)
genre.Typeface = fontface
'genre.Color = Colors.Green
genre.TextSize = 14
url.Initialize("url")
player_feeds.AddView(url, 0, 76dip, 100%x, 16dip)
url.Typeface = fontface
'url.Color = Colors.Green
url.TextSize = 14
track.Initialize("track")
player_feeds.AddView(track, 0, 96dip, 100%x, 16dip)
track.Typeface = fontface
'track.Color = Colors.Green
track.TextSize = 14
lblPosition.Initialize("lblPosition")
sv.Panel.AddView(lblPosition, 80%x, 300dip, 18%x, 20dip)
lblPosition.Typeface = fontface
lblPosition.TextColor = Colors.White
lblPosition.Text = "0:00 (0:00)"
lblPosition.Gravity = Gravity.RIGHT
End Sub
#End Region
Sub startpacket_Tick
startpacket.Enabled = False
' start the request to get the connection state of the remote server
Dim req As HttpRequest
req.InitializeGet("http://steve.dualzdesigns.com/vipradio2/example1.php")
httpC.Execute(req, 1)
End Sub
Sub httpC_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Try
Dim result As String
result = Response.GetString("UTF8")
' status
Dim status As String
status = result.SubString(result.IndexOf("[status]") + 12)
status = status.SubString2(0, status.IndexOf("[") - 5) ' go back 5 spaces to stop the gap between data packets
'Msgbox(status, "") ' debug only
If status == "1" Then
statusonline.Bitmap = onlineimage
statusoffline.Bitmap = offlineimage_dull
Else
statusonline.Bitmap = onlineimage_dull
statusoffline.Bitmap = offlineimage
End If
' end status
' listeners
Dim ret_listeners As String
ret_listeners = result.SubString(result.IndexOf("[listener]") + 13)
ret_listeners = ret_listeners.SubString2(0, ret_listeners.IndexOf("[") - 5)
'Msgbox(ret_listeners, "") ' debug only
Dim ret_maxlisteners As String
ret_maxlisteners = result.SubString(result.IndexOf("[listener_max]") + 18)
ret_maxlisteners = ret_maxlisteners.SubString2(0, ret_maxlisteners.IndexOf("[") - 5)
'Msgbox(ret_maxlisteners, "") ' debug only
listeners.Text = "Connected: " & ret_listeners & " of " & ret_maxlisteners
' end listeners
' peak listeners
Dim ret_peakcount As String
ret_peakcount = result.SubString(result.IndexOf("[peak]") + 9)
ret_peakcount = ret_peakcount.SubString2(0, ret_peakcount.IndexOf("[") - 5)
'Msgbox(ret_peakcount, "") ' debug only
peaklisteners.Text = "Peak Listeners: " & ret_peakcount
' end peak listeners
' genre
Dim ret_genre As String
ret_genre = result.SubString(result.IndexOf("[genre]") + 10)
ret_genre = ret_genre.SubString2(0, ret_genre.IndexOf("[") - 5)
'Msgbox(ret_genre, "") ' debug only
genre.Text = "Genre: " & ret_genre
' end genre
' url
Dim ret_url As String
ret_url = result.SubString(result.IndexOf("[url]") + 8)
ret_url = ret_url.SubString2(0, ret_url.IndexOf("[") - 5)
'Msgbox(ret_url, "") ' debug only
url.Text = "Url: " & ret_url
' end url
' track
Dim ret_track As String
ret_track = result.SubString(result.IndexOf("[track]") + 10)
ret_track = ret_track.SubString2(0, ret_track.IndexOf(")") - 1)
'Msgbox(ret_track1, "") ' debug only
track.Text = "Track: " & ret_track
' end track
' title
Dim ret_title As String
ret_title = result.SubString(result.IndexOf("[title]") + 10)
ret_title = ret_title.SubString2(0, ret_title.IndexOf("[") - 5)
'Msgbox(ret_title, "") ' debug only
feed_main_title.Text = ret_title
' end title
' start the player (DEBUG ONLY)
mp_StreamReady
Catch
End Try
End Sub
Sub mp_StreamReady
Log("starts playing")
mp.Play
End Sub
Sub mp_StreamError (ErrorCode As String, ExtraData As Int)
Log("Error: " & ErrorCode & ", " & ExtraData)
ToastMessageShow("Error: " & ErrorCode & ", " & ExtraData, True)
End Sub
Sub mp_StreamBuffer(Percentage As Int)
Log(Percentage)
End Sub
#Region unused routines
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#End Region