Android Question how to stop particular mediaplayer while using multiple instances

mkvidyashankar

Active Member
Licensed User
Longtime User
Hi

I am using multiple instances of Media player to play different combination of mediafiles. I would like to stop play of one particular audio file. How to do that?
 

mkvidyashankar

Active Member
Licensed User
Longtime User
Thanks for the reply

I tried using the same

B4X:
Dim index As Int = clv2.GetItemFromView(Sender)
    Dim idd As Int =clv2.GetValue(index)
    Dim mp As MediaPlayer=MediaPlayers.Get(idd)
    If mp.IsPlaying Then mp.Stop

but I am getting this error

HTML:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 276 (Main)
java.lang.RuntimeException: Method: IsPlaying not found in: java.lang.String
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:968)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:621)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:707)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4475)
    at android.view.View$PerformClick.run(View.java:18786)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)

I am using Audio library verson 1.63

please help
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
hi
here is the code
B4X:
ub CheckBox1_CheckedChange(Checked As Boolean)
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim idd As Int =clv2.GetValue(index)
    Dim cursor1 As Cursor
   
        cursor1= sql1.ExecQuery("SELECT * FROM table1 WHERE ID = " & idd )
        For i = 0 To cursor1.RowCount-1
            cursor1.Position=i
            'ID=cursor1.GetInt2(0)
            scheme= cursor1.GetString2(1)
            imagepath=cursor1.GetString2(2)
            desription=cursor1.GetString2(3)
            sound1=cursor1.GetString2(4)
            MediaPlayers.put(idd,sound1)
        Next
        cursor1.Close
       
    If checkbox1.Checked  Then
       
        spsample.Initialize
        If spsample.IsPlaying Then spsample.Stop
        spsample.Load(File.DirAssets,sound1)
        spsample.Play
    Else
        Dim mp As MediaPlayer=MediaPlayers.Get(sound1)
        If mp.IsPlaying Then mp.Stop
    End If
End Sub
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
Sorry some confusion, it is not working.

B4X:
ub ChkBx_CheckedChange(Checked As Boolean)
    'Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As Panel = lst.FindPanelContaining(Sender)
    'Dim checkbox1 As CheckBox = pnl.GetView(2)
    Dim idd As Int =pnl.Tag
    Dim cursor1 As Cursor
   
        cursor1= sql1.ExecQuery("SELECT * FROM table1 WHERE ID = " & idd )
        For i = 0 To cursor1.RowCount-1
            cursor1.Position=i
            'ID=cursor1.GetInt2(0)
            scheme= cursor1.GetString2(1)
            imagepath=cursor1.GetString2(2)
            desription=cursor1.GetString2(3)
            sound1=cursor1.GetString2(4)
            MediaPlayers.put(idd,sound1)
        Next
        cursor1.Close
       
    If Checked  Then
        spsample.Initialize
        If spsample.IsPlaying Then spsample.Stop
        spsample.Load(File.DirAssets,sound1)
        spsample.Play
    End If   
    If Checked=False Then
        Dim mp As MediaPlayer=MediaPlayers.Get(idd)
        mp.Stop
    End If

still i dnt understand mp.stop(last line).

getting this error
java.lang.RuntimeException: Method: Stop not found in: java.lang.String


mp is assigned as string
how to stop the mediaplayer which is assigned in the previous line.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sorry some confusion, it is not working.
You are NOT storing Mediaplayers in your list as said in #6
Your list contains STRINGS.
A String does not have a Stop method
 
Upvote 0
Top