本文整理匯總了Java中android.media.MediaPlayer.getCurrentPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.getCurrentPosition方法的具體用法?Java MediaPlayer.getCurrentPosition怎麽用?Java MediaPlayer.getCurrentPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.getCurrentPosition方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resume
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* resume playing
*
* @return
*/
public synchronized UDAudio resume() {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
try {
if (player.getCurrentPosition() > 0) {
player.start();
} else {
play(mUriOrName, mLoopTimes);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例2: onSeekComplete
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onSeekComplete(MediaPlayer mp) {
Logger.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
mCurrentPosition = mp.getCurrentPosition();
if (mState == PlaybackStateCompat.STATE_BUFFERING) {
registerAudioNoisyReceiver();
mMediaPlayer.start();
mState = PlaybackStateCompat.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例3: onPrepared
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
isPlaying = true;
this.duration = mediaPlayer.getDuration();
this.currentTime = mediaPlayer.getCurrentPosition();
updateTimeAudio();
if (jcPlayerServiceListeners != null) {
for (JcPlayerView.JcPlayerViewServiceListener jcPlayerServiceListener : jcPlayerServiceListeners) {
jcPlayerServiceListener.updateTitle(currentJcAudio.getTitle());
jcPlayerServiceListener.onPreparedAudio(currentJcAudio.getTitle(), mediaPlayer.getDuration());
}
}
if (notificationListener != null) {
notificationListener.updateTitle(currentJcAudio.getTitle());
notificationListener.onPreparedAudio(currentJcAudio.getTitle(), mediaPlayer.getDuration());
}
if (jcPlayerStatusListeners != null) {
for (JcPlayerView.JcPlayerViewStatusListener jcPlayerViewStatusListener : jcPlayerStatusListeners) {
jcStatus.setJcAudio(currentJcAudio);
jcStatus.setPlayState(JcStatus.PlayState.PLAY);
jcStatus.setDuration(duration);
jcStatus.setCurrentPosition(currentTime);
jcPlayerViewStatusListener.onPreparedAudioStatus(jcStatus);
}
}
}
示例4: onSeekComplete
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
Log.i(TAG, "onSeekComplete, current position: " + mCurrentPosition);
mCurrentPosition = mediaPlayer.getCurrentPosition();
if (mPlaybackState == PlaybackStateCompat.STATE_BUFFERING) {
mPlayer.start();
mPlaybackState = PlaybackStateCompat.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlayStateChanged(mPlaybackState);
}
}
示例5: onSeekComplete
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* Called when MediaPlayer has completed a seek
*
* @see OnSeekCompleteListener
*/
@Override
public void onSeekComplete(MediaPlayer mp) {
mCurrentPosition = mp.getCurrentPosition();
if (mState == PlaybackStateCompat.STATE_BUFFERING) {
registerAudioNoisyReceiver();
mMediaPlayer.start();
mState = PlaybackStateCompat.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlaybackStateChanged(mState);
}
}
示例6: voicePlay
import android.media.MediaPlayer; //導入方法依賴的package包/類
public static void voicePlay(final MediaPlayer player, String path, final SeekBar seekBar, final Chronometer chronometer) {
if (player != null) {
setChronometer(chronometer, Constant.CHRONOMETER_START);
if (!isPlaying) {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
player.setDataSource(path);
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
isPlaying = true;
}
player.start();
//設置Bar的最大值
int max = player.getDuration();
seekBar.setMax(max);
//定時器更新進度條
final Timer timer = new Timer();
TimerTask timeTask = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
int a = player.getCurrentPosition();
seekBar.setProgress(player.getCurrentPosition());
}
};
timer.schedule(timeTask, 0, 500);
/*player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
player.start();
seekBar.setMax(player.getDuration());
seekBar.setEnabled(true);
}
});*/
//音頻播放完之後重新設置顯示
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
seekBar.setProgress(0);
setChronometer(chronometer, Constant.CHRONOMETER_RESET);
timer.cancel();
}
});
}
}