Android Question Why does MediaPlayer not work in a class module?

wdegler

Active Member
Licensed User
Longtime User
I have a test program with a class module and an MP3 file in the files list.
The following code works in the main module: I hear the sound.

Dim MP as MediaPlayer
MP.Initialize
MP.Load(File.DirAssets,"Note.MP3")
MP.Play

This same code does NOT work in the class module even though debugging does step through it.: I do not hear the sound.
Can someone tell me why?
It would be convenient in my project if there is a way to play the sound in the class module.
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
It should work in a service class, I've used a service class to control both mediaplayer and soundpool object without any issue. Just be sure in the Service_Destory to stop any mediaplayer/soundpool that might be on-going.
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Classes can do whatever activities and services can do. They share the context with their parent module (module where it was initialized).

Please upload a small project which demonstrates the problem.
Thank you, Erel, for your response. It is good to know that sounds CAN be played in a class. I prepared a small project to illustrate the problem but it DOES work there so there is no reason for me to send it. My rather large project does not work with a class so I am now using an Activity module where it does work. Eventually, I expect to figure out why the class module did not work in my project.
Thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…