Exemplo n.º 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;
        }
Exemplo n.º 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());
    }
  }
Exemplo n.º 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);
    }
  }
Exemplo n.º 4
0
  // --------------------------------------------------
  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();
          }
        });
  }