Skip to content

Commit

Permalink
feat(android): videoPlayer autoHide (#13725)
Browse files Browse the repository at this point in the history
* feat(android): videoPlayer autoHide

* brackes, link in docs

* docs
  • Loading branch information
m1ga authored Feb 7, 2023
1 parent 66d46dd commit 8b37384
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions android/modules/media/src/java/android/widget/TiVideoView8.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class TiVideoView8 extends SurfaceView implements MediaPlayerControl
// preparing
@SuppressWarnings("unused")
private int mStateWhenSuspended; // state before calling suspend()
private boolean autoHide = false;

// TITANIUM
private TiPlaybackListener mPlaybackListener;
Expand Down Expand Up @@ -492,6 +493,9 @@ public void onPrepared(MediaPlayer mp)
// so
// start the video here instead of in the callback.
if (mTargetState == STATE_PLAYING) {
if (autoHide) {
setAlpha(1);
}
start();
if (mMediaController != null) {
mMediaController.show();
Expand Down Expand Up @@ -636,6 +640,9 @@ public void surfaceDestroyed(SurfaceHolder holder)
if (mCurrentState != STATE_SUSPEND) {
release(true);
}
if (autoHide) {
setAlpha(0);
}
}
};

Expand Down Expand Up @@ -884,4 +891,12 @@ public int getAudioSessionId()
// TODO Auto-generated method stub
return 0;
}

public void setAutoHide(boolean value)
{
if (value) {
setAlpha(0);
}
autoHide = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_REPEAT_MODE)) {
videoView.setRepeatMode(TiConvert.toInt(d, TiC.PROPERTY_REPEAT_MODE));
}
if (d.containsKey("autoHide")) {
videoView.setAutoHide(TiConvert.toBoolean(d, "autoHide"));
}
}

@Override
Expand All @@ -161,6 +164,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
videoView.setRepeatMode(TiConvert.toInt(newValue));
} else if (key.equals(TiC.PROPERTY_SHOWS_CONTROLS)) {
setMediaControlStyle(getPlayerProxy().getMediaControlStyle());
} else if (key.equals("autoHide")) {
videoView.setAutoHide(TiConvert.toBoolean(newValue));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down
12 changes: 12 additions & 0 deletions apidoc/Titanium/Media/VideoPlayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ properties:
type: Boolean
default: true

- name: autoHide
summary: Indicates if player is hidden by default and shown when its ready.
description: |
On Android the background of the video player is set to the primary background color.
When switching on `autoHide` it will hide the player until the video is loaded.
Then it will automatically show the player. In a <Titanium.UI.ListView> it will hide
it again when it is outside the viewport.
type: Boolean
platforms: [android]
since: 12.1.0
default: false

- name: backgroundView
deprecated:
since: "7.0.0"
Expand Down

0 comments on commit 8b37384

Please sign in to comment.