I am having some trouble using the android MediaPlayer in a non activity class, always a context error. Here is the bugged line:
MediaPlayer Shoot = MediaPlayer.create(this, R.raw.shot);
Now I know I cant use “this” in a service, but all the other stuff I tried kept giving bugs.
any suggestions?
You are too luck because in the last two days I have develop an app that uses MediaPlayer inside a background Service 😉
You can simply retrieve an instance of your MediaPlayer using the next line:
Then you can set all listener and play song that you want.
Edit 22th april 2012
To set listeners (an example):
To start and play song you have to do something like this: