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

Commit

Permalink
* [android] Support attr controls (#1663)
Browse files Browse the repository at this point in the history
* * [android] Support attr controls

* * [android] Rename controls attr
  • Loading branch information
miomin authored and YorkShen committed Oct 24, 2018
1 parent bf595cf commit 1bdc3f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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
20 changes: 18 additions & 2 deletions android/sdk/src/main/java/com/taobao/weex/ui/view/WXVideoView.java
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

0 comments on commit 1bdc3f7

Please sign in to comment.