0

I want a simple app that when launched starts playing a music and continiously runs a gif animation, how can I do it, I can't get the mediaplayer to start.. This is what I have so far

public class Main extends Activity {
    MediaPlayer music;
    AnimationDrawable background;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        music = MediaPlayer.create(Main.this, R.raw.thesong);

    }
}
Barney
  • 2,355
  • 3
  • 22
  • 37
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81

1 Answers1

2

You're missing 2 lines below your new MediaPlayer instance:

music = MediaPlayer.create(Main.this, R.raw.thesong); 
music.setLooping(true);
music.start();

Not that this matter much, you should really be staying off the main UI thread to play your music, which you're not.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • very weird, tried it earlier with only the start(); and it didn't worked... and how can I run the gif animation please? – Sartheris Stormhammer Apr 11 '13 at 18:55
  • For the animated gif, I'm thinking displaying the gif inside a WebView should do it (thought, I'm only 80% sure about that, unfortunately, I don't have the time to double-check that right now). – Stephan Branczyk Apr 11 '13 at 18:59
  • It doesn't matter, for it to work reliably without giving some of your users an Application Not Responding message, you'll have to play your music inside a Service (even if you end up binding that Service to the Activity, so that it stops when the Activity is no longer visible) – Stephan Branczyk Apr 11 '13 at 19:01
  • Here: http://stackoverflow.com/a/3028672/320111 You don't need to implement the main accepted answer (since the original question is different from yours). The second answer provided by Maneesh to that same question however should be enough to solve the issue in your particular use case. – Stephan Branczyk Apr 11 '13 at 19:17