// ****************状态位查询****************** //
 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 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);
    }
  }
 // 取消声音渐变的
 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);
   }
 }
Esempio n. 5
0
 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 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 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 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);
   }
 }
Esempio n. 10
0
  public boolean sendCommand(String info) {

    if (inited) {
      try {
        return mControlService.sendCommand(info);

      } catch (RemoteException e) {
        LogManager.printStackTrace(e);
        init();
      }
    } else {
      init();
    }
    return false;
  }
Esempio n. 11
0
        @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 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");
    }
  }