MediaPlayer with looped audio not stopping on app onPause?

When you declare the MediaPlayer in your onCreate, it shadows the member mp, so all of the methods are performed on the object declared in onCreate, not on the class member: MediaPlayer mp = MediaPlayer. Create(this, R.raw. Longstream) Change it to public MediaPlayer mp; @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); mp = MediaPlayer. Create(this, R.raw. Longstream); mp.

SetVolume(0.2f, 0.2f); mp. SetLooping(true); mp.start(); }.

When you declare the MediaPlayer in your onCreate, it shadows the member mp, so all of the methods are performed on the object declared in onCreate, not on the class member: MediaPlayer mp = MediaPlayer. Create(this, R.raw. Longstream); Change it to public MediaPlayer mp; @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); mp = MediaPlayer. Create(this, R.raw. Longstream); mp.

SetVolume(0.2f, 0.2f); mp. SetLooping(true); mp.start(); }.

This is your code modified, it should work this way: the problem came from the fact that you declare mp as an attribute of your class, but you then instantiate it locally in your onCreate method. Public MediaPlayer mp; @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); mp = MediaPlayer.

Create(this, R.raw. Longstream); mp. SetVolume(0.2f, 0.2f); mp.

SetLooping(true); mp.start(); }.

I've written an app which has some looped audio playing in the background (via MediaPlayer). When the app is ended (e.g. However, it seems that by the time onPause is called the mediaplayer (mp) object is always null, even though the looped audio is still being played. So it can't be stopped.

So, am I declaring the mediaplayer incorrectly? Or how do I get it to persist to be closed properly? And how come it is still playing if the object is null?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions