本文整理汇总了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();
}
});
}
}