コード例 #1
0
ファイル: Player.java プロジェクト: treejames/Children
        @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;
        }
コード例 #2
0
ファイル: Player.java プロジェクト: treejames/Children
  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());
    }
  }
コード例 #3
0
ファイル: Player.java プロジェクト: treejames/Children
        @Override
        public void onPrepared(MediaPlayer mPlayer) {
          Logger.LOGD(TAG, "onPrepared called");

          if (mRunMode != Configer.RunMode.MODE_DIRECT) {
            int pos = mHListView.getClickPos() == -1 ? 0 : mHListView.getClickPos();
            mMvTitle.setText(mData.get(pos).getName());
          }
          mDuration = mPlayer.getDuration();
          if (mDuration == 0) mDuration = 1200;
          mTvDur.setText(MediaUtil.formatTime(mDuration));
          mBtnPlay.setBackgroundResource(R.drawable.mv_btn_pause);
          mPlayer.start();

          mLoading.cancel();
        }
コード例 #4
0
ファイル: Player.java プロジェクト: treejames/Children
  @Override
  protected void onPostHandle(
      int requestType,
      Object data,
      boolean status,
      int paramInt2,
      Object paramObject2,
      Object paramObject3) {
    // TODO Auto-generated method stub
    super.onPostHandle(requestType, data, status, paramInt2, paramObject2, paramObject3);
    if (data == null) {
      mLoading.cancel();
      mBReqing = false;
      return;
    }

    ResHeadAndBody rslt = (ResHeadAndBody) data;

    if (mUaMap.size() == 0) {
      List<ExtraEntry> extra = rslt.getHeader().getExtra();
      if (extra != null && extra.size() > 0) {
        for (ExtraEntry en : extra) {
          Logger.LOGD("++extra: " + en.getKey() + ", " + en.getValue());
          mUaMap.put(en.getKey(), en.getValue());
        }
      }
    }

    // gson 将请求的数据,转为了ResponePList数据类型
    ResponePList plist = (ResponePList) rslt.getBody();
    List<PlayItemEntity> pList = plist.getpList();
    // 如果数据空,则页面相关信息不会被变更
    if (pList == null || pList.isEmpty()) {
      mLoading.cancel();
      mBReqing = false;
      return;
    }

    ResponsePager pg = (ResponsePager) rslt.getPage();
    if (pg != null) {
      if (mTotalPage == 0) {
        mTotalPage = pg.getPageCount();

        // 更新 集数分组
        mSetsAdapter.setSetCnt(pg.getCount()); // 总集数
        mSetsAdapter.notifyDataSetChanged();
        mSetsHList.setVisibility(View.VISIBLE);
      }

      mCurPg = pg.getPageIndex();
      if (mHadDataGetArr.indexOfKey(mCurPg) < 0) {
        mHadDataGetArr.put(mCurPg, 1); // 入库,即存在

        ArrayList<Integer> keys = new ArrayList<Integer>();
        for (int i = 0; i < mHadDataGetArr.size(); i++) {
          keys.add(mHadDataGetArr.keyAt(i));
        }

        // 计算 insertIdx,根据带插入的列表的集码对应的位置,进行计算在mData中的插入位置
        Collections.sort(keys);
        int curIdx = keys.indexOf(mCurPg);
        int insertIdx = PAGE_SIZE * curIdx; // [insertIdx, --)

        // 数据入库
        mData.addAll(insertIdx, plist.getpList()); // 在mData中insertIdx之前插入 plist.getpList()

        if (!mBfirstData) mHListView.setSelection(insertIdx);
      }
    }

    if (mBfirstData) {
      mHListView.setClickPos(0);
      mBfirstData = false;
      myPlay(mHListView.getClickPos());
    }

    /////////// 放在底部  每次请求要保存状态,保存状态  /////////////
    saveState(plist.getpList());

    mLoading.cancel();
    mBReqing = false;
  }
コード例 #5
0
ファイル: Player.java プロジェクト: treejames/Children
  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);
    }
  }
