Skip to content

Commit

Permalink
fix html5 video playback
Browse files Browse the repository at this point in the history
  • Loading branch information
christiantroy committed Jun 22, 2012
1 parent 2fa4bb8 commit ed703a4
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 16 deletions.
24 changes: 24 additions & 0 deletions core/java/android/webkit/HTML5VideoFullScreen.java
Expand Up @@ -10,9 +10,16 @@
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.os.ServiceManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.widget.FrameLayout;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import android.view.ViewParent;
import android.util.Log;


/**
Expand All @@ -22,6 +29,10 @@ public class HTML5VideoFullScreen extends HTML5VideoView
implements MediaPlayerControl, MediaPlayer.OnPreparedListener,
View.OnTouchListener {

private static final String TAG = "HTML5VideoFullScreen";
//add by Bevis
private static final boolean ZOOM_BY_VIDEO_RATIO = true;

// Add this sub-class to handle the resizing when rotating screen.
private class VideoSurfaceView extends SurfaceView {

Expand Down Expand Up @@ -149,6 +160,19 @@ private void prepareForFullScreen() {
mPlayer.reset();
MediaController mc = new FullScreenMediaController(mProxy.getContext(), mLayout);
mc.setSystemUiVisibility(mLayout.getSystemUiVisibility());

if(ZOOM_BY_VIDEO_RATIO){
mPlayer.setOnVideoSizeChangedListener( new MediaPlayer.OnVideoSizeChangedListener() {
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth > 0 && mVideoHeight > 0) {
mVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight);
}
}
});
}

setMediaController(mc);
mPlayer.setScreenOnWhilePlaying(true);
prepareDataAndDisplayMode(mProxy);
Expand Down
32 changes: 32 additions & 0 deletions core/java/android/webkit/HTML5VideoView.java
Expand Up @@ -39,6 +39,10 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {

protected HTML5VideoViewProxy mProxy;

//add by Bevis
static final boolean BREAKPOINT_ON = true;
String mVideoUrl = "";

// Save the seek time when not prepared. This can happen when switching
// video besides initial load.
protected int mSaveSeekTime;
Expand Down Expand Up @@ -86,6 +90,19 @@ public void start() {

public void pause() {
if (isPlaying()) {
if(BREAKPOINT_ON){
int curPos = getCurrentPosition();
int duration = getDuration();
if(curPos > 10000 && curPos < (duration - 10000)){
int olddPoint = mProxy.getBreakpoint(mVideoUrl);
if(olddPoint != curPos){
mProxy.saveBreakpoint(mVideoUrl,curPos - 3000);
}
}
else{
mProxy.deleteBreakpoint(mVideoUrl);
}
}
mPlayer.pause();
} else if (mCurrentState == STATE_NOTPREPARED) {
mPauseDuringPreparing = true;
Expand Down Expand Up @@ -181,6 +198,9 @@ protected static Map<String, String> generateHeaders(String url,

public void setVideoURI(String uri, HTML5VideoViewProxy proxy) {
// When switching players, surface texture will be reused.
if(BREAKPOINT_ON){
mVideoUrl = uri;
}
mUri = Uri.parse(uri);
mHeaders = generateHeaders(uri, proxy);
}
Expand Down Expand Up @@ -228,6 +248,10 @@ public void prepareDataAndDisplayMode(HTML5VideoViewProxy proxy) {
mCurrentState = STATE_NOTPREPARED;
}

//add by Bevis
String getVideoUrl(){
return mVideoUrl;
}

// Common code
public int getVideoLayerId() {
Expand Down Expand Up @@ -259,6 +283,14 @@ public void run() {
@Override
public void onPrepared(MediaPlayer mp) {
mCurrentState = STATE_PREPARED;
if(BREAKPOINT_ON){
if(mProxy != null){
int breakTime = mProxy.getBreakpoint(mVideoUrl);
if(breakTime > 0){
mSaveSeekTime = breakTime;
}
}
}
seekTo(mSaveSeekTime);
if (mProxy != null) {
mProxy.onPrepared(mp);
Expand Down

0 comments on commit ed703a4

Please sign in to comment.