<commit_before>package net.x4a42.volksempfaenger.receiver;

import net.x4a42.volksempfaenger.service.PlaybackService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

public class MediaButtonEventReceiver extends BroadcastReceiver {
	static boolean ignoreNext = false;

	@Override
	public void onReceive(Context context, Intent intent) {
		if (!Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
			return;
		}

		final KeyEvent event = (KeyEvent) intent
				.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

		if (event == null) {
			return;
		}
		// FIXME
		// intents are being received twice
		// we do not know why, so ignore every second intent
		if (ignoreNext) {
			ignoreNext = false;
			return;
		} else {
			ignoreNext = true;
		}
		switch (event.getKeyCode()) {
		case KeyEvent.KEYCODE_MEDIA_PLAY:
			break;
		case KeyEvent.KEYCODE_MEDIA_PAUSE:
			break;
		case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
			Intent keyIntent = new Intent(context, PlaybackService.class);
			keyIntent.setAction(Intent.ACTION_MEDIA_BUTTON);
			keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
			context.startService(keyIntent);
			break;
		default:
			return;
		}
	}
}<commit_msg>Please give us a big round of facepalm for fixing the problem with media button intents being received twice. One was the DOWN and the other one the UP intent, fixes #5.<commit_after>package net.x4a42.volksempfaenger.receiver;

import net.x4a42.volksempfaenger.service.PlaybackService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

public class MediaButtonEventReceiver extends BroadcastReceiver {

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

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

		final KeyEvent event = (KeyEvent) intent
				.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

		if (event == null) {
			return;
		}

		if (event.getAction() == KeyEvent.ACTION_UP) {
			switch (event.getKeyCode()) {
			case KeyEvent.KEYCODE_MEDIA_PLAY:
				break;
			case KeyEvent.KEYCODE_MEDIA_PAUSE:
				break;
			case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
				Intent keyIntent = new Intent(context, PlaybackService.class);
				keyIntent.setAction(Intent.ACTION_MEDIA_BUTTON);
				keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
				context.startService(keyIntent);
				break;
			default:
				return;
			}
		}

	}

}
{'fraction_non_alphanumeric': 0.09235668789808917, 'fraction_numerical': 0.0051751592356687895, 'mean_word_length': 4.46304347826087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4370562', 'n_tokens_mistral': 915, 'n_tokens_neox': 807, 'n_words': 180}