Android Open Source - RadioRake Remote Control Receiver






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.asp.radiorake;
//from w ww  . j  a  v a2  s  .  co m
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.KeyEvent;
import com.aspillai.R;


public class RemoteControlReceiver extends BroadcastReceiver {

    private static final String TAG = "com.asp.radiorake.RemoteControlReceiver";

    public RemoteControlReceiver() {
        super();
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d(TAG, "RemoteControlReceiver.onReceive");

        RadioApplication radioApplication = (RadioApplication) context.getApplicationContext();
        MediaPlayer mediaPlayer = radioApplication.getMediaPlayer();

        String intentAction = intent.getAction();
        if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
            return;
        }

        KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        int action = event.getAction();
        int keyCode = event.getKeyCode();

        if (action == KeyEvent.ACTION_DOWN) {
            Intent playerIntent;
            switch (keyCode) {
                case KeyEvent.KEYCODE_MEDIA_STOP:
                    if (mediaPlayer.isPlaying()) {
                        Log.d(TAG, "Bluetooth stop received");
                        playerIntent = createPlayingIntent(context, null, RadioApplication.StopPlaying);
                        PlayerService.sendWakefulWork(context, playerIntent);
                    }
                    break;
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                    if (mediaPlayer.isPlaying()) {
                        Log.d(TAG, "Bluetooth pause received");
                        playerIntent = createPlayingIntent(context, null, RadioApplication.PausePlaying);
                        PlayerService.sendWakefulWork(context, playerIntent);
                    } else {
                        Log.d(TAG, "Bluetooth resume received");
                        playerIntent = createPlayingIntent(context, null, RadioApplication.ResumePlaying);
                        PlayerService.sendWakefulWork(context, playerIntent);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    protected Intent createPlayingIntent(Context context, RadioDetails radioDetails, int operation) {
        Intent intent = new Intent("com.asp.radiorake.PlayerService");

        if (radioDetails != null) {
            intent.putExtra(context.getString(R.string.radio_details_key), radioDetails);
        }

        intent.putExtra(context.getString(R.string.player_service_operation_key), operation);
        return intent;
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java