コード例 #6
0
ファイル: Player.java プロジェクト: treejames/Children
  // --------------------------------------------------
  void initMyView() {
    // 退出事件
    findViewById(R.id.go_back)
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                onExitProc();
              }
            });

    mLoading = CustomProgressDialog.createDialog(this);
    mLoading.setMessage(getResources().getString(R.string.default_loading_txt));
    mLoading.show();

    // 集组显示
    mSetsHList = (HorizontalListView) findViewById(R.id.id_sethlist);
    mSetsAdapter = new SetsHListAdapter(this);
    mSetsHList.setAdapter(mSetsAdapter);

    mSetsHList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            setCurSetGrpIdx(arg2);
          }
        });

    mHListView = (HorizontalListView) findViewById(R.id.id_horizontalScrollView);
    mAdapter = new HorizontalScrollViewAdapter(this, mData, getIntent().getStringExtra("pic"));
    mHListView.setAdapter(mAdapter);

    mHListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            Logger.LOGD("", "=================== onitemclick :" + arg2);
            ((HorizontalScrollViewAdapter) arg0.getAdapter()).notifyDataSetChanged();
            mPlayingIdx = 0;
            myPlay(arg2);
          }
        });

    mHListView.setOnScrollListener(
        new OnScrollListener() {
          @Override
          public void onScrollStateChanged(View view, int scrollState) {
            // TODO Auto-generated method stub
          }

          // 这里两个工作:1. 数据预请求;2.集组焦点的切换。
          @Override
          public void onScroll(
              View view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // TODO Auto-generated method stub
            Logger.LOGD(
                "",
                "onScroll: " + firstVisibleItem + "," + visibleItemCount + "," + totalItemCount);

            // 对于请求的数据要先判断是否已经请求过了。
            if (firstVisibleItem + visibleItemCount + 12 >= totalItemCount // 注意next函数,尽可能一致
                && mData.size() > visibleItemCount
                && mData.size() >= PAGE_SIZE) { // 数据至少要满屏
              // 另外注意,这里的mCurPg,只有当请求成功,它的值才会变更。
              queryPlayList(mCurPg + 1);
              return;
            }

            // 1. totalItemCount >0
            // 2. firstVisibleItem: idx for the first item of data
            // 3. visibleItemCount
            if (totalItemCount > 0) {
              float end = firstVisibleItem + visibleItemCount;
              int setgrpidx = (int) (Math.ceil(end / PAGE_SIZE) - 1);
              if (setgrpidx >= 0 && setgrpidx != mSetsHList.getSelectPosition()) {
                Logger.LOGD("", "############ Alter setgroup :" + setgrpidx);
                mCurSetsGrpIdx = setgrpidx;
                mSetsHList.setSelection(setgrpidx);
              }
            }
          }
        });

    initSurfaceView();

    mImgPauseFlag = (ImageView) findViewById(R.id.img_pause);

    mBtnPlay = (Button) findViewById(R.id.btn_play);
    mBtnPlay.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (isPlaying()) {
              Logger.LOGD("", "btn: isplaying!!, begin to pause");
              do_pause();
              // mBtnPlay.setBackgroundResource(R.drawable.mv_btn_play);
            } else if (mbPause) {
              Logger.LOGD("", "btn: ispaused,begin to resmue!!");
              // mBtnPlay.setBackgroundResource(R.drawable.mv_btn_pause);
              do_resume();
            }

            ctrlShowMgr();
          }
        });
    mHeaderContainer = (RelativeLayout) findViewById(R.id.header_container);
    mCtrlContainer = (RelativeLayout) findViewById(R.id.ctrlbar_container);
    mMvTitle = (TextView) findViewById(R.id.mv_title);
    mMvTitle.setText("                       ");

    mLayerTop = (RelativeLayout) findViewById(R.id.layer_top);

    mTvCurtm = (TextView) findViewById(R.id.curtime);
    mTvDur = (TextView) findViewById(R.id.dur);

    sBar = (SeekBar) findViewById(R.id.seekb);
    sBar.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            Logger.LOGD("", "seekbar.......onStartTrackingTouch");
            // ctrlShowMgr();
          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            int dest = seekBar.getProgress();
            int sMax = sBar.getMax();
            mPlayer.seekTo(mDuration * dest / sMax);

            Logger.LOGD("", "seekbar.......onStopTrackingTouch");
            // ctrlShowMgr();
          }
        });
  }