I am receiving 4 rtsp video links simultaneously in a single screen using videoview in the audio library... I want to mute individual videos when clicking on a button... But videoview doesnot have an option to mute audio...i want to play audio of single stream at a time and mute others... How can i do that?
Sub muteaudio_v1
Dim r1, r2 As Reflector
r1.Target = v1
r1.Target = r1.GetField("mMediaPlayer")
Dim mp As MediaPlayer
r2.Target = mp
r2.SetField("mp", r1.Target, "android.media.MediaPlayer")
mp.SetVolume(0,0)
End Sub
this shows error on setfield line after running the program
LogCat connected to: HT22WV810549
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 107 (main)
java.lang.IllegalArgumentException: invalid value for field
at java.lang.reflect.Field.setField(Native Method)
at java.lang.reflect.Field.set(Field.java)
at anywheresoftware.b4a.agraham.reflection.Reflection.SetField(Reflection.java:401)
at b4a.example.main._muteaudio_v1(main.java:697)
at b4a.example.main._play(main.java:495)
at b4a.example.main._button1_click(main.java:385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
B4X:
Sub muteaudio_v1
Dim r1, r2 As Reflector
r1.Target = v1
r1.Target = r1.GetField("mMediaPlayer")
Dim mp As MediaPlayer
r2.Target = mp
r2.SetField("mp", r1.Target, "android.media.MediaPlayer")
mp.SetVolume(0,0)
End Sub
line 107 is "r2.SetField("mp", r1.Target, "android.media.MediaPlayer")"
v1 is my "videoview v1"
Sub Activity_Create(FirstTime As Boolean)
Dim vv As VideoView
vv.Initialize("vv")
Activity.AddView(vv, 0, 0, 100%X, 100%y)
vv.LoadVideo(File.DirRootExternal, "DCIM/Camera/1.mp4")
vv.Play
CallSubDelayed2(Me, "MuteVideo", vv)
End Sub
Sub muteVideo (vv As VideoView)
Dim r1, r2 As Reflector
r1.Target = vv
r1.Target = r1.GetField("mMediaPlayer")
If r1.Target = Null Then
CallSubDelayed2(Me, "MuteVideo", vv)
Return
End If
Dim mp As MediaPlayer
r2.Target = mp
r2.SetField2("mp", r1.Target)
mp.SetVolume(0,0)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim vv As VideoView
vv.Initialize("vv")
Activity.AddView(vv, 0, 0, 100%X, 100%y)
vv.LoadVideo(File.DirRootExternal, "DCIM/Camera/1.mp4")
vv.Play
CallSubDelayed2(Me, "MuteVideo", vv)
End Sub
Sub muteVideo (vv As VideoView)
Dim r1, r2 As Reflector
r1.Target = vv
r1.Target = r1.GetField("mMediaPlayer")
If r1.Target = Null Then
CallSubDelayed2(Me, "MuteVideo", vv)
Return
End If
Dim mp As MediaPlayer
r2.Target = mp
r2.SetField2("mp", r1.Target)
mp.SetVolume(0,0)
End Sub
It uses reflection to get a reference to the internal MediaPlayer of VideoView. The internal MediaPlayer is not immediately ready so CallSubDelayed is used to wait for it.
So its the same thing that shown in the link i posted..... Any way it was pleasure to communicate with the real developer who created all this stuff.. Community is working well for me.. Also am suggesting my friend to buy this..
It uses reflection to get a reference to the internal MediaPlayer of VideoView. The internal MediaPlayer is not immediately ready so CallSubDelayed is used to wait for it.
Erel one more help...
I have to full screen the video when i touch the video, so i created 4 panels for 4 videoviews ,when i play i can see only one panel cant see 3 other videos...if there is a panel beneath videoview i can simply write code inside "panel_click"..so thats my first problem(I wanna to get some thing linke v4.click)...
===================
one other thing is that
in above code am trying to make v4 to fullscreen when i press a button...here v1,v2,v3 videoviews setlayout function is making the video area into a smaller space and its working immediately....but if i simply gave "v4.SetLayout(0%x,0%x,100%x,100%y)" this does not works....But it works if i remove v4 view and connect once again...but v1,v2,v3 videoviews does not need to remove to make it smaller....... So the problem is "setlayout" can immediately make video to a smaller space ..but making it to a larger space is not working without reconnecting agin
above code is working good but removing view and adding it again make a lot of time to connect to video agin because am streaming a rtsp link..
Sorry for long post,I hope you understand what i need
Erel your way for controlling audio is working good but only after removing layout and reconnecting again..its so bad that i cant control video whenever i want without reconnecting to my http stream....please find a solution..below code is working but by reconnecting but calling "CallSubDelayed2(Me, "Volume1", v1)" simply will not change anything
B4X:
Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
vol1=Value
' Msgbox(vol1,False)
v1.stop
v1.RemoveView
Activity.AddView(v1, 0%x, 0%y, 100%x,100%y)
v1.LoadVideo("http", a)
v1.SetLayout(2%x, 15%y, 45%x,55%y)
Activity.Invalidate
CallSubDelayed2(Me, "Volume1", v1)
v1.Play
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim vv As VideoView
vv.Initialize("vv")
Activity.AddView(vv, 0, 0, 100%X, 100%y)
vv.LoadVideo(File.DirRootExternal, "DCIM/Camera/1.mp4")
vv.Play
CallSubDelayed2(Me, "MuteVideo", vv)
End Sub
Sub muteVideo (vv As VideoView)
Dim r1, r2 As Reflector
r1.Target = vv
r1.Target = r1.GetField("mMediaPlayer")
If r1.Target = Null Then
CallSubDelayed2(Me, "MuteVideo", vv)
Return
End If
Dim mp As MediaPlayer
r2.Target = mp
r2.SetField2("mp", r1.Target)
mp.SetVolume(0,0)
End Sub
Erel please help me its urgent...above code is working only for muting audio..but once it is muted i cant raise the volume up...but if i remove view and connect again it will get volume...that is not a good practice...so please gave solution fast...am in a hurry sorry...