0

I would create a small app that uses the accelerometer sensor to start the mp3 player. Basically my idea is this: 1) start the application 2) Turn off the screen of your smartphone 3) shake the cell 4) start the mp3 player, with a song by default

I'm not expert in programming in Android, I hope in your help

bisssi
  • 63
  • 9

1 Answers1

0

Look at my sample for shaking device at this link

For mediaPlayer:

public static void playMusic(Context context, int beepType) {
        try { 

            mMediaPlayer = MediaPlayer.create(context, R.raw.mymusic);

            mMediaPlayer.setLooping(false);
            mMediaPlayer.start();
            mMediaPlayer.setOnCompletionListener(new
                    OnCompletionListener() {
                        public void onCompletion(MediaPlayer arg0) {
                            // if (mMediaPlayer != null) {
                            // mMediaPlayer.release();
                            // mMediaPlayer = null;
                            // }
                        }
                    });
        } catch (Exception e) {
            if (mMediaPlayer != null) {
                mMediaPlayer.release();
                mMediaPlayer = null;
            }
        }
    }
Community
  • 1
  • 1
Bob
  • 22,810
  • 38
  • 143
  • 225
  • can you check this out http://stackoverflow.com/questions/36643083/can-anyone-tell-me-how-do-i-start-mp3 – Abhishek Apr 15 '16 at 10:04