Skip to content

Commit

Permalink
Merge pull request #69 from dev-labs-bg/feature/change-video-file-run…
Browse files Browse the repository at this point in the history
…time

Feature - change video file runtime
  • Loading branch information
slavipetrov authored Apr 3, 2020
2 parents 33567bd + 87d48c8 commit a198266
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,55 @@ public FullscreenVideoView setSeekToTimeMillis(int timeMillis) {
return this;
}

/**
* Pauses the video at runtime.
*
* This method is not part of the building pattern and because of that it's not returning
* an instance of FullscreenVideoView.
*/
public void pause() {
if (fullscreenVideoMediaPlayer != null) {
fullscreenVideoMediaPlayer.pause();
}
}

/**
* Plays the video at runtime.
*
* This method is not part of the building pattern and because of that it's not returning
* an instance of FullscreenVideoView.
*/
public void play() {
if (fullscreenVideoMediaPlayer != null) {
fullscreenVideoMediaPlayer.start();
hideThumbnail();
}
}

/**
* Changes the video URL at runtime.
*
* This method is not part of the building pattern and because of that it's not returning
* an instance of FullscreenVideoView.
*
* @param url The new video URL.
*/
public void changeUrl(@NonNull String url) {
changeSource(url);
}

/**
* Changes the video file at runtime.
*
* This method is not part of the building pattern and because of that it's not returning
* an instance of FullscreenVideoView.
*
* @param videoFile The new video file.
*/
public void changeVideoFile(@NonNull File videoFile) {
changeSource(videoFile.getPath());
}

/**
* Gets a drawable by it's resource id.
*
Expand Down Expand Up @@ -940,25 +989,12 @@ private void updateLayoutParams(ViewGroup.MarginLayoutParams params) {
setLayoutParams(params);
}

public void pause() {
if (fullscreenVideoMediaPlayer != null) {
fullscreenVideoMediaPlayer.pause();
}
}

public void play() {
if (fullscreenVideoMediaPlayer != null) {
fullscreenVideoMediaPlayer.start();
hideThumbnail();
}
}

public void changeUrl(@NonNull final String url) {
private void changeSource(String videoPath) {
handleOnDetach();

init(attrs);

setupMediaPlayer(url);
setupMediaPlayer(videoPath);

if (args.autoStartEnabled) {
enableAutoStart();
Expand Down Expand Up @@ -1042,11 +1078,6 @@ public void changeUrl(@NonNull final String url) {
playbackSpeedOptions(playbackSpeedOptions);
}

int thumbnailResId = args.thumbnailResId;
if (thumbnailResId != -1) {
thumbnail(thumbnailResId);
}

if (args.hideProgress) {
hideProgress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ class VideoControllerView extends FrameLayout
private int fastForwardDuration = Constants.FAST_FORWARD_DURATION;
private int rewindDuration = Constants.REWIND_DURATION;

private ViewTreeObserver.OnWindowFocusChangeListener onWindowFocusChangeListener =
new ViewTreeObserver.OnWindowFocusChangeListener() {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (videoView.isLandscape()) {
((Activity) getContext())
.getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
}
};

public VideoControllerView(Context context) {
super(context);
LayoutInflater layoutInflater = LayoutInflater.from(context);
Expand Down Expand Up @@ -166,27 +186,7 @@ public void init(AttributeSet attrs) {

handler = new MessageHandler(this);

// TODO: Move this to another method
getViewTreeObserver().addOnWindowFocusChangeListener(
new ViewTreeObserver.OnWindowFocusChangeListener() {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (videoView.isLandscape()) {
((Activity) getContext())
.getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
}
}
);
getViewTreeObserver().addOnWindowFocusChangeListener(onWindowFocusChangeListener);
}

@Override
Expand Down Expand Up @@ -623,6 +623,7 @@ public void onDetach() {

videoView = null;
mediaControllerListener = null;
getViewTreeObserver().removeOnWindowFocusChangeListener(onWindowFocusChangeListener);
}

public void setEnterFullscreenDrawable(Drawable enterFullscreenDrawable) {
Expand Down

0 comments on commit a198266

Please sign in to comment.