Android Question Pausing Media Player Remotely

iZAK

New Member
Licensed User
I am writing a custom media player app. It works fine on the devices, but when connected to my vehicle via bluetooth, it will not show my track or let me pause. My car shows the pause key pressed, but my app continues on as if nothing happened.

Code is:

My Media Player:
Build1=Default,com.mediaplayertest
File1=1.bal
File2=us.mid
FileGroup1=Default Group
FileGroup2=Default Group
Group=Default Group
Library1=core
Library2=xui views
ManifestCode=
NumberOfFiles=2
NumberOfLibraries=2
NumberOfModules=0
Version=12.5
@EndOfDesignText@
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Media Player Vehicle Pause test
    '#VersionCode: 1
    #VersionName:
    #SupportedOrientations: portrait
#End Region

Sub Process_Globals
    Dim MediaPlayer1 As MediaPlayer
    Dim timer1 As Timer
End Sub

Sub Globals
    Dim barPosition As SeekBar
    Dim barVolume As SeekBar
    Dim lblPosition As Label
    Private bplay As SwiftButton
    Private bpause As SwiftButton
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        MediaPlayer1.Initialize( )
        MediaPlayer1.Load(File.DirAssets, "us.mid")
        timer1.Initialize("timer1", 1000)
    End If
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    MediaPlayer1.Play
    timer1.Enabled = True
    timer1_Tick 'don't wait one second for the UI to update.
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If MediaPlayer1.IsPlaying Then MediaPlayer1.Pause
    timer1.Enabled = False
End Sub

Sub timer1_Tick
    If MediaPlayer1.IsPlaying Then
        barPosition.Value = MediaPlayer1.Position / MediaPlayer1.Duration * 100
        lblPosition.Text = "Position: " & ConvertToTimeFormat(MediaPlayer1.Position) & _
            " (" & ConvertToTimeFormat(MediaPlayer1.Duration) & ")"
    End If
End Sub

'converts milliseconds to m:ss format.
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 barVolume_ValueChanged (Value As Int, UserChanged As Boolean)
    MediaPlayer1.SetVolume(barVolume.Value / 100, barVolume.Value / 100)
End Sub

Sub barPosition_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged = False Then Return 'the value was changed programmatically
    MediaPlayer1.Position = Value / 100 * MediaPlayer1.Duration
    If MediaPlayer1.IsPlaying = False Then
        MediaPlayer1.Play
    End If
    timer1_Tick
End Sub

Private Sub bplay_Click
    If MediaPlayer1.IsInitialized Then
        If MediaPlayer1.IsPlaying = False Then
            MediaPlayer1.Play
        End If
    End If
    
End Sub

Private Sub bpause_Click
    If MediaPlayer1.IsInitialized Then
        If MediaPlayer1.IsPlaying Then
            MediaPlayer1.Pause
        End If
    End If
End Sub


Does anyone have any experience in this area they would be willing to share with me?
Thanks in advance.
 
Top