0

In our Gamefield class do we want to start a simple Mediaplayer with a Backgroundmusik like this

public GameField(Context context, int width, int height) {
    super(context);
    getHolder().addCallback(this);
    // get an instance of the gameLoop
    setFocusable(true); // events happen on this view

    //Starting soundloop
    MediaPlayer play = MediaPlayer.create(this.getContext(), R.raw.coryphee_coryphee);
    play.setLooping(true);
    play.start(); ......

This actually stops after some time playing the musik. In our Mainacivity do we start a Mediaplayer like this and it does not stop playing.

Why does it stop and how can if fix it? We fixed it with running it in a Thread but i think it should work like this. Every tutorial i could find do it like this so i am a bit helpless

Best Regards and thanks alot.

bemeyer
  • 6,154
  • 4
  • 36
  • 86
  • Is that view object active and visible the entire time as well? If the object that owns the `MediaPlayer` gets garbage collected for any reason, playback will cease. – devunwired Nov 14 '12 at 18:49
  • Yes it's our serface view where we render the picture. (Canvas) – bemeyer Nov 14 '12 at 20:23
  • Possible duplicate of [MediaPlayer stop playing after about 5 seconds](http://stackoverflow.com/questions/6241687/mediaplayer-stop-playing-after-about-5-seconds) – hcarrasko Dec 28 '16 at 03:30

1 Answers1

3

Look at this one it is the same case for you.

Link

but i think it is something else at your case.

Community
  • 1
  • 1
Omarj
  • 1,151
  • 2
  • 16
  • 43
  • 1
    This actually worked for us. I wonder why it does this. We defined it as private Metiaplayer play and it still stoped. As Static it worked. Thanks – bemeyer Nov 15 '12 at 09:22