Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

* [android] Support attr controls #1663

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public interface Name {
String AUTO_RECYCLE = "autoBitmapRecycle";
String SHOW_INDICATORS = "showIndicators";
String AUTO_PLAY = "autoPlay";
String CONTROLS = "controls";
String SCROLL_DIRECTION = "scrollDirection";
String SCOPE = "scope";
String RECYCLE = "recycle";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public WXVideo(WXSDKInstance instance, WXVContainer parent, boolean isLazy, Basi
@Override
protected FrameLayout initComponentHostView(@NonNull Context context) {
final WXVideoView.Wrapper video = new WXVideoView.Wrapper(context);

video.setOnErrorListener(new MediaPlayer.OnErrorListener() {

@Override
Expand Down Expand Up @@ -230,6 +229,15 @@ public void setAutoPlay(boolean autoPlay) {
}
}

@WXComponentProp(name = Constants.Name.CONTROLS)
public void setControls(String controls) {
if (TextUtils.equals("controls", controls)) {
mWrapper.setControls(true);
} else if (TextUtils.equals("nocontrols", controls)) {
mWrapper.setControls(false);
}
}

private boolean mStopped;

@WXComponentProp(name = Constants.Name.PLAY_STATUS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.MediaController;
Expand Down Expand Up @@ -106,7 +107,7 @@ public static class Wrapper extends FrameLayout implements ViewTreeObserver.OnGl
private MediaPlayer.OnErrorListener mOnErrorListener;
private MediaPlayer.OnCompletionListener mOnCompletionListener;
private WXVideoView.VideoPlayListener mVideoPlayListener;

private boolean mControls = true;

public Wrapper(Context context) {
super(context);
Expand Down Expand Up @@ -226,6 +227,17 @@ public void setOnVideoPauseListener(VideoPlayListener listener) {
}
}

public void setControls(boolean controls) {
mControls = controls;
if (mVideoView != null && mMediaController != null) {
if (!mControls) {
mMediaController.setVisibility(View.GONE);
} else {
mMediaController.setVisibility(View.VISIBLE);
}
}
}

private synchronized void createVideoView() {
if(mVideoView != null){
return;
Expand All @@ -246,7 +258,11 @@ private synchronized void createVideoView() {
controller.setAnchorView(this);
video.setMediaController(controller);
controller.setMediaPlayer(video);

if (!mControls) {
controller.setVisibility(View.GONE);
} else {
controller.setVisibility(View.VISIBLE);
}
mMediaController = controller;
mVideoView = video;

Expand Down