//apparently, a few 4.3 devices have an issue with com.android.music.metachanged....
//stickyBroadcast.setAction(playbackHasChanged ? "com.android.music.playstatechanged" : "com.android.music.metachanged");
@SuppressWarnings("deprecation")
	private static void broadcastStateChange(String title, boolean preparing, boolean titleOrSongHaveChanged) {
		if (notificationBroadcastPending) {
			localHandler.removeMessages(MSG_BROADCAST_STATE_CHANGE);
			notificationBroadcastPending = false;
		}
		final long now = SystemClock.uptimeMillis();
		final long delta = now - notificationLastUpdateTime;
		if (delta < 100 || notificationLastUpdateTime == 0) {
			notificationBroadcastPending = true;
			localHandler.sendMessageAtTime(Message.obtain(localHandler, MSG_BROADCAST_STATE_CHANGE, (preparing ? 0x01 : 0) | (titleOrSongHaveChanged ? 0x02 : 0), 0, title), (notificationLastUpdateTime == 0 ? ((notificationLastUpdateTime = now) + 2000) : (notificationLastUpdateTime + 110 - delta)));
			return;
		}
		notificationLastUpdateTime = now;
		refreshNotification();
		WidgetMain.updateWidgets();
		//
		//perhaps, one day we should implement RemoteControlClient for better Bluetooth support...?
		//http://developer.android.com/reference/android/media/RemoteControlClient.html
		//https://android.googlesource.com/platform/packages/apps/Music/+/master/src/com/android/music/MediaPlaybackService.java
		//
		//http://stackoverflow.com/questions/15527614/send-track-informations-via-a2dp-avrcp
		//http://stackoverflow.com/questions/14536597/how-does-the-android-lockscreen-get-playing-song
		//http://stackoverflow.com/questions/10510292/how-to-get-current-music-track-info
		//
		//https://android.googlesource.com/platform/packages/apps/Bluetooth/+/android-4.3_r0.9.1/src/com/android/bluetooth/a2dp/Avrcp.java
		//
		if (localSong == null) {
			stickyBroadcast.setAction("com.android.music.playbackcomplete");
			stickyBroadcast.removeExtra("id");
			stickyBroadcast.removeExtra("songid");
			stickyBroadcast.removeExtra("track");
			stickyBroadcast.removeExtra("artist");
			stickyBroadcast.removeExtra("album");
			stickyBroadcast.removeExtra("duration");
			//stickyBroadcast.removeExtra("position");
			stickyBroadcast.removeExtra("playing");
		} else {
			//apparently, a few 4.3 devices have an issue with com.android.music.metachanged....
			//stickyBroadcast.setAction(playbackHasChanged ? "com.android.music.playstatechanged" : "com.android.music.metachanged");
			stickyBroadcast.setAction("com.android.music.playstatechanged");
			stickyBroadcast.putExtra("id", localSong.id);
			stickyBroadcast.putExtra("songid", localSong.id);
			stickyBroadcast.putExtra("track", title);
			stickyBroadcast.putExtra("artist", localSong.artist);
			stickyBroadcast.putExtra("album", localSong.album);
			stickyBroadcast.putExtra("duration", (long)localSong.lengthMS);
			//stickyBroadcast.putExtra("position", (long)0);
			stickyBroadcast.putExtra("playing", localPlaying);
		}
		// maybe check if api >= 21, and if so, use sendBroadcast instead.....???
		// https://developer.android.com/reference/android/content/Context#sendStickyBroadcast(android.content.Intent)
		try {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
				thePlayer.sendBroadcast(stickyBroadcast);
			else
				thePlayer.sendStickyBroadcast(stickyBroadcast);
		} catch (RuntimeException ex) {
			//just ignore because most apps actually use RemoteControlClient on newer Androids
		}
		if (remoteControlClient != null)
			broadcastStateChangeToRemoteControl(title, preparing, titleOrSongHaveChanged);
		if (mediaSession != null)
			broadcastStateChangeToMediaSession(title, preparing, titleOrSongHaveChanged);
	}
stickyBroadcast.removeExtra("playing");
} else {
//apparently, a few 4.3 devices have an issue with com.android.music.metachanged....
//stickyBroadcast.setAction(playbackHasChanged ? "com.android.music.playstatechanged" : "com.android.music.metachanged");
stickyBroadcast.setAction("com.android.music.playstatechanged");
stickyBroadcast.putExtra("id", localSong.id);
stickyBroadcast.setAction("com.android.music.playbackcomplete");
stickyBroadcast.removeExtra("id");
stickyBroadcast.removeExtra("songid");
stickyBroadcast.removeExtra("track");
stickyBroadcast.removeExtra("artist");
stickyBroadcast.removeExtra("album");
stickyBroadcast.removeExtra("duration");
//stickyBroadcast.removeExtra("position");
stickyBroadcast.removeExtra("playing");
} else {
//apparently, a few 4.3 devices have an issue with com.android.music.metachanged....
//stickyBroadcast.setAction(playbackHasChanged ? "com.android.music.playstatechanged" : "com.android.music.metachanged");
stickyBroadcast.setAction("com.android.music.playstatechanged");
stickyBroadcast.putExtra("id", localSong.id);
stickyBroadcast.putExtra("songid", localSong.id);
stickyBroadcast.putExtra("track", title);
stickyBroadcast.putExtra("artist", localSong.artist);
stickyBroadcast.putExtra("album", localSong.album);
stickyBroadcast.putExtra("duration", (long)localSong.lengthMS);
//stickyBroadcast.putExtra("position", (long)0);
stickyBroadcast.putExtra("playing", localPlaying);
}
//http://developer.android.com/reference/android/media/RemoteControlClient.html
//https://android.googlesource.com/platform/packages/apps/Music/+/master/src/com/android/music/MediaPlaybackService.java
//
//http://stackoverflow.com/questions/15527614/send-track-informations-via-a2dp-avrcp
//http://stackoverflow.com/questions/14536597/how-does-the-android-lockscreen-get-playing-song
//http://stackoverflow.com/questions/10510292/how-to-get-current-music-track-info
//
//https://android.googlesource.com/platform/packages/apps/Bluetooth/+/android-4.3_r0.9.1/src/com/android/bluetooth/a2dp/Avrcp.java
//
if (localSong == null) {
stickyBroadcast.setAction("com.android.music.playbackcomplete");
stickyBroadcast.removeExtra("id");
stickyBroadcast.removeExtra("songid");
stickyBroadcast.removeExtra("track");
stickyBroadcast.removeExtra("artist");
stickyBroadcast.removeExtra("album");
stickyBroadcast.removeExtra("duration");
//stickyBroadcast.removeExtra("position");
stickyBroadcast.removeExtra("playing");
} else {
//apparently, a few 4.3 devices have an issue with com.android.music.metachanged....
//stickyBroadcast.setAction(playbackHasChanged ? "com.android.music.playstatechanged" : "com.android.music.metachanged");
stickyBroadcast.setAction("com.android.music.playstatechanged");
stickyBroadcast.putExtra("id", localSong.id);
stickyBroadcast.putExtra("songid", localSong.id);
stickyBroadcast.putExtra("track", title);
stickyBroadcast.putExtra("artist", localSong.artist);
stickyBroadcast.putExtra("album", localSong.album);
stickyBroadcast.putExtra("duration", (long)localSong.lengthMS);
//stickyBroadcast.putExtra("position", (long)0);
stickyBroadcast.putExtra("playing", localPlaying);
}
// maybe check if api >= 21, and if so, use sendBroadcast instead.....???
// https://developer.android.com/reference/android/content/Context#sendStickyBroadcast(android.content.Intent)
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
thePlayer.sendBroadcast(stickyBroadcast);
else
thePlayer.sendStickyBroadcast(stickyBroadcast);
} catch (RuntimeException ex) {
//just ignore because most apps actually use RemoteControlClient on newer Androids
}