Android Tutorial MediaPlayer tutorial

Pelican104

New Member
Licensed User
Longtime User
Hi Erel,

Doesn't the android mediaplayer have an AudioSessionID property which can be used to attach effects to a mediaplayer?

I can find some references to a GetAudioSessionID method in the android API documentation but can't access the method in b4A.

Thanks
 

stevel05

Expert
Licensed User
Longtime User
You can get the audioSessionID via reflection:

B4X:
       Dim MP As Mediaplayer

       MP.Initialize

   Dim R As Reflector
   R.Target=MP
   R.Target=R.GetField("mp")
   AudioSessionID=R.RunMethod("getAudioSessionId")

The question is, what do you want to do with it? The Audio Effects API's are not currently available to B4A, unless I've missed a library which is more than possible of course.
 

Pelican104

New Member
Licensed User
Longtime User
Thanks Steve, that works perfectly.

I'd been attempting to do this using reflection but without any joy, I hadn't used the line

R.Target=R.GetField("mp")

What is that line doing?

I need the Audio Session ID for use with the UltimateAudio library, I wanted to generate a visualisation of a specific media player rather than the total output.

Thanks for your assistance that's been a great lesson on reflection as much as anything else.
 

stevel05

Expert
Licensed User
Longtime User
Within the B4A mediaplayerwrapper, the field mp holds the java mediaplayer object.

R.GetField("mp") gets its contents.

-------------------
Sent via Tapatalk
 
Last edited:

birnesoft

Active Member
Licensed User
Longtime User
Set stereo volume balance

is it possiple to set the left and right volume of the mediaplayer like with the audiotrack lib?
 

birnesoft

Active Member
Licensed User
Longtime User
It works

Yes it works!! :wav:
Wow Erel you are genial.

the value of the left and the right volume have to be
between 0 and 1

thanks much Björn
 

latch

Active Member
Licensed User
Longtime User
Is there an event that fires when the track ends or do you periodically check .isplaying to see if you need to load the next track?
 

stevel05

Expert
Licensed User
Longtime User
If you use Initialize2 the complete event is called when play is finished.

B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim MP As MediaPlayer
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
MP.Initialize2("MP")
MP.Load(File.DirAssets,"file,mp3")
MP.Play
End Sub
Sub MP_Complete
   Log("Finished")
End Sub
 
Last edited:

aklisiewicz

Active Member
Licensed User
Longtime User
I have problem unziping this file.
Error:
! C:\INSTALLS\B4A\EXAMPLES\MediaPlayer.zip: Unknown method in
! C:\INSTALLS\B4A\EXAMPLES\MediaPlayer.zip: Unknown method in
! C:\INSTALLS\B4A\EXAMPLES\MediaPlayer.zip: Unknown method in
! C:\INSTALLS\B4A\EXAMPLES\MediaPlayer.zip: Unknown method in
! C:\INSTALLS\B4A\EXAMPLES\MediaPlayer.zip: No files to extract
 

texwillerx

Member
Licensed User
Longtime User
Using media player synchronously

I want to use media player.

My problem is that, I have to wait until the player finished the mp3 file.

I don't want to use a do loop.

Thanks and regards
 

rogeriosca

Member
Licensed User
Longtime User


Thanks ! Works perfectly on DEFY.
 

Larry

New Member
Licensed User
Longtime User
I followed the code and installed it just the same. When I added an .mp3 file instead of the .mid file, it freezes up every time... Any suggestions?
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello Erel,
how is it possible to set the sound, only when a button is long clicked?
 

Paul Edwards

Member
Licensed User
Longtime User
I've been working on a media player app. It works fine in the foreground, but stops when the phone goes to sleep. I know I need to add a Service Module so it can continue to play in the background. Is there an explanation of how to do this on this website?

Paul
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…