Skip to content

Commit

Permalink
add loop support + update exoPlayer core
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Apr 23, 2020
1 parent d4445f9 commit 80d6a9b
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 11 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

testImplementation 'junit:junit:4.12'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_height="wrap_content"
app:andexo_aspect_ratio="aspect_16_9"
app:andexo_full_screen="true"
app:andexo_loop="finite"
app:andexo_play_when_ready="true"
app:andexo_resize_mode="Fit"
app:andexo_show_controller="true" />
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jun 27 12:19:07 GMT+03:30 2019
#Thu Apr 23 18:42:10 IRDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 14
versionName "1.0.14"
versionCode 15
versionName "1.0.15"
vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -33,9 +33,9 @@ dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'

implementation 'com.google.android.exoplayer:exoplayer:2.10.3'
implementation 'com.google.android.exoplayer:exoplayer:2.11.4'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
44 changes: 41 additions & 3 deletions library/src/main/java/com/potyvideo/library/AndExoPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.LoopingMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
Expand All @@ -47,6 +48,7 @@
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.potyvideo.library.globalEnums.EnumAspectRatio;
import com.potyvideo.library.globalEnums.EnumLoop;
import com.potyvideo.library.globalEnums.EnumResizeMode;
import com.potyvideo.library.globalInterfaces.ExoPlayerCallBack;
import com.potyvideo.library.utils.PublicFunctions;
Expand All @@ -67,6 +69,7 @@ public class AndExoPlayerView extends LinearLayout implements View.OnClickListen
private boolean showController = true;
private EnumResizeMode currResizeMode = EnumResizeMode.FILL;
private EnumAspectRatio currAspectRatio = EnumAspectRatio.ASPECT_16_9;
private EnumLoop currLoop = EnumLoop.Finite;

private SimpleExoPlayer simpleExoPlayer;
private PlayerView playerView;
Expand Down Expand Up @@ -230,6 +233,11 @@ private void initializeView(Context context) {
setShowController(typedArray.getBoolean(R.styleable.AndExoPlayerView_andexo_show_controller, true));
}

if (typedArray.hasValue(R.styleable.AndExoPlayerView_andexo_loop)) {
EnumLoop enumLoop = EnumLoop.get(typedArray.getInteger(R.styleable.AndExoPlayerView_andexo_loop, EnumLoop.Finite.getValue()));
setLoopMode(enumLoop);
}

typedArray.recycle();
}

Expand All @@ -239,7 +247,7 @@ private void initializeView(Context context) {
public SimpleExoPlayer getPlayer() {
return simpleExoPlayer;
}

private void initializePlayer() {

if (simpleExoPlayer == null) {
Expand All @@ -263,7 +271,20 @@ public void setSource(String source) {
if (mediaSource != null) {
if (simpleExoPlayer != null) {
showProgress();
simpleExoPlayer.prepare(mediaSource, true, false);

switch (currLoop) {
case INFINITE: {
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
simpleExoPlayer.prepare(loopingSource, true, false);
break;
}

case Finite:
default: {
simpleExoPlayer.prepare(mediaSource, true, false);
break;
}
}
}
}
}
Expand All @@ -273,7 +294,20 @@ public void setSource(String source, HashMap<String, String> extraHeaders) {
if (mediaSource != null) {
if (simpleExoPlayer != null) {
showProgress();
simpleExoPlayer.prepare(mediaSource, true, false);

switch (currLoop) {
case INFINITE: {
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
simpleExoPlayer.prepare(loopingSource, true, false);
break;
}

case Finite:
default: {
simpleExoPlayer.prepare(mediaSource, true, false);
break;
}
}
}
}
}
Expand Down Expand Up @@ -444,6 +478,10 @@ public void setAspectRatio(EnumAspectRatio aspectRatio) {
}
}

private void setLoopMode(EnumLoop loopMode) {
this.currLoop = loopMode;
}

private Activity getActivity() {
Context context = getContext();
while (context instanceof ContextWrapper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.potyvideo.library.globalEnums;

public enum EnumLoop {

UNDEFINE("UNDEFINE", -1),
INFINITE("Infinite", 1),
Finite("Finite", 2),
;

private String valueStr;

private Integer value;

EnumLoop(String valueStr, Integer value) {
this.valueStr = valueStr;
this.value = value;
}

public static EnumLoop get(String value) {
if (value == null) {
return UNDEFINE;
}

EnumLoop[] arr$ = values();
for (EnumLoop val : arr$) {
if (val.valueStr.equalsIgnoreCase(value.trim())) {
return val;
}
}

return UNDEFINE;
}

public static EnumLoop get(Integer value) {

if (value == null) {
return UNDEFINE;
}

EnumLoop[] arr$ = values();
for (EnumLoop val : arr$) {
if (val.value == value) {
return val;
}
}

return UNDEFINE;
}

public String getValueStr() {
return valueStr;
}

public Integer getValue() {
return value;
}

public void setValueStr(String valueStr) {
this.valueStr = valueStr;
}
}
6 changes: 6 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<declare-styleable name="AndExoPlayerView">
<attr name="andexo_resize_mode" />
<attr name="andexo_aspect_ratio" />
<attr name="andexo_loop" />
<attr name="andexo_full_screen" format="boolean" />
<attr name="andexo_play_when_ready" format="boolean" />
<attr name="andexo_show_controller" format="boolean" />
Expand All @@ -23,4 +24,9 @@
<enum name="aspect_mp3" value="5" />
</attr>

<attr name="andexo_loop" format="enum">
<enum name="infinite" value="1" />
<enum name="finite" value="2" />
</attr>

</resources>

0 comments on commit 80d6a9b

Please sign in to comment.