You can obtain the Context
in several ways.
You can get it from the current view in the getView()
method of the adapter:
view.getContext();
Or you can pass the context to the adapter's constructor, remembering that a good practice involves using a WeakReference
, so that you do not generate leaks.
Once you do have the Context
, the code you are using just works:
player = MediaPlayer.create(context, R.raw.example);
player.prepare();
If you are using a WeakReference, your code will be:
player = MediaPlayer.create(mContext.get(), R.raw.example);
player.prepare();