Android Question How to make MediaPlayerStream loop after complete when screen is off

tuhatinhvn

Active Member
Licensed User
Longtime User
Here my code:

B4X:
#Region  Service Attributes
    #StartAtBoot: 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 MediaPlayer1 As MediaPlayerStream
Dim timer1 As Timer
Dim vitri As Int
Dim kichthuoc As Int
Dim mangbai As List
End Sub
Sub Service_Create

      'StartServiceAt(c, DateTime.Now, True)

End Sub

Sub Service_Start (StartingIntent As Intent)
MediaPlayer1.Initialize("MediaPlayer1")
Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.Vibrate = False
    n.Sound = False
    n.Light = False
    n.SetInfo("Play...", "", Main)
    Service.StartForeground(1, n)
End Sub

Sub Service_Destroy

End Sub
Sub choibai(link As String)
MediaPlayer1.Load(link)
timer1.Initialize("timer1", 1000)
timer1.Enabled=True
End Sub
Sub dungbai
MediaPlayer1.Pause
End Sub
Sub MediaPlayer1_StreamReady


  MediaPlayer1.Play
'  timer1.Enabled=True
'    ProgressDialogHide
  'myProgressDialog.Hide

End Sub
Sub timer1_Tick
    If MediaPlayer1.IsPlaying Then
    Dim a1 As Int
    Dim a2 As String
    a1=MediaPlayer1.Position / MediaPlayer1.Duration * 100
    a2="Thời gian: " & ConvertToTimeFormat(MediaPlayer1.Position) & _
            " / " & ConvertToTimeFormat(MediaPlayer1.Duration)
    CallSubDelayed3(Main,"chuyengiatri",a1, a2)
        'SeekBar1.Value =
        'Label3.Text =
    End If
End Sub
Sub ConvertToTimeFormat(ms As Int) As String
    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
Sub chinhvolume(giatri As Int)
MediaPlayer1.SetVolume(giatri / 100, giatri / 100)
End Sub



Sub MediaPlayer1_complete
CallSubDelayed(Main,"nextbai")
End Sub


Main Activity:

B4X:
Sub nextbai

Log(lv.GetSize)
Log(vitri)
If vitri<lv.GetSize-1 Then

a22 = lv.GetValue(vitri+1)
lv.JumpToItem(vitri+1)
vitri=vitri+1
choi(Regex.Split("\|",a22)(1))


End If
End Sub

Sub choi(link As String)


'ProgressDialogShow("Đang nạp hãy đợi 1 chút...")
    Dim truyvanhttp As HttpJob
          truyvanhttp.Initialize("maychu4",Me)
    truyvanhttp.Download(link)
    truyvanhttp.GetRequest.SetHeader("User-Agent", "LCARS UI")
   truyvanhttp.GetRequest.SetHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
   truyvanhttp.GetRequest.SetHeader("Accept-Encoding", "Text/plain")
End Sub

But when press home or screen off app can not next track
 

susu

Well-Known Member
Licensed User
Longtime User
Sorry if it's off topic.
Is there Position method for MediaPlayerStream? Why I can't find it in the Audio library?
 
Upvote 0
Top