Beispiel #1
0
 @Override
 public void handleMessage(Message msg) {
   // TODO Auto-generated method stub
   super.handleMessage(msg);
   // Log.i("tvinfo", msg.what + "-" + msg.obj);
   if (msg.what == 1) {
     progress.setVisibility(View.VISIBLE);
     title.setText("开始播放 ...");
   }
   if (msg.what == 2) {
     title.setText("开始加载 ...");
   }
   if (msg.what == 3) {
     title.setText("开始播放 ...");
     play(prg);
   }
   if (msg.what == 4) {
     title.setText("加载失败 ...");
   }
   if (msg.what == 9) {
     show("获取", "正在获取播放列表,请稍后...");
   }
   if (msg.what == -100) {
     playmenu.setVisibility(View.GONE);
   }
   if (msg.what == 66) {
     if (player != null && player.isPlaying() && !isseek) {
       currtime.setText(Utils.longToString(player.getCurrentPosition()));
       playSeek.setProgress(player.getCurrentPosition() / 1000);
     }
   }
 }
Beispiel #2
0
 @Override
 public void run() {
   if (player != null) {
     seekBar.setProgress(player.getCurrentPosition());
     playerCurrentTime.setText(convertTime(player.getCurrentPosition()));
     seekBarHandler.postDelayed(this, 100);
   }
 }
 /**
  * Called when MediaPlayer has completed a seek
  *
  * @see OnSeekCompleteListener
  */
 @Override
 public void onSeekComplete(MediaPlayer mp) {
   LogHelper.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
   mCurrentPosition = mp.getCurrentPosition();
   if (mState == PlaybackStateCompat.STATE_BUFFERING) {
     mMediaPlayer.start();
     mState = PlaybackStateCompat.STATE_PLAYING;
   }
   if (mCallback != null) {
     mCallback.onPlaybackStatusChanged(mState);
   }
 }
        @Override
        public void handleMessage(Message msg) {
          if (mediaPlayer.isPlaying()) {

            int progress = (mediaPlayer.getCurrentPosition() * 100) / mediaPlayer.getDuration();
            Integer timeValues[] = new Integer[3];
            timeValues[0] = mediaPlayer.getCurrentPosition();
            timeValues[1] = mediaPlayer.getDuration();
            timeValues[2] = progress;

            Constants.PROGRESSBAR_HANDLER.sendMessage(
                Constants.PROGRESSBAR_HANDLER.obtainMessage(0, timeValues));
          }
        }
Beispiel #5
0
 public int getCurrentPosition() {
   int j = 0;
   if (e != null) {
     j = e.getCurrentPosition();
   }
   return j;
 }
 /**
  * Reconfigures MediaPlayer according to audio focus settings and starts/restarts it. This method
  * starts/restarts the MediaPlayer respecting the current audio focus state. So if we have focus,
  * it will play normally; if we don't have focus, it will either leave the MediaPlayer paused or
  * set it to a low volume, depending on what is allowed by the current focus settings. This method
  * assumes mPlayer != null, so if you are calling it, you have to do so from a context where you
  * are sure this is the case.
  */
 private void configMediaPlayerState() {
   LogHelper.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
   if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
     // If we don't have audio focus and can't duck, we have to pause,
     if (mState == PlaybackStateCompat.STATE_PLAYING) {
       pause();
     }
   } else { // we have audio focus:
     if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
       mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
     } else {
       if (mMediaPlayer != null) {
         mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
       } // else do something for remote client.
     }
     // If we were playing when we lost focus, we need to resume playing.
     if (mPlayOnFocusGain) {
       if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
         LogHelper.d(
             TAG, "configMediaPlayerState startMediaPlayer. seeking to ", mCurrentPosition);
         if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
           mMediaPlayer.start();
           mState = PlaybackStateCompat.STATE_PLAYING;
         } else {
           mMediaPlayer.seekTo(mCurrentPosition);
           mState = PlaybackStateCompat.STATE_BUFFERING;
         }
       }
       mPlayOnFocusGain = false;
     }
   }
   if (mCallback != null) {
     mCallback.onPlaybackStatusChanged(mState);
   }
 }
Beispiel #7
0
 @Override
 public int getCurrentPosition() {
   if (isInPlaybackState()) {
     return mMediaPlayer.getCurrentPosition();
   }
   return 0;
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   measureVideo(mVideoWidth, mVideoHeight, widthMeasureSpec, heightMeasureSpec);
   if (mSurfaceHolder != null && mMediaPlayer != null && mMediaPlayer.getCurrentPosition() > 0) {
     mSurfaceHolder.setFixedSize(getMeasuredWidth(), getMeasuredHeight());
   }
 }
Beispiel #9
0
  public void startPlayback(float percentage) {
    if (state() == PLAYING_PAUSED_STATE) {
      mSampleStart = System.currentTimeMillis() - mPlayer.getCurrentPosition();
      mPlayer.seekTo((int) (percentage * mPlayer.getDuration()));
      mPlayer.start();
      setState(PLAYING_STATE);
    } else {
      stop();

      mPlayer = new MediaPlayer();
      try {
        mPlayer.setDataSource(mSampleFile.getAbsolutePath());
        mPlayer.setOnCompletionListener(this);
        mPlayer.setOnErrorListener(this);
        mPlayer.prepare();
        mPlayer.seekTo((int) (percentage * mPlayer.getDuration()));
        mPlayer.start();
      } catch (IllegalArgumentException e) {
        setError(INTERNAL_ERROR);
        mPlayer = null;
        return;
      } catch (IOException e) {
        setError(STORAGE_ACCESS_ERROR);
        mPlayer = null;
        return;
      }

      mSampleStart = System.currentTimeMillis();
      setState(PLAYING_STATE);
    }
  }
 @Override
 public void play() {
   if (mMediaPlayer.getCurrentPosition() >= mMediaPlayer.getDuration()) {
     mMediaPlayer.seekTo(0);
   }
   mMediaPlayer.start();
 }
 @Override
 public void onCompletion(MediaPlayer mp) {
   if (play.getCurrentPosition() > 0) {
     mp.reset();
     playNext();
   }
 }
Beispiel #12
0
 protected long getCurrentPosition() {
   if (isPlaying) {
     return (mPlayer.getCurrentPosition());
   } else {
     return (-1);
   }
 }
 private void updateSoundSystemInfo() {
   playbackInfo.setStatus(
       player != null && player.isPlaying() ? PlaybackStatus.PLAYING : PlaybackStatus.PAUSED);
   playbackInfo.setTime(player != null ? player.getCurrentPosition() : 0);
   updateSoundSystemUI();
   mActivity.getSmartHouseController().updatePlaybackInfo(copyPlaybackInfo());
 }
 private void sendSeekPos() {
   if (mMediaPlayer != null) {
     intent = new Intent(UPDATE_CUR_POS);
     intent.putExtra("curPos", mMediaPlayer.getCurrentPosition());
     sendBroadcast(intent);
   }
 }
  private int getPositionSeconds() {
    if (mMediaPlayer != null) {
      return mMediaPlayer.getCurrentPosition() / 1000;
    }

    return 0;
  }
  private void prevTrack() {
    try {
      if (player != null) {
        int time = player.getCurrentPosition();
        if (time >= 3000) {
          player.seekTo(0);
          return;
        }
      }

      currentIndex--;
      if (currentIndex < 0) {
        currentIndex = trackIds.length - 1;
      }

      prepareToPlay(trackIds[currentIndex]);

    } finally {
      postProcesses.add(
          new Runnable() {
            @Override
            public void run() {
              playTrack();
              eventBus.post(new TrackChangedEvent(currentIndex));
            }
          });
    }
  }
  private void Rewind(int milisecond) {
    int position = mediaPlayer.getCurrentPosition();
    position -= milisecond;

    if (position < 1) position = 0;

    mediaPlayer.seekTo(position);
  }
 public void playCoo() {
   if (!coo.isPlaying()) {
     if (coo.getCurrentPosition() != 1) {
       coo.seekTo(1);
     }
     coo.start();
   }
 }
  @Override
  public int getCurrentPosition() {

    if (mMediaPlayer != null) {
      return mMediaPlayer.getCurrentPosition();
    }
    return 0;
  }
 @Override
 public void onCompletion(MediaPlayer mp) {
   // check if playback has reached the end of a track
   if (player.getCurrentPosition() > 0) {
     mp.reset();
     playNext();
   }
 }
Beispiel #21
0
 public int currentProgress() {
   if (mediaMode == MediaMode.UnInitialized) {
     int duration = currentDuration();
     if (duration == 0) return 0;
     return currentPostion() * 100 / duration;
   }
   return mediaPlayer.getCurrentPosition() * 100 / mediaPlayer.getDuration();
 }
Beispiel #22
0
 public String getLocationString() {
   Location useLocation = getLocation();
   if (isPlaying()) {
     return getTimeString(mediaPlayer.getCurrentPosition());
   }
   if (currentMeta() != null) return getTimeString(currentMeta().getCurrentPos());
   return "";
 }
Beispiel #23
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (!FloatingService.bLock) {
      noticeShowControllerView(mMediaPlayer.getCurrentPosition(), mMediaPlayer.getDuration(), true);
    }

    return super.onTouchEvent(event);
  }
Beispiel #24
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putInt(videoIdxTag, videoIdx);
   if (mMediaPlayer != null) {
     outState.putInt("curPos", mMediaPlayer.getCurrentPosition());
   }
 }
 /** @return the current track position */
 @Override
 public int getPosition() {
   if (mMediaPlayer != null && mPreparedQuery != null) {
     return mMediaPlayer.getCurrentPosition();
   } else {
     return 0;
   }
 }
  public void stopBGM() {
    try {
      currentPosition = mediaPlayer.getCurrentPosition();
      mediaPlayer.pause();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #27
0
 public void setCurrentPaused(int position) {
   boolean wasPlaying = mediaPlayer.isPlaying();
   if (wasPlaying) {
     currentMeta().setCurrentPos(mediaPlayer.getCurrentPosition());
     mediaPlayer.stop();
   }
   mediaMode = MediaMode.Paused;
   currentPodcastInPlayer = position;
 }
Beispiel #28
0
 // Called when user hits next button. Migth be playing or not playing at the time.
 public void next() {
   boolean isPlaying = mediaPlayer.isPlaying();
   if (isPlaying) {
     currentMeta().setCurrentPos(mediaPlayer.getCurrentPosition());
     currentMeta().save();
     mediaPlayer.stop();
   }
   next(isPlaying);
 }
  public int getTime() {
    int time = 0;

    if (mp != null) {
      time = mp.getCurrentPosition();
    }

    return time;
  }
Beispiel #30
0
 /** 记录退出后播放位置 */
 private void rePlayPosition() {
   // TODO 待解决
   if (mPlayer != null) {
     if (playType == PLAY_TYPE_LOD || playType == PLAY_TYPE_ONDEMAND) {
       MPConPlayUtils.updateLastTime(
           getParentName(), getChildName(), currentPosition, mPlayer.getCurrentPosition());
     }
   }
 }