Public Sub audioControl_Display(show As Boolean)
If show Then
If Not(audioControlPanel.IsInitialized) Then
' Initialise audioControlPanel and add to activity
audioControlPanel.Initialize("audioControlPanel")
audioControlPanel.Color = 0xFFD9D7DE
' Determine if in landscape or portrait mode
Dim orientation As String
orientation = Format.GetScreenOrientation
If orientation = "portrait" Then
Activity.AddView(audioControlPanel, 0, Activity.Height - 75dip, 100%x, 75dip)
Else
Activity.AddView(audioControlPanel, Activity.Width - 75dip, 0, 75dip, 100%y)
End If
' Create audiobuttonpanel with textured background and add to audiocontrolpanel to produce a bordered effect
Dim audioButtonPanel As Panel
audioButtonPanel.Initialize("audioControlPanel")
audioButtonPanel.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "audio control background.png", 100%x, 100%y))
audioControlPanel.AddView(audioButtonPanel, 2dip, 2dip, audioControlPanel.Width-4dip, audioControlPanel.Height-4dip)
' Add buttons to the panel
init_audioButton(0, "previous", audioButtonPanel, orientation)
init_audioButton(1, "rewind", audioButtonPanel, orientation)
If Music_Service.playerStatus = "stopped" Then
init_audioButton(2, "play", audioButtonPanel, orientation)
Else
init_audioButton(2, "stop", audioButtonPanel, orientation)
End If
init_audioButton(3, "forward", audioButtonPanel, orientation)
init_audioButton(4, "next", audioButtonPanel, orientation)
End If
audioControlPanel.Visible = True
Else
If audioControlPanel.IsInitialized Then
audioControlPanel.Visible = False
End If
End If
' Refresh CustomListView height to account for Audio Control Panel if visible or hidden
clvAdjustHeight
End Sub
Private Sub init_audioButton(index As Int, function As String, btnPanel As Panel, orientation As String)
Dim btnWidth, btnHeight As Int
Dim btn As Button
' Create a new audio control button
btn.Initialize("audioButton")
' Assign the button with the required function eg."previous", "Play", "Stop" etc.
btn.Tag = function
' Screen orientation affects where audio control panel is placed
If orientation = "portrait" Then
' Buttons to be placed horizontally with a 5dip gap both sides of audio control panel and 1dip gap top and bottom
btnWidth = (btnPanel.Width - 10dip) / 5
btnHeight = btnPanel.Height - 4dip
' The index sets position of the button
btnPanel.AddView(btn, 5dip + (btnWidth * index), 2dip, btnWidth, btnHeight)
Else
' Buttons to be placed vertically with a 5dip gap top and bottom and 1dip gap on either sides
btnWidth = btnPanel.Width - 4dip
btnHeight = (btnPanel.Height - 10dip) / 5
' The index sets position of the button
btnPanel.AddView(btn, 2dip, 5dip + (btnHeight * index), btnWidth, btnHeight)
End If
' Apply the button with the required image
btn.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "audio " & function & ".png", btnWidth, btnHeight))
End Sub
Public Sub audioButton_Click()
If Music_Service.playerInitialised Then
Dim btn As Button = Sender
Select Case btn.Tag
Case "previous"
Music.PlayPreviousTrack
Case "rewind"
Case "stop"
If Music_Service.musicStream.IsPlaying Then
Music_Service.musicStream.Pause
Music_Service.playerStatus = "stopped"
btn.Tag = "play"
btn.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "audio " & "play" & ".png", (audioControlPanel.Width - 10dip) / 5, audioControlPanel.Height - 4dip))
End If
Case "play"
If Not(Music_Service.musicStream.IsPlaying) AND Music.playList.Size >= 1 Then
Music_Service.musicStream.Play
Music_Service.playerStatus = "playing"
btn.Tag = "stop"
btn.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "audio " & "stop" & ".png", (audioControlPanel.Width - 10dip) / 5, audioControlPanel.Height - 4dip))
End If
Case "forward"
Case "next"
Music.PlayNextTrack
End Select
End If
End Sub