private void handleStartTag(String tag) { if (tag == null) { return; } if (tag.equalsIgnoreCase(TAG_CONTENT)) { String tempId = mXmlPullParser.getAttributeValue(null, REQUEST_ID); if (tempId != null && !tempId.trim().equals("") && !tempId.equals("null")) { mInfo._sessionId = Integer.parseInt(tempId); } String userKey = mXmlPullParser.getAttributeValue(null, ATTR_UK); if (userKey != null && !userKey.trim().equals("")) { mInfo._appId = userKey; mInfo._packageName = userKey; } String packageName = mXmlPullParser.getAttributeValue(null, ATTR_PACKAGE); if (packageName != null && !packageName.trim().equals("")) { mInfo._packageName = packageName; } } else if (tag.equalsIgnoreCase(TAG_COMMAND)) { mInfo._commandName = mXmlPullParser.getAttributeValue(null, ATTR_COMMAND_ID); } else if (tag.equalsIgnoreCase(TAG_ARG)) { mPraseState = PRASE_STATE_ARG; } }
private void handText(String text) { if (text.equals("\n") || text.equals("\n\t")) { return; } switch (mPraseState) { case PRASE_STATE_SUMMARY: mInfo._answer = text; break; case PRASE_STATE_ARG: mInfo.addArg(text); break; } }
public CommandInfo getInfo() { if (mInfo != null) { mInfo.standardizing(); } return mInfo; }
@Override public IVoiceCommand execute() { super.execute(); // TODO Auto-generated method stub String arg = mInfo.getArg(0); LogManager.i(TAG, "execute -----info:" + arg); // 记录歌曲命令开始执行的时间 SupKeyList.COMMAND_START_EXECUTE = System.currentTimeMillis(); int commandType = -1; if (mParamMap.containsKey(arg)) { commandType = Integer.valueOf(mParamMap.get(arg)); // TODO Intent i = new Intent(); if (commandType >= MusicUtil.COMMAND_NEXT && commandType <= MusicUtil.COMMAND_RANDOM) { mAirPlayMusicController.setAirplay(false); mAirPlayMusicController.stop(); this.getUnion().getRecogniseSystem().startWakeup(); } LogManager.i(TAG, "current commandType:" + commandType); switch (commandType) { case MusicUtil.COMMAND_EXIT: // TODO:如果添加停止音乐方法可能会影响到播放器状态,暂时改为暂停播放当前音乐 getUnion().getMediaInterface().pause(); mBaseContext.setGlobalLong("mediaPauseTime", System.currentTimeMillis()); mDlanMusicController.sendToDlanStop(); mAirPlayMusicController.stop(); this.getUnion().getRecogniseSystem().startWakeup(); break; case MusicUtil.COMMAND_STOP: if (mDlanMusicController.isDlan()) { LogManager.i(TAG, "dlna----------COMMAND_STOP---onpause"); mDlanMusicController.pause(); } else if (mAirPlayMusicController.isAirplay()) { LogManager.i(TAG, "airplay-----------COMMAND_STOP---onpause"); mAirPlayMusicController.pause(); } else { LogManager.i(TAG, "普通歌曲-----------COMMAND_STOP---onpause"); getUnion().getMediaInterface().pause(); mBaseContext.setGlobalLong("mediaPauseTime", System.currentTimeMillis()); } break; case MusicUtil.COMMAND_START: if (mDlanMusicController.isDlan()) { LogManager.i(TAG, "dlna----------COMMAND_START---play"); mDlanMusicController.paly(); } else if (mAirPlayMusicController.isAirplay()) { LogManager.i(TAG, "airplay----------COMMAND_START---play"); mAirPlayMusicController.play(); } else { LogManager.i(TAG, "普通歌曲----------COMMAND_START---play"); long distance = System.currentTimeMillis() - mBaseContext.getGlobalLong("mediaPauseTime"); if (distance > 3600000) { // 同一首歌暂停有效期为1小时 getUnion().getCommandEngine().handleText("唱歌"); return null; } else { getUnion().getMediaInterface().resume(); } } break; case MusicUtil.COMMAND_NEXT: forceNext(); MusicUtil.logMusic(commandType, mBaseContext); return null; case MusicUtil.COMMAND_PRE: MusicUtil.logMusic(commandType, mBaseContext); getUnion().getMediaInterface().playPre(); return null; case MusicUtil.COMMAND_RANDOM: // random not support MusicUtil.logMusic(commandType, mBaseContext); getUnion().getMediaInterface().playNext(); return null; case MusicUtil.COMMAND_CIRCLE: i.setAction(KeyList.PKEY_MUSIC_CIRCLE); getUnion().getMediaInterface().setPlayMode(IMediaInterface.PLAY_MODE_SIGNAL); sendAnswerSession("好的,进入单曲循环"); break; case MusicUtil.COMMAND_BAD: if (getUnion().getBaseContext().getGlobalBoolean(KeyList.GKEY_IS_MUSIC_IN_PLAYING)) { forceNext(); } MusicUtil.logMusic(commandType, mBaseContext); return null; case MusicUtil.COMMAND_GOOD: if (getUnion().getBaseContext().getGlobalBoolean(KeyList.GKEY_IS_MUSIC_IN_PLAYING)) { sendAnswerSession("收藏成功"); } MusicUtil.logMusic(commandType, mBaseContext); return null; default: break; } } MusicUtil.logMusic(commandType, mBaseContext); return null; }