示例#1
0
        @Override
        public boolean onError(MediaPlayer player, int whatError, int extra) {
          Logger.LOGD(TAG, "onError called: " + "(" + whatError + "," + extra + ")");
          if (mRunMode == Configer.RunMode.MODE_DIRECT && whatError != -38) {
            onExitProc();
            return true;
          }

          switch (whatError) {
            case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
              // initPlayer();
              Logger.LOGD("Play Error:::", "MEDIA_ERROR_SERVER_DIED");
              onExitProc();
              break;
            default:
              PlayItemEntity pie = mData.get(mCurClickPos);
              if (pie.getUrlList() != null && ((mPlayingIdx + 1) < pie.getUrlList().size())) {
                Logger.LOGD("begin to alter source");
                mPlayingIdx++;
                myPlay(mCurClickPos);
              } else {
                next(true);
              }
              break;
          }
          return true;
        }
示例#2
0
  private void next(boolean bplay) {
    Logger.LOGD("fun ...... next...");
    mPlayingIdx = 0;
    if (mRunMode == Configer.RunMode.MODE_NETWORK) {
      if (mAdapter.getCount() - mHListView.getClickPos() < 12) { // 这儿与onscroll事件是有些不一样的哦
        Logger.LOGD("", "!!!!!! begin to load pg: " + (mCurPg + 1));
        queryPlayList(mCurPg + 1);
      }
    }

    if (bplay) {
      int pos = mHListView.getClickPos() + 1;
      if (mAdapter == null || mData.size() == 0) {
        onExitProc();
        return;
      }
      if (pos >= mData.size()) {
        pos = 0;
      }
      mHListView.setClickPos(pos);

      int setgrppos = (int) (Math.ceil((pos * 1f) / PAGE_SIZE) - 1);
      if (setgrppos >= 0) {
        mCurSetsGrpIdx = setgrppos;
        mSetsHList.setSelection(mCurSetsGrpIdx);
      }

      // 仅当隐藏时,其才将当前播放的滚动到开头,避免用户在选择影片时,其突然跳到正在播放的条目
      if (/*mFill1*/ mLayerTop.getVisibility() == View.INVISIBLE) mHListView.setSelection(pos);

      myPlay(pos);
    }
  }
示例#3
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;
        }
示例#4
0
 private void do_resume() {
   Logger.LOGD("", "Log");
   if (mPlayer != null && mbPause) {
     Logger.LOGD("", "do_resume");
     mBtnPlay.setBackgroundResource(R.drawable.mv_btn_pause);
     mPlayer.start();
     mbPause = false;
     mImgPauseFlag.setVisibility(View.GONE);
   }
 }
示例#5
0
  private void registerMyRcv() {
    Logger.LOGD(TAG, "Service registerMyRcv");

    if (batteryReceiver == null) {
      batteryReceiver = new BatteryRcvBindView((BatteryImgView) findViewById(R.id.battery));
      registerReceiver(batteryReceiver, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
    }

    if (myReceiver == null) {
      myReceiver = new MyReceiver();
      IntentFilter filter = new IntentFilter();
      filter.addAction(Configer.Action.MV_CTL_PLAY);
      filter.addAction(Configer.Action.MV_CTL_PAUSE);
      filter.addAction(Configer.Action.MV_CTL_NEXT);
      filter.addAction(Configer.Action.MV_CTL_PREV);
      filter.addAction(Configer.Action.MV_CTL_PLAY_PAUSE);

      // exit
      filter.addAction(Configer.Action.ACT_EXIT);

      // 锁(关)屏状态
      filter.addAction(Intent.ACTION_SCREEN_ON);
      filter.addAction(Intent.ACTION_SCREEN_OFF);

      registerReceiver(myReceiver, filter);
    }
  }
示例#6
0
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Logger.LOGD(TAG, "-=-=-=-onResume-=-=-=-=");

    registerMyRcv();
  }
示例#7
0
  @Override
  protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    Logger.LOGD("", "onstop");

    onExitProc();
  }
示例#8
0
 @Override
 public void onCompletion(MediaPlayer player) {
   Logger.LOGD("Play Over:::", "onComletion called");
   if (mRunMode != Configer.RunMode.MODE_DIRECT) {
     next(true);
   } else {
     onExitProc();
   }
 }
示例#9
0
  private void do_pause() {
    if (mPlayer != null && mPlayer.isPlaying()) { // isPlaying()函数怪怪的
      Logger.LOGD("", "do_pause");
      mBtnPlay.setBackgroundResource(R.drawable.mv_btn_play);
      mPlayer.pause();
      mbPause = true;

      mImgPauseFlag.setVisibility(View.VISIBLE);
    }
  }
示例#10
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    int action = ev.getAction();

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        if (!mBCtrlbarShow) {
          showCtrlbar();
          return true;
        }

        if (inRangeOfView(mHListView, ev)
            || inRangeOfView(mHeaderContainer, ev)
            || inRangeOfView(mCtrlContainer, ev)
            || inRangeOfView(mSetsHList, ev)) {

          Logger.LOGD("", "down on mHListView");
          if (System.currentTimeMillis() - mLasttm > 1500) {
            mLasttm = System.currentTimeMillis();
            ctrlShowMgr();
          }
        } else {
          Logger.LOGD("", "down on Fill area");
          hideCtrlbar();
          return true;
        }
        break;

      case MotionEvent.ACTION_UP:
        break;
      case MotionEvent.ACTION_MOVE:
        break;
    }

    return super.dispatchTouchEvent(ev);
  }
示例#11
0
        @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();
        }
示例#12
0
  private void initPlayer() {
    Logger.LOGD(TAG, "begint to new InitPlayer");
    if (mPlayer != null) {
      mPlayer.release();
      mSurfaceView.setVisibility(View.INVISIBLE);
    }

    mPlayer = new MediaPlayer();
    mSurfaceView.setVisibility(View.VISIBLE);
    //		if (mHolder != null)
    //			mPlayer.setDisplay(mHolder);
    mPlayer.setOnPreparedListener(mPrepareListener);
    mPlayer.setOnCompletionListener(mCompleteListener);
    mPlayer.setOnErrorListener(mErrorListener);
    mPlayer.setOnInfoListener(mInfoListener);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mPlayer.reset();

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
示例#13
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());
    }
  }
示例#14
0
  @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;
  }
示例#15
0
 void ctrlShowMgr() {
   Logger.LOGD("", "---ctrlShowMgr");
   mHandler.removeCallbacks(ctrBarHidding); // 停止Timer
   mHandler.postDelayed(ctrBarHidding, 4000); // 开始Timer
 }