public void addContent(String corder, String dorder, String target) { LogManager.e(corder); SentenceObject s = new SentenceObject(wm.getSegList(corder), corder); s.setOrder(dorder); s.setTarget(target); LogManager.e(s.toString()); mHash.put(corder, s); }
// ****************状态位查询****************** // public int getDuration() { try { if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { duration = mMediaPlayer.getDuration(); } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } return duration; }
public boolean isPlaying() { try { if (mMediaPlayer != null) { isPlaying = mMediaPlayer.isPlaying(); } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } return isPlaying; }
public void dlnaStop() { if (!messageQueue.inThread()) { throw new RuntimeException("stop must run on MediaPlayerService handler Thread"); } try { LogManager.d(TAG, "dlna-----stop"); reset(); mMediaPlayer.reset(); } catch (Exception e) { LogManager.printStackTrace(e); } }
public String isHouseCommand(String text) { Matcher m = pattern.matcher(text); if (m.find()) { text = text.replace(m.group(), ""); } LogManager.e(text); ArrayList<WordObj> mSegList = wm.getSegList(text); int i = 0; if (sentence.isFullOrder(mSegList)) { for (WordObj w : mSegList) { if (!w.getType().equals("其他")) { if (w.getType().equals("模式") && w.getWord().equals("回家")) { text = w.getWord() + w.getType(); i += text.length(); } else { i += w.getWord().length(); } } } if (i > (text.length() * 0.8)) { return text; } } return null; }
public ParseResultList HandText(String text) { ArrayList<SentenceObject> resultList = new ArrayList<SentenceObject>(); ArrayList<WordObj> mSegList = wm.getSegList(text); int resultscore = Integer.MAX_VALUE; if (mSegList.size() == 1) { if (mSegList.get(0).getType().equals("父动作")) { return null; } } for (SentenceObject s : mHash.values()) { // 数值越小,表示越准确 int tempReuslt = wm.comPair(mSegList, s.getTextObjects()) + s.getResultDistance(); // 取得最接近的家电 if (tempReuslt < resultscore) { resultscore = tempReuslt; resultList.clear(); resultList.add(s); } else if (tempReuslt == resultscore) { // 累计得分相同项 resultList.add(s); } } LogManager.e("result score " + resultscore); ParseResultList result = new ParseResultList(resultList, resultscore); isHouseCommand(text); return result; }
@Override public void onServiceConnected(ComponentName name, IBinder service) { LogManager.e("dog service connect sucess"); mControlService = IDogControlService.Stub.asInterface(service); try { mControlService.setCommandChangeListen(mChangeListener); LogManager.e("set listenr " + mChangeListener); } catch (RemoteException e1) { // e1.printStackTrace(); LogManager.printStackTrace(e1); } inited = true; if (mOnGetDevAdd != null) { mOnGetDevAdd.onGetAdd(null); } }
public void release() { if (!messageQueue.inThread()) { throw new RuntimeException("release must run on MediaPlayerService handler Thread"); } try { if (mMediaPlayer != null) { LogManager.d(TAG, "release()"); mMediaPlayer.release(); reset(); } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } }
@Override public void onServiceDisconnected(ComponentName name) { LogManager.e("dog service connect fail"); inited = false; mControlService = null; if (mOnGetDevAdd != null) { mOnGetDevAdd.onDisConnect(); } }
// 取消声音渐变的 public void simplePause() { if (!messageQueue.inThread()) { throw new RuntimeException("simplePause must run on MediaPlayerService handler Thread"); } try { if (mMediaPlayer != null) { if (hasReady) { LogManager.d(TAG, "simplePause()"); mMediaPlayer.setVolume(1, 1); mMediaPlayer.pause(); } else { LogManager.d(TAG, "simplePause() is ignore! mediaPlayer is not ready"); } } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } }
private void forceNext() { MyMusicHandler mediaInterface = (MyMusicHandler) getUnion().getMediaInterface(); if (mediaInterface.getMediaInfoList() == null || mediaInterface.getPlayMode() == IMediaInterface.PLAY_MODE_SIGNAL || mediaInterface.getPlayMode() == IMediaInterface.PLAY_MODE_LOOPSIGNAL || mediaInterface.getMediaInfoList().size() <= 1) { LogManager.i( "CommandMediaControl" + "----->" + "getPlayMode:" + mediaInterface.getPlayMode() + "---->size:" + mediaInterface.getMediaInfoList().size()); LogManager.i("CommandMediaControl" + "----->" + "播放本地歌曲"); getUnion().getCommandEngine().handleText("唱歌"); } else { LogManager.e(MusicUtil.COMMAND_NEXT + "----->" + "播放下一首"); getUnion().getMediaInterface().playNext(); } }
public void onStatusClick(TouchStatus status) { switch (status) { case TOUCH_BEGIN: isNewTouch = true; touchBeginTime = System.currentTimeMillis(); isCalledClickInTouch = false; isCalledLongClickInTouch = false; this.onTouchBegin(); break; case TOUCH_ED: if ((System.currentTimeMillis() - touchBeginTime) > LONG_CLICK_TIME && !isCalledClickInTouch) { isCalledClickInTouch = true; LogManager.d(TAG, "onClickInTouch..."); onClickInTouch(); } else if ((System.currentTimeMillis() - touchBeginTime) > LONG_LONG_CLICK_TIME && !isCalledLongClickInTouch) { isCalledLongClickInTouch = true; LogManager.d(TAG, "onLongClickInTouch..."); onLongClickInTouch(); } break; case TOUCH_END: // 开始按键与结束按键值不一样 this.onTouchEnd(); if (System.currentTimeMillis() - touchBeginTime < LONG_CLICK_TIME) { onShortClick(); } else if ((System.currentTimeMillis() - touchBeginTime) > LONG_CLICK_TIME && (System.currentTimeMillis() - touchBeginTime) < LONG_LONG_CLICK_TIME) { LogManager.d(TAG, "onLongClick..."); onLongClick(); } else { LogManager.d(TAG, "onLongLongClick..."); onLongLongClick(); } break; default: break; } }
private void process(String url) { url = url.replace("\n", ""); LogManager.e("语音请求连接:" + url); InputStreamReader input = NetWorkUtil.getNetworkInputStreamReader(url); if (input != null) { try { mInfo = new CommandInfo(); mXmlPullParser.setInput(input); int evtType = mXmlPullParser.getEventType(); while (evtType != XmlPullParser.END_DOCUMENT) { switch (evtType) { case XmlPullParser.START_TAG: handleStartTag(mXmlPullParser.getName()); break; case XmlPullParser.TEXT: handText(mXmlPullParser.getText()); break; case XmlPullParser.END_TAG: // handleEndTag(mXmlPullParser.getName()); break; } evtType = mXmlPullParser.next(); } } catch (Exception e) { mInfo = null; LogManager.e("XmlParserNew 解析xml异常:" + e.toString()); } finally { try { input.close(); } catch (IOException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } } } else { mInfo = null; LogManager.e("XmlParserNew", "获取信息失败,返回对象:" + mInfo); } }
public void pause() { if (!messageQueue.inThread()) { throw new RuntimeException("pause must run on MediaPlayerService handler Thread"); } try { if (mMediaPlayer != null) { if (hasReady) { LogManager.i(TAG, "onpause()"); // 声音渐出 MediaPlayerUtil.autoIncreaseVloume(context, mMediaPlayer, false); mMediaPlayer.pause(); } else { LogManager.i(TAG, "onpause() is ignore! mediaPlayer is not ready"); } } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } }
public List<CommandInfo> getCommands() { if (inited) { try { return mControlService.getCommand(); } catch (RemoteException e) { LogManager.printStackTrace(e); init(); } } else { init(); } return null; }
public boolean sendCommand(String info) { if (inited) { try { return mControlService.sendCommand(info); } catch (RemoteException e) { LogManager.printStackTrace(e); init(); } } else { init(); } return false; }
public void seekTo(int pos) { if (!messageQueue.inThread()) { throw new RuntimeException("seekTo must run on MediaPlayerService handler Thread"); } try { if (mMediaPlayer != null) { if (hasReady) { int d = getDuration(); if (pos <= d) { LogManager.d(TAG, "seekTo (" + pos + ")"); } else { LogManager.d(TAG, "seekTo error pos > Duration :" + pos + "/" + d + ")"); } mMediaPlayer.seekTo(pos); } else { LogManager.d(TAG, "seekTo(" + pos + ") is ignore! mediaPlayer is not ready"); } } } catch (IllegalStateException e) { LogManager.printStackTrace(e); } catch (Exception e) { LogManager.printStackTrace(e); } }
public void buildDogCommand() { if (commands != null) { for (CommandInfo info : commands) { HouseCommandParse.getInstanse().removeContent(info.getCommandName()); } } commands = getCommands(); if (commands != null) { for (CommandInfo info : commands) { LogManager.e("dog's command :" + info.getCommandName()); HouseCommandParse.getInstanse() .addContent(info.getCommandName(), info.getCommandContent(), DogClient.TYPE); } } }
@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; }
@Override public void onCreate() { super.onCreate(); LogManager.d("view launch"); this.startService(new Intent(this, UpgradeService.class)); }
// ****************操作命令****************** // public void setMediaInfoList(String path) { if (!messageQueue.inThread()) { throw new RuntimeException("setMediaInfoList must run on MediaPlayerService handler Thread"); } try { LogManager.d(TAG, "setMediaInfoList", "set Path:" + path); // 复用播放器 hasReady = false; mMediaPlayer.reset(); if (mBaseContext.getPrefBoolean(KeyList.PKEY_CUREENT_MUSIC_IS_DLAN, false)) { LogManager.d(TAG, "setMediaInfoList dlan音乐"); mMediaPlayer.setDataSource(path); mMediaPlayer.prepareAsync(); mMediaPlayer.setOnPreparedListener( new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { // TODO Auto-generated method stub if (preparedListener != null) { preparedListener.onPrepared(mp); } } }); // 统计第三方协议播放 mBaseContext.sendUmengEvent( UmengUtil.THE_THIRD_PROTOCOL_PLAY, UmengUtil.THE_THIRD_PROTOCOL_PLAY_CONTENT); } else if (path.startsWith("http")) { LogManager.d(TAG, "setMediaInfoList 代理音乐"); String localMusicCache = HttpGetProxyUtils.getLocalOrCacheMusicsPath(path); if (localMusicCache != null) { mMediaPlayer.setDataSource(localMusicCache); } else { String mypath = HttpProxy.proxyHttpUrl + path; mMediaPlayer.setDataSource(mypath); } } else { LogManager.d(TAG, "setMediaInfoList 普通音乐"); if (path.startsWith(MusicInfoManager.MUSIC_SAVE_POSE)) { int currentLocalMusicId = Integer.parseInt(path.replace(MusicInfoManager.MUSIC_SAVE_POSE, "")); // 记录当前歌曲ID mBaseContext.setPrefInteger(KeyList.CURRENT_LOCAL_MUSIC_ID, currentLocalMusicId); } mMediaPlayer.setDataSource(path); } if (!mBaseContext.getPrefBoolean(KeyList.PKEY_CUREENT_MUSIC_IS_DLAN, false)) { mMediaPlayer.prepare(); } // 阻塞播放器 hasReady = true; } catch (IOException e) { LogManager.printStackTrace(e, "MediaPlayerService", "setMediaInfoList"); LogManager.e("path:" + path + " is invaild!"); // 无法复用播放器 hasReady = false; try { if (onErrorListener != null) { onErrorListener.onError(mMediaPlayer, MEDIA_ERROR_TRY, currentPosition); } } catch (IllegalStateException e1) { LogManager.printStackTrace(e1); } catch (Exception e1) { LogManager.printStackTrace(e1); } } catch (Exception e) { LogManager.printStackTrace(e, "MediaPlayerService", "setMediaInfoList"); } }