Skip to content

Commit

Permalink
Merge pull request #9240 from m1ga/6_2_X
Browse files Browse the repository at this point in the history
[TIMOB-25007] (6_2_X) Android: repeatMode for VideoPlayer
  • Loading branch information
Lokesh Choudhary committed Aug 11, 2017
2 parents ceab07d + e9e1ea0 commit 2f23234
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
23 changes: 23 additions & 0 deletions android/modules/media/src/java/android/widget/TiVideoView8.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class TiVideoView8 extends SurfaceView implements MediaPlayerControl
// TITANIUM
private TiPlaybackListener mPlaybackListener;
private float mVolume = 1.0f;
private int mLoop = 0;

public TiVideoView8(Context context)
{
Expand Down Expand Up @@ -396,6 +397,11 @@ private void openVideo()
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.prepareAsync();
mMediaPlayer.setVolume(mVolume, mVolume);
if (mLoop == 0) {
mMediaPlayer.setLooping(false);
} else {
mMediaPlayer.setLooping(true);
}
// we don't set the target state here either, but preserve the
// target state that was there before.
mCurrentState = STATE_PREPARING;
Expand Down Expand Up @@ -863,6 +869,23 @@ public void setScalingMode(int scalingMode)
mScalingMode = scalingMode;
}

public void setRepeatMode(int repeatMode)
{
mLoop = repeatMode;
if (mMediaPlayer != null) {
if (mLoop == 0) {
mMediaPlayer.setLooping(false);
} else {
mMediaPlayer.setLooping(true);
}
}
}

public int getRepeatMode()
{
return mLoop;
}

@Override
public int getAudioSessionId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public class MediaModule extends KrollModule
@Kroll.constant public static final int VIDEO_FINISH_REASON_PLAYBACK_ENDED = 0;
@Kroll.constant public static final int VIDEO_FINISH_REASON_PLAYBACK_ERROR = 1;
@Kroll.constant public static final int VIDEO_FINISH_REASON_USER_EXITED = 2;

@Kroll.constant public static final int VIDEO_REPEAT_MODE_NONE = 0;
@Kroll.constant public static final int VIDEO_REPEAT_MODE_ONE = 1;

@Kroll.constant public static final int VIDEO_TIME_OPTION_NEAREST_KEYFRAME = MediaMetadataRetriever.OPTION_CLOSEST;
@Kroll.constant public static final int VIDEO_TIME_OPTION_CLOSEST_SYNC = MediaMetadataRetriever.OPTION_CLOSEST_SYNC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_VOLUME)) {
videoView.setVolume(TiConvert.toFloat(d, TiC.PROPERTY_VOLUME, 1.0f));
}
if (d.containsKey(TiC.PROPERTY_REPEAT_MODE)) {
videoView.setRepeatMode(TiConvert.toInt(d, TiC.PROPERTY_REPEAT_MODE));
}
}

@Override
Expand Down Expand Up @@ -166,6 +169,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
} else if (key.equals(TiC.PROPERTY_VOLUME)) {
videoView.setVolume(TiConvert.toFloat(newValue));

} else if (key.equals(TiC.PROPERTY_REPEAT_MODE)) {
videoView.setRepeatMode(TiConvert.toInt(newValue));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand All @@ -187,6 +192,15 @@ public void setScalingMode(int mode)

videoView.setScalingMode(mode);
}

public void setRepeatMode(int mode)
{
if (videoView == null) {
return;
}

videoView.setRepeatMode(mode);
}

