|
|
|
@ -67,91 +67,13 @@ public class PreviewActivity extends AppCompatActivity implements View.OnClickLi |
|
|
|
|
private float[] ratios; |
|
|
|
|
private String[] ratioLabels; |
|
|
|
|
|
|
|
|
|
private SurfaceHolder.Callback surfaceCallbacks = new SurfaceHolder.Callback() { |
|
|
|
|
@Override |
|
|
|
|
public void surfaceCreated(SurfaceHolder holder) { |
|
|
|
|
showVideoPreview(holder); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private MediaController.MediaPlayerControl MediaPlayerControlImpl = new MediaController.MediaPlayerControl() { |
|
|
|
|
@Override |
|
|
|
|
public void start() { |
|
|
|
|
mediaPlayer.start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void pause() { |
|
|
|
|
mediaPlayer.pause(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getDuration() { |
|
|
|
|
return mediaPlayer.getDuration(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getCurrentPosition() { |
|
|
|
|
return mediaPlayer.getCurrentPosition(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void seekTo(int pos) { |
|
|
|
|
mediaPlayer.seekTo(pos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isPlaying() { |
|
|
|
|
return mediaPlayer.isPlaying(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getBufferPercentage() { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canPause() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canSeekBackward() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canSeekForward() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getAudioSessionId() { |
|
|
|
|
return mediaPlayer.getAudioSessionId(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public static Intent newIntentPhoto(Context context, |
|
|
|
|
String filePath) { |
|
|
|
|
|
|
|
|
|
public static Intent newIntentPhoto(Context context, String filePath) { |
|
|
|
|
return new Intent(context, PreviewActivity.class) |
|
|
|
|
.putExtra(MEDIA_ACTION_ARG, MediaAction.ACTION_PHOTO) |
|
|
|
|
.putExtra(FILE_PATH_ARG, filePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Intent newIntentVideo(Context context, |
|
|
|
|
String filePath) { |
|
|
|
|
|
|
|
|
|
public static Intent newIntentVideo(Context context, String filePath) { |
|
|
|
|
return new Intent(context, PreviewActivity.class) |
|
|
|
|
.putExtra(MEDIA_ACTION_ARG, MediaAction.ACTION_VIDEO) |
|
|
|
|
.putExtra(FILE_PATH_ARG, filePath); |
|
|
|
@ -278,7 +200,22 @@ public class PreviewActivity extends AppCompatActivity implements View.OnClickLi |
|
|
|
|
loadVideoParams(savedInstanceState); |
|
|
|
|
} |
|
|
|
|
photoPreviewContainer.setVisibility(View.GONE); |
|
|
|
|
surfaceView.getHolder().addCallback(surfaceCallbacks); |
|
|
|
|
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { |
|
|
|
|
@Override |
|
|
|
|
public void surfaceCreated(SurfaceHolder holder) { |
|
|
|
|
showVideoPreview(holder); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void showVideoPreview(SurfaceHolder holder) { |
|
|
|
@ -292,7 +229,62 @@ public class PreviewActivity extends AppCompatActivity implements View.OnClickLi |
|
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
|
mediaController = new MediaController(PreviewActivity.this); |
|
|
|
|
mediaController.setAnchorView(surfaceView); |
|
|
|
|
mediaController.setMediaPlayer(MediaPlayerControlImpl); |
|
|
|
|
mediaController.setMediaPlayer(new MediaController.MediaPlayerControl() { |
|
|
|
|
@Override |
|
|
|
|
public void start() { |
|
|
|
|
mediaPlayer.start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void pause() { |
|
|
|
|
mediaPlayer.pause(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getDuration() { |
|
|
|
|
return mediaPlayer.getDuration(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getCurrentPosition() { |
|
|
|
|
return mediaPlayer.getCurrentPosition(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void seekTo(int pos) { |
|
|
|
|
mediaPlayer.seekTo(pos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isPlaying() { |
|
|
|
|
return mediaPlayer.isPlaying(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getBufferPercentage() { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canPause() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canSeekBackward() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean canSeekForward() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getAudioSessionId() { |
|
|
|
|
return mediaPlayer.getAudioSessionId(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
int videoWidth = mp.getVideoWidth(); |
|
|
|
|
int videoHeight = mp.getVideoHeight(); |
|
|
|
|