Exemple #1
0
        @Override
        public boolean onInfo(MediaPlayer player, int whatInfo, int extra) {
          switch (whatInfo) {
            case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
              break;

            case MediaPlayer.MEDIA_INFO_BUFFERING_START:
              if (player.isPlaying()) {
                Logger.LOGD(TAG, "resume to pause MEDIA_INFO_BUFFERING_START");
                needResume = true;
                if (!mLoading.isShowing()) mLoading.show();
              }
              break;
            case MediaPlayer.MEDIA_INFO_BUFFERING_END:
              if (needResume) {
                player.start();
                needResume = false;
                Logger.LOGD(TAG, "resume to play!!!! MEDIA_INFO_BUFFERING_END");
                mLoading.cancel();
              }
              break;
            default:
              Logger.LOGD(TAG, "what=" + whatInfo + ",extra=" + extra);
              break;
          }
          return false;
        }
Exemple #2
0
  public void myPlay(String url, String src) {
    if (url == null || url.length() == 0) {
      Toast.makeText(mContext, "无播放地址", Toast.LENGTH_SHORT).show();
      return;
    }

    if (!mLoading.isShowing()) mLoading.show();
    mPlayPath = url;
    Logger.LOGD(TAG, "begin to play:" + mPlayPath + ", " + src);

    if (mPlayer == null) {
      Logger.LOGD(TAG, "mPlayer is null!!");
      initPlayer();
    }
    try {
      Logger.LOGD(TAG, "-=-=-=-=-=-= -=-=-reset-=--= -=-==-");
      mPlayer.reset();
      // mPlayer.stop();

      Logger.LOGD("mUaMap.size= " + mUaMap.size() + ", value: " + mUaMap.get(src));
      Map<String, String> headers = new HashMap<String, String>();
      if (mUaMap.get(src) != null) {
        Logger.LOGD("=== had  headers ====");

        String headinfo = mUaMap.get(src);
        String[] grp = headinfo.split("\\$\\$");
        if (grp != null) {
          for (String items : grp) {
            String[] item = items.split("\\:");
            if (item != null && item.length == 2) {
              Logger.LOGD("Add header: " + item[0] + "=" + item[1]);
              headers.put(item[0], item[1]);
            }
          }
        }
      }

      if (headers.size() > 0) {
        Logger.LOGD("use header");
        mPlayer.setDataSource(Player.this, Uri.parse(url), headers);
      } else {
        Logger.LOGD("use no-header");
        mPlayer.setDataSource(url);
      }
      mPlayer.prepareAsync();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      Logger.LOGD(TAG, e.toString());
    } catch (IllegalStateException e) {
      e.printStackTrace();
      Logger.LOGD(TAG, e.toString());
    } catch (IOException e) {
      e.printStackTrace();
      Logger.LOGD(TAG, e.toString());
    }
  }
Exemple #3
0
  private boolean queryPlayList(int pgIdx /* , int pgSize */) {
    if (mRunMode == Configer.RunMode.MODE_LOCAL) {
      if (!mBfirstData) return false;

      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  // TODO Auto-generated method stub
                  mData.clear();
                  mCurPg = 0;

                  File f = new File(mCurLocalPath);
                  File[] l = f.listFiles(new FileNameSelector());
                  if (l == null) {
                    // Toast.makeText(this, mCurLocalPath+ " 目录下没有内容", Toast.LENGTH_SHORT).show();
                    onExitProc();
                    return;
                  }

                  if (!mCurLocalPath.endsWith("/")) mCurLocalPath += "/";

                  for (File file : l) {
                    // Logger.LOGD("", mCurLocalPath+file);
                    if (file.isDirectory()) continue;

                    String name = file.getName();
                    int pos = name.lastIndexOf(".");
                    if (pos < 0 || (pos >= (name.length() - 1))) continue;

                    PlayItemEntity pie = new PlayItemEntity();
                    pie.setName(name);

                    List<UrlInfoEntry> ulist = new ArrayList<UrlInfoEntry>();
                    UrlInfoEntry u = new UrlInfoEntry();
                    u.setUrl(mCurLocalPath + name);
                    ulist.add(u);
                    pie.setUrlList(ulist);
                    // pie.setDownUrl(mCurLocalPath+name);
                    mData.add(pie);
                  }
                  mBfirstData = false;

                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          // TODO Auto-generated method stub
                          // mHListView.initDatas(mAdapter);
                          // initHScrollView(-1);
                          mHListView.setClickPos(0);
                          myPlay(mHListView.getClickPos());
                        }
                      });
                }
              })
          .start();

      return true;
    } else {
      if (mBReqing) return true;

      // 如果已经请求过了,则不再请求。
      if (mHadDataGetArr.indexOfKey(pgIdx) >= 0) return true;

      mBReqing = true;
      if (!mLoading.isShowing()) mLoading.show();

      HashMap<String, Object> bodyRequest = new HashMap<String, Object>();
      bodyRequest.put("id", mCurCateId);
      bodyRequest.put("pageindex", pgIdx);
      bodyRequest.put("pagesize", PAGE_SIZE);
      bodyRequest.put("type", mReqType);
      HttpManger http = new HttpManger(this, bHandler, this);
      return http.httpRequest(
          Configer.REQ_VIDEO_PLAYLIST, bodyRequest, false, ResponePList.class, false, false, true);
    }
  }