public void setMediaControlStyle(int style)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@Kroll.proxy(creatableInModule = MediaModule.class, propertyAccessors = {
"url", "initialPlaybackTime", "duration", "contentURL", "autoplay", "endPlaybackTime", "playableDuration",
TiC.PROPERTY_VOLUME
TiC.PROPERTY_VOLUME, TiC.PROPERTY_REPEAT_MODE
})
public class VideoPlayerProxy extends TiViewProxy implements TiLifecycle.OnLifecycleEvent
{
Expand All @@ -56,6 +56,7 @@ public class VideoPlayerProxy extends TiViewProxy implements TiLifecycle.OnLifec
private static final int MSG_RELEASE = MSG_FIRST_ID + 109; // Call view.release() (more drastic)
private static final int MSG_HIDE_MEDIA_CONTROLLER = MSG_FIRST_ID + 110;
private static final int MSG_SET_VIEW_FROM_ACTIVITY = MSG_FIRST_ID + 111;
private static final int MSG_REPEAT_CHANGE = MSG_FIRST_ID + 112;

// Keeping these out of TiC because I believe we'll stop supporting them
// in favor of the documented property, which is "mediaControlStyle".
Expand All @@ -71,6 +72,7 @@ public class VideoPlayerProxy extends TiViewProxy implements TiLifecycle.OnLifec
protected int scalingMode = MediaModule.VIDEO_SCALING_ASPECT_FIT;
private int loadState = MediaModule.VIDEO_LOAD_STATE_UNKNOWN;
private int playbackState = MediaModule.VIDEO_PLAYBACK_STATE_STOPPED;
private int repeatMode = MediaModule.VIDEO_REPEAT_MODE_NONE;

// Used only if TiVideoActivity is used (fullscreen == true)
private Handler videoActivityHandler;
Expand Down Expand Up @@ -318,6 +320,26 @@ public int getPlaybackState()
return playbackState;
}

@Kroll.method @Kroll.getProperty
public int getRepeatMode()
{
return repeatMode;
}

@Kroll.method @Kroll.setProperty
public void setRepeatMode(int mode)
{
boolean alert = (mode != repeatMode);
repeatMode = mode;
if (alert && view != null) {
if (TiApplication.isUIThread()) {
getVideoView().setRepeatMode(mode);
} else {
getMainHandler().sendEmptyMessage(MSG_REPEAT_CHANGE);
}
}
}

@Override
public void hide(@Kroll.argument(optional=true) KrollDict options)
{
Expand Down Expand Up @@ -389,6 +411,12 @@ public boolean handleMessage(Message msg)
setVideoViewFromActivity((TiCompositeLayout) msg.obj);
handled = true;
break;
case MSG_REPEAT_CHANGE:
if (vv != null) {
vv.setRepeatMode(repeatMode);
}
handled = true;
break;
}

if (!handled) {
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,11 @@ public class TiC
*/
public static final String PROPERTY_REPEAT_COUNT = "repeatCount";

/**
* @module.api
*/
public static final String PROPERTY_REPEAT_MODE = "repeatMode";

/**
* @module.api
*/
Expand Down
6 changes: 4 additions & 2 deletions apidoc/Titanium/Media/Media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,14 @@ properties:
summary: Constant for disabling repeat on video playback.
type: Number
permission: read-only
platforms: [iphone, ipad, mobileweb]
platforms: [android, iphone, ipad, mobileweb]
since: {android: "6.2.0", iphone: "0.9.0", ipad: "0.9.0", mobileweb: "1.8"}
- name: VIDEO_REPEAT_MODE_ONE
summary: Constant for repeating one video (i.e., the one video will repeat constantly) during playback.
type: Number
permission: read-only
platforms: [iphone, ipad, mobileweb]
platforms: [android, iphone, ipad, mobileweb]
since: {android: "6.2.0", iphone: "0.9.0", ipad: "0.9.0", mobileweb: "1.8"}
- name: VIDEO_SCALING_ASPECT_FILL
summary: Scale video to fill the screen, clipping edges if necessary.
description: |
Expand Down
3 changes: 2 additions & 1 deletion apidoc/Titanium/Media/VideoPlayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,11 @@ properties:

- name: repeatMode
summary: Determines how the movie player repeats when reaching the end of playback.
platforms: [iphone, ipad, mobileweb]
platforms: [android, iphone, ipad, mobileweb]
type: Number
constants: Titanium.Media.VIDEO_REPEAT_MODE_*
default: Titanium.Media.VIDEO_REPEAT_MODE_NONE
since: {android: "6.2.0", iphone: "0.9.0", ipad: "0.9.0", mobileweb: "1.8"}

- name: scalingMode
summary: Determines how the content scales to fit the view.
Expand Down

0 comments on commit 2f23234

Please sign in to comment.