Android Question Media play by Blutooth headset instead of wire headset.

LUHUANWEI

Member
Licensed User
It is possible to play media via Bluetooth headset while both BT headset and wire headset are connected? or play media by both BT headset and wire headset in the same time, now only wire headset when I play the media. My code as below.

Sub SetEarPhone(Value As Boolean)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Dim mode As Int
If Value Then mode = 2 Else mode = 0
r.RunMethod2("setMode", mode, "java.lang.int")
End Sub
Sub StartBluetoothSco()
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod("startBluetoothSco")
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod2("setMode", 2, "java.lang.int")
End Sub
Sub Activity_Create(FirstTime As Boolean)
SetEarPhone(True)
StartBluetoothSco
End Sub
Sub Activity_Pause(UserClosed As Boolean)
SetEarPhone(False)
End Sub
 

LUHUANWEI

Member
Licensed User
Hi Erel,
Thanks for reply, because I am poor on Java, hope to have more details about how to set audio stream and where should I insert the code you posted, thank you very much!
 
Upvote 0

LUHUANWEI

Member
Licensed User
Hi Erel,
How to understand this:
jo.GetFieldJO("mp").RunMethod("setAudioStreamType", Array(2))
what is "mp" and what is "Array(2)"?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi, I'm not Erel but please have a look here.

mp stands for MediaPlayer
method "setAudioStreamType" expects an int; passing 2 is like passing the costant "STREAM_RING" as noted by Erel in his post above.
Other possible audio stream type values may be found here.
 
Last edited:
Upvote 0

LUHUANWEI

Member
Licensed User
Dear All,
I got below error when I debug my app, sp is Mediaplayer dim in Sub Process_Globals. I can't understand why sp not found.
Hope to get more help on API, thanks.

** Activity (main) Create, isFirst = true **
Error occurred on line: 125 (Main)
java.lang.RuntimeException: Field: sp not found in: anywheresoftware.b4a.objects.MediaPlayerWrapper
at anywheresoftware.b4j.object.JavaObject$FieldCache.getField(JavaObject.java:306)
at anywheresoftware.b4j.object.JavaObject.GetField(JavaObject.java:181)
at anywheresoftware.b4j.object.JavaObject.GetFieldJO(JavaObject.java:188)
at KUXUAN.YIN.main._activity_create(main.java:559)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at KUXUAN.YIN.main.afterFirstLayout(main.java:102)
at KUXUAN.YIN.main.access$000(main.java:17)
at KUXUAN.YIN.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top