// we need), so we won’t get a “surface changed” callback, so
// start the video here instead of in the callback.
if (seekWhenPrepared != 0) {
mediaPlayer.seekTo(seekWhenPrepared);
seekWhenPrepared = 0;
}
if (startWhenPrepared) {
mediaPlayer.start();
startWhenPrepared = false;
if (mediaController != null) {
mediaController.show();
}
} else if (!isPlaying() &&
(seekWhenPrepared != 0 || getCurrentPosition() > 0)) {
if (mediaController != null) {
// Show the media controls when we’re paused into a video and make 'em stick.
mediaController.show(0);
}
}
}
} else {
// We don’t know the video size yet, but should start anyway.
// The video size might be reported to us later.
if (seekWhenPrepared != 0) {
mediaPlayer.seekTo(seekWhenPrepared);
seekWhenPrepared = 0;
}
if (startWhenPrepared) {
mediaPlayer.start();
startWhenPrepared = false;
}
}
}
};
private OnCompletionListener mCompletionListener =
new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (mediaController != null) {
mediaController.hide();
}
if (myOnCompletionListener != null) {
myOnCompletionListener.onCompletion(mediaPlayer);
}
}
};
private OnErrorListener mErrorListener =
new OnErrorListener() {
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d(TAG, "Error: " + framework_err + “,” + impl_err);
if (mediaController != null) {
mediaController.hide();
}
/* If an error handler has been supplied, use it and finish. */
if (myOnErrorListener != null) {
if (myOnErrorListener.onError(mediaPlayer, framework_err, impl_err)) {
return true;
}
}
/* Otherwise, pop up an error dialog so the user knows that
-
something bad has happened. Only try and pop up the dialog
-
if we’re attached to a window. When we’re going away and no
-
longer have a window, don’t bother showing the user an error.
*/
if (getWindowToken() != null) {
Resources r = mContext.getResources();
int messageId;
/* if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
messageId = com.android.internal.R.string.VideoView_error_text_invalid_progressive_playback;
} else {
messageId = com.android.internal.R.string.VideoView_error_text_unknown;
}
new AlertDialog.Builder(mContext)
.setTitle(com.android.internal.R.string.VideoView_error_title)
.setMessage(messageId)
.setPositiveButton(com.android.internal.R.string.VideoView_error_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
If we get here, there is no onError listener, so
- at least inform them that the video is over.
if (mOnCompletionListener != null) {
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}
})
.setCancelable(false)
.show();*/
}
return true;
}
};
private MediaPlayer.OnBufferingUpdateListener mBufferingUpdateListener =
new MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
currentBufferPercentage = percent;
}
};
/**
-
Register a callback to be invoked when the media file
-
is loaded and ready to go.
-
@param l The callback that will be run
*/
public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
myOnPreparedListener = l;
}
/**
-
Register a callback to be invoked when the end of a media file
-
has been reached during playback.
-
@param l The callback that will be run
*/
public void setOnCompletionListener(OnCompletionListener l) {
myOnCompletionListener = l;
}
/**
-
Register a callback to be invoked when an error occurs
-
during playback or setup. If no listener is specified,
-
or if the listener returned false, VideoView will inform
-
the user of any errors.
-
@param l The callback that will be run
*/
public void setOnErrorListener(OnErrorListener l) {
myOnErrorListener = l;
}
SurfaceHolder.Callback mSHCallback = new SurfaceHolder.Callback() {
public void surfaceChanged(SurfaceHolder holder, int format,
int w, int h) {
surfaceWidth = w;
surfaceHeight = h;
if (mediaPlayer != null && isPrepared && videoWidth == w && videoHeight == h) {
if (seekWhenPrepared != 0) {
mediaPlayer.seekTo(seekWhenPrepared);
seekWhenPrepared = 0;
}
mediaPlayer