Here is code.
MediaPlayer app.
Three panels for three windows.
Three menu button at the main window.
Menu changing to different window works all right,
In the first panel there is ToggleButton to play or pause MediaPlayer.
Seekbar to show progress.
Label to show time.
Problem:
I cannot make ToggleButton to work.
Thanks,
Nam
------------------------------
Sub Process_Globals
Dim MediaPlayer1 As MediaPlayer
Dim timer1 As Timer
End Sub
Sub Globals
Dim pnlPage1, pnlPage2, pnlPage3 As Panel
Dim pnlToolbox As Panel
Dim SeekBar2 As SeekBar
Dim ToggleButton1 As ToggleButton
Dim Label3 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim PanelHeight As Float
If FirstTime Then
MediaPlayer1.Initialize()
MediaPlayer1.Load(File.DirAssets, "NOW_Meditation_1.mp3")
timer1.Initialize("timer1", 1000)
End If
Activity.LoadLayout("Main")
pnlToolbox.Top = Activity.Height - pnlToolbox.Height
PanelHeight = pnlToolbox.Top - 5dip
pnlPage1.Initialize("")
Activity.LoadLayout("Page1")
pnlPage1.AddView(pnlPage1,0,0,100%x,PanelHeight)
pnlPage1.Visible=True
'music progress bar
SeekBar2.Initialize("")
Activity.AddView(SeekBar2,5%x,70%y,220dip,17dip)
'SeekBar2.Max = 35
SeekBar2.Max = MediaPlayer1.Duration
SeekBar2.Value = 0
ToggleButton1.Initialize("")
Activity.AddView(ToggleButton1,76%x,65%y,60dip,40dip)
ToggleButton1.Textoff = "pause"
Label3.Initialize("")
Activity.AddView(Label3,4%x,66%y,130dip,40dip)
Label3.Text = "P:"
Label3.TextColor = Colors.black
pnlPage2.Initialize("")
pnlPage2.LoadLayout("Page2")
Activity.AddView(pnlPage2,0,0,100%x,PanelHeight)
pnlPage2.Visible=False
pnlPage3.Initialize("")
pnlPage3.LoadLayout("Page3")
Activity.AddView(pnlPage3,0,0,100%x,PanelHeight)
pnlPage3.Visible=False
End Sub
Sub btnPage_Click
Dim Send As Button
Send = Sender
pnlPage1.Visible=False
pnlPage2.Visible=False
pnlPage3.Visible=False
Select Send.Tag
Case "1"
pnlPage1.Visible=True
Case "2"
pnlPage2.Visible=True
Case "3"
pnlPage3.Visible=True
End Select
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ToggleButton1_CheckedChange(Checked As Boolean)
'play or pause
If MediaPlayer1.IsPlaying Then
MediaPlayer1.Pause
timer1.Enabled = False
Else
MediaPlayer1.Play
timer1.Enabled = True
timer1_Tick
End If
End Sub
Sub SeekBar2_ValueChanged (Value As Int, UserChanged As Boolean)
If UserChanged = False Then Return
MediaPlayer1.Position = Value / 100 * MediaPlayer1.Duration
If MediaPlayer1.IsPlaying = False Then
MediaPlayer1.Play
If ToggleButton1.Checked = False Then
ToggleButton1.Checked = True
Else
End If
End If
timer1.Enabled = True
timer1_Tick
End Sub
Sub timer1_Tick
If MediaPlayer1.IsPlaying Then
SeekBar2.Value = MediaPlayer1.Position / MediaPlayer1.Duration * 100
Label3.Text = "Progress: " & ConvertToTimeFormat(MediaPlayer1.Position) & _
" (" & ConvertToTimeFormat(MediaPlayer1.Duration) & ")"
End If
End Sub
Sub ConvertToTimeFormat(ms As Int) As String
'converts milliseconds to m:ss format.
Dim seconds, minutes As Int
seconds = Round(ms / 1000)
minutes = Floor(seconds / 60)
seconds = seconds Mod 60
Return NumberFormat(minutes, 1, 0) & ":" & NumberFormat(seconds, 2, 0) 'ex: 3:05
End Sub