Back to project page audioplayer.
The source code is released under:
GNU General Public License
If you think the Android project audioplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package fr.julien_dumortier.simplemusicplayer.service.bluetoohactionmanager; //w w w . ja v a2 s . co m import fr.julien_dumortier.simplemusicplayer.service.playlist.MusicMediaPlayer; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.view.KeyEvent; public class BluetoothReceiver extends BroadcastReceiver{ public static MusicMediaPlayer mMusicMediaPlayer; public void onReceive(Context context, Intent intent) { final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event.getAction() != KeyEvent.ACTION_DOWN) return; if(mMusicMediaPlayer!=null) switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_STOP: case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if(mMusicMediaPlayer.isPlaying()) mMusicMediaPlayer.pause(); else mMusicMediaPlayer.resume(); break; case KeyEvent.KEYCODE_MEDIA_NEXT: mMusicMediaPlayer.next(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: mMusicMediaPlayer.last(); break; } } }