Skip to content

Commit

Permalink
fix: ensure that video controls are shown by default and forever (unt…
Browse files Browse the repository at this point in the history
…il dismissed) (#76)

* fix: only set media controller once to avoid unnecessarily hiding the controls

* fix: override `MediaController` so that `show` prefers having no timeout
  • Loading branch information
G-Rath authored May 16, 2023
1 parent a2a7a09 commit c3f1568
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ public static SignVideoFragment newInstance(DictItem dictItem) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMediaController = new MediaController(getContext());
mMediaController = new MediaController(getContext()) {
@Override
public void show(int timeout) {
// we want the controller to remain shown until hide() is called by default,
// which can be done by passing a timeout of 0; however some of the private
// internals of MediaController call show _and_ they favor doing so with the
// default value explicitly rather than calling show(), so we have to do this
// override which just turns any use of the default value into 0.
super.show(timeout == 3000 ? 0 : timeout);
}
};
mNetworkManager = new NetworkManager();
if (getArguments() != null) {
mDictItem = (DictItem) getArguments().getSerializable(ARG_DICT_ITEM);
Expand Down Expand Up @@ -108,10 +118,22 @@ public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});

final boolean[] isPrepared = { false };
mVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// avoid resetting the media controller multiple times, because
// that triggers the controls to be hidden which can be confusing
if (isPrepared[0]) {
mVideo.start();

return;
}

mVideo.setMediaController(mMediaController);
mMediaController.setAnchorView(mAnchorView);
isPrepared[0] = true;

mVideo.start();
}
});
Expand Down

0 comments on commit c3f1568

Please sign in to comment.