本文整理汇总了Java中net.protyposis.android.mediaplayer.MediaPlayer类的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer类的具体用法?Java MediaPlayer怎么用?Java MediaPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaPlayer类属于net.protyposis.android.mediaplayer包,在下文中一共展示了MediaPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPrepared
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
mCurrentState = STATE_PREPARED;
setPlaybackSpeed(mPlaybackSpeedWhenPrepared);
if(mOnPreparedListener != null) {
mOnPreparedListener.onPrepared(mp);
}
int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call
if (seekToPosition != 0) {
seekTo(seekToPosition);
}
if(mTargetState == STATE_PLAYING) {
start();
}
}
示例2: onCompletion
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onCompletion(MediaPlayer mp) {
mCurrentState = STATE_PLAYBACK_COMPLETED;
mTargetState = STATE_PLAYBACK_COMPLETED;
if(mOnCompletionListener != null) {
mOnCompletionListener.onCompletion(mp);
}
stayAwake(false);
}
示例3: onError
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if(mOnErrorListener != null) {
return mOnErrorListener.onError(mp, what, extra);
}
return true;
}
示例4: onInfo
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if(mOnInfoListener != null) {
return mOnInfoListener.onInfo(mp, what, extra);
}
return true;
}
示例5: openVideo
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
private void openVideo() {
if (mSource == null || mInputSurfaceHolder == null) {
// not ready for playback yet, will be called again later
return;
}
release();
mPlayer = new MediaPlayer();
mPlayer.setSurface(getInputHolder().getSurface());
mPlayer.setOnPreparedListener(mPreparedListener);
mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
mPlayer.setOnSeekListener(mSeekListener);
mPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.setOnErrorListener(mErrorListener);
mPlayer.setOnInfoListener(mInfoListener);
// Create a handler for the error message in case an exceptions happens in the following thread
final Handler exceptionHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
return true;
}
});
// Set the data source asynchronously as this might take a while, e.g. is data has to be
// requested from the network/internet.
// IMPORTANT:
// We use a Thread instead of an AsyncTask for performance reasons, because threads started
// in an AsyncTask perform much worse, no matter the priority the Thread gets (unless the
// AsyncTask's priority is elevated before creating the Thread).
// See comment in MediaPlayer#prepareAsync for detailed explanation.
new Thread(new Runnable() {
@Override
public void run() {
try {
mPlayer.setDataSource(mSource);
// Async prepare spawns another thread inside this thread which really isn't
// necessary; we call this method anyway because of the events it triggers
// when it fails, and to stay in sync which the Android VideoView that does
// the same.
mPlayer.prepareAsync();
mCurrentState = STATE_PREPARING;
Log.d(TAG, "video opened");
} catch (IOException e) {
Log.e(TAG, "video open failed", e);
// Send message to the handler that an error occurred
// (we don't need a message id as the handler only handles this single message)
exceptionHandler.sendEmptyMessage(0);
}
}
}).start();
}
示例6: setOnPreparedListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
this.mOnPreparedListener = l;
}
示例7: setOnSeekListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnSeekListener(MediaPlayer.OnSeekListener l) {
this.mOnSeekListener = l;
}
示例8: setOnSeekCompleteListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener l) {
this.mOnSeekCompleteListener = l;
}
示例9: setOnCompletionListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
this.mOnCompletionListener = l;
}
示例10: setOnErrorListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnErrorListener(MediaPlayer.OnErrorListener l) {
this.mOnErrorListener = l;
}
示例11: setOnInfoListener
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnInfoListener(MediaPlayer.OnInfoListener l) {
this.mOnInfoListener = l;
}
示例12: getSeekMode
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public MediaPlayer.SeekMode getSeekMode() {
return mPlayer.getSeekMode();
}
示例13: setSeekMode
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setSeekMode(MediaPlayer.SeekMode seekMode) {
mPlayer.setSeekMode(seekMode);
}
示例14: onVideoSizeChanged
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
updateResolution(width, height);
}
示例15: onSeek
import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onSeek(MediaPlayer mp) {
if(mOnSeekListener != null) {
mOnSeekListener.onSeek(mp);
}
}