Android Question VideoView Volume Control Problem

biometrics

Active Member
Licensed User
Longtime User
I need to control the volume of two videoviews to cross fade the audio when the one stops playing (fading out/volume going to silent) and the other starts playing (fading in/volume going to maximum). I can't use the phone volume control as that is global.

I use the code Erel posted here: https://www.b4x.com/android/forum/threads/mute-audio-in-videoview.39122/#post-232208

This code should work:
B4X:
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

We use this Android 4.4 device as a media player for digital signage: http://giadatech.com/pshow-65.html

20150702191825377.jpg


20150702192014175.jpg


I was using a monitor with DVI input and a HDMI to DVI cable when I was developing the code. I was listening to the sound with headphones via the 3.5mm earphone port. It was working well.

I am now testing using a monitor with HDMI input and a HDMI to HDMI cable. This monitor has speakers so I'm not using the 3.5 mm earphone port. The code is failing now.

The following code from Erel's example is repeating and never gets past the If statement:

B4X:
If r1.Target = Null Then
    CallSubDelayed2(Me, "MuteVideo", vv)
    Return
End If

Any assistance will be greatly appreciated.
 

biometrics

Active Member
Licensed User
Longtime User
Turns out you can't set the VideoView volume if it's set to invisible.

Might still convert to ExoPlayer but I'll see if this works tomorrow at the office.
 
Upvote 0

biometrics

Active Member
Licensed User
Longtime User
Ok, I give up on setting the volume on a VideoView, it's just not reliable. ExoPlayer here I come ...
 
Upvote 0
Top