@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); Log.d(TAG, ">> mBroadcastReceiver action received = " + action); mHandler.removeMessages(Constants.HANDLER_MESSAGE_PLAY_RADIO_CHANNEL_TIMEOUT); // send handler message switch (action) { case MusicService.ACTION_PLAYED: case MusicService.ACTION_PAUSED: case MusicService.ACTION_COMPLETED: case MusicService.ACTION_ERROR: case MusicService.ACTION_STOPPED: case MusicService.ACTION_PLAYING_STATUS: Message msg = new Message(); msg.what = HANDLER_MESSAGE_MUSIC_SERVICE_ACTION; Bundle b = new Bundle(); b.putString(MusicService.EXTRA_ACTION, action); b.putSerializable( MusicService.EXTRA_PLAYING_STATUS, intent.getSerializableExtra(MusicService.EXTRA_PLAYING_STATUS)); b.putParcelable( MusicService.EXTRA_MUSIC_ITEM, intent.getParcelableExtra(MusicService.EXTRA_MUSIC_ITEM)); msg.setData(b); mHandler.sendMessage(msg); break; default: break; } }
@Override public void onPlayRadioRequest(RadioChannelInfo.RadioChannel channel) { Log.d(TAG, "> User select radio channel... show progrss and ...."); showProgressDialog(); if (channel != null) { Intent i = new Intent(this, MusicService.class); i.setAction(MusicService.ACTION_URL); MusicRetriever.Item item = new MusicRetriever.Item(0, -1, null, channel.channelName, null, channel.channelUrl, 0); i.putExtra(MusicService.EXTRA_MUSIC_ITEM, item); startService(i); mHandler.sendEmptyMessageDelayed(Constants.HANDLER_MESSAGE_PLAY_RADIO_CHANNEL_TIMEOUT, 10000); } }
public void handleMessage(Message msg) { if (msg == null) { return; } switch (msg.what) { // 라디오목록 가져오기 완료. case Constants.HANDLER_MESSAGE_GET_RADIO_CHANNEL_TASK: RadioChannelInfo data = (RadioChannelInfo) msg.obj; dismissProgressDialog(); if (data != null && Constants.RESULT_OK.equals(data.getResultCode())) { mRadioChannelItems = data.getRadioChannelList(); if (mRadioChannelItems == null) { mRadioChannelItems = new ArrayList<>(); } } else { if (mRadioChannelItems == null) { mRadioChannelItems = new ArrayList<>(); } if (data == null) { data = new RadioChannelInfo(); data.setResultMessage(getString(R.string.server_connection_error)); } Intent i = new Intent(this, MusicService.class); i.setAction(MusicService.ACTION_STOP); i.putExtra(MusicService.EXTRA_MUSIC_FORCE_STOP, true); startService(i); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setPositiveButton( R.string.alert_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); // finish(); } }); alert.setMessage(data.getResultMessage()); try { alert.show(); } catch (Exception e) { } } mIsExecuteGetRadioChannelTask = false; getRadioChannelTask = null; setupRadioChannelPager(); break; // 라디오재생 요청에 대한 타임아웃. 미디어서비스에서 응답시간에 대한 타임아웃 case Constants.HANDLER_MESSAGE_PLAY_RADIO_CHANNEL_TIMEOUT: Intent i = new Intent(this, MusicService.class); i.setAction(MusicService.ACTION_STOP); i.putExtra(MusicService.EXTRA_MUSIC_FORCE_STOP, true); startService(i); break; // 볼륨키로 볼륨조절 시 case HANDLER_MESSAGE_STREAM_MUSIC_VOLUME_CHANGE: int currentVolume = msg.arg1; if (currentVolume <= 0) { mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_off); } else { mSoundToggle.setBackgroundResource(R.drawable.ic_button_radio_sound_on); } mSeekbar.setProgress(currentVolume); break; // 플레이어컨트롤 case HANDLER_MESSAGE_MUSIC_SERVICE_ACTION: Bundle b = msg.getData(); if (b == null) { Log.i(TAG, "HANDLER_MESSAGE_MUSIC_SERVICE_ACTION bundle is not found!!"); return; } String action = b.getString(MusicService.EXTRA_ACTION); MusicService.State state = (MusicService.State) b.getSerializable(MusicService.EXTRA_PLAYING_STATUS); MusicRetriever.Item item = b.getParcelable(MusicService.EXTRA_MUSIC_ITEM); if (state == MusicService.State.Playing) { mPlayToggle.setBackgroundResource(R.drawable.ic_btn_radio_pause_selector); mRadioTitle.setText(item.getTitle()); } else if (state == MusicService.State.Paused) { mPlayToggle.setBackgroundResource(R.drawable.ic_btn_radio_play_selector); mRadioTitle.setText(item.getTitle()); } else if (state == MusicService.State.Stopped) { mPlayToggle.setBackgroundResource(R.drawable.ic_btn_radio_play_selector); b.remove(MusicService.EXTRA_MUSIC_ITEM); mRadioTitle.setText(R.string.activity_radio_default_title); } else { mRadioTitle.setText(R.string.activity_radio_default_title); } mCurrentPlayingStatus = b; for (int idx = 0; idx < mActivityInteractionListener.size(); idx++) { mActivityInteractionListener.get(idx).onPlayItemChanged(b); } if (!mIsExecuteGetRadioChannelTask) { mHandler.sendEmptyMessageDelayed(HANDLER_MESSAGE_HIDE_PROGRESS_DIALOG, 1500); } break; // 프로그레스바 제거 case HANDLER_MESSAGE_HIDE_PROGRESS_DIALOG: dismissProgressDialog(); break; } }