From 8cf90861a89bafc4ba4e9d7dc1362c472e4d1a9c Mon Sep 17 00:00:00 2001 From: Reza Amuzadeh Date: Thu, 27 Jan 2022 16:21:11 +0330 Subject: [PATCH] fix playerWhenReady issue --- .idea/gradle.xml | 5 +- .idea/misc.xml | 9 ++- .idea/runConfigurations.xml | 10 ---- app/build.gradle | 25 +++++---- .../andexoplayer/MainActivityKotlin.kt | 1 + build.gradle | 8 +-- gradle/wrapper/gradle-wrapper.properties | 6 +- library/build.gradle | 55 +++++++++++-------- .../com/potyvideo/library/AndExoPlayerRoot.kt | 6 +- .../com/potyvideo/library/AndExoPlayerView.kt | 24 ++++---- 10 files changed, 81 insertions(+), 68 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index efee511..57b4f1b 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,11 +4,11 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index a750660..6f16cd7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,12 @@ + + + @@ -43,7 +50,7 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 8b30a6e..c4ae8b0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,13 @@ apply plugin: 'kotlin-android' android { - buildToolsVersion = '29.0.3' - compileSdkVersion 29 + buildToolsVersion = '30.0.3' + compileSdkVersion 30 defaultConfig { applicationId "com.potyvideo.andexoplayer" minSdkVersion 19 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -24,22 +24,27 @@ android { } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = '11' } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.recyclerview:recyclerview:1.2.0-rc01' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation project(path: ':library') } diff --git a/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt b/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt index 3c05602..4c4d676 100644 --- a/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt +++ b/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt @@ -26,6 +26,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli andExoPlayerView.setResizeMode(EnumResizeMode.ZOOM) // sync with attrs andExoPlayerView.setAndExoPlayerListener(this) + andExoPlayerView.setPlayWhenReady(true) findViewById(R.id.local).setOnClickListener(this) findViewById(R.id.stream_mp4).setOnClickListener(this) diff --git a/build.gradle b/build.gradle index 66057e8..b2fd06f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,16 +2,16 @@ buildscript { - ext.kotlin_version = '1.4.30' + ext.kotlin_version = '1.5.31' repositories { google() - jcenter() mavenCentral() + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'com.android.tools.build:gradle:7.0.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" @@ -23,8 +23,8 @@ buildscript { allprojects { repositories { google() - jcenter() mavenCentral() + jcenter() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aac636a..f299cc3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Oct 16 12:53:10 IRST 2020 +#Tue Nov 02 15:35:49 IRST 2021 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index 07a8924..c065a05 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,28 +1,22 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'com.github.dcendents.android-maven' -group = 'com.github.HamidrezaAmz' +apply plugin: 'maven-publish' android { - buildToolsVersion = '29.0.3' - compileSdkVersion 29 + buildToolsVersion = '30.0.3' + compileSdkVersion 30 defaultConfig { minSdkVersion 16 - targetSdkVersion 29 - versionCode 23 - versionName "2.0.7" + targetSdkVersion 30 + versionCode 30 + versionName "3.0.1" vectorDrawables.useSupportLibrary = true multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - - kotlinOptions { - jvmTarget = '1.8' - } } buildTypes { @@ -33,8 +27,12 @@ android { } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = '11' } buildFeatures { @@ -47,10 +45,10 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // Global - implementation "androidx.appcompat:appcompat:1.2.0" - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation "androidx.recyclerview:recyclerview:1.2.0" - implementation "androidx.core:core-ktx:1.3.2" + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // ViewModel and LiveData @@ -60,10 +58,23 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' // Exo Dependencies - api "com.google.android.exoplayer:exoplayer:2.13.2" - api 'com.google.android.exoplayer:exoplayer-ui:2.13.2' - api 'com.google.android.exoplayer:exoplayer-hls:2.13.2' - api 'com.google.android.exoplayer:exoplayer-dash:2.13.2' + api "com.google.android.exoplayer:exoplayer:2.15.0" + api "com.google.android.exoplayer:exoplayer-ui:2.15.0" + api "com.google.android.exoplayer:exoplayer-hls:2.15.0" + api "com.google.android.exoplayer:exoplayer-dash:2.15.0" +} + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + from components.release + groupId = 'com.github.hamidrezaamz' + artifactId = 'MagicalExoPlayer' + version = '3.0.1' + } + } + } } diff --git a/library/src/main/java/com/potyvideo/library/AndExoPlayerRoot.kt b/library/src/main/java/com/potyvideo/library/AndExoPlayerRoot.kt index 779c243..dc030e9 100644 --- a/library/src/main/java/com/potyvideo/library/AndExoPlayerRoot.kt +++ b/library/src/main/java/com/potyvideo/library/AndExoPlayerRoot.kt @@ -14,9 +14,9 @@ import com.potyvideo.library.globalEnums.* import com.potyvideo.library.utils.DoubleClick abstract class AndExoPlayerRoot @JvmOverloads constructor( - context: Context, - attributeSet: AttributeSet? = null, - defStyleAttr: Int = 0 + context: Context, + attributeSet: AttributeSet? = null, + defStyleAttr: Int = 0 ) : LinearLayout(context, attributeSet, defStyleAttr) { private var inflatedView: View = inflate(context, R.layout.layout_player_base_kotlin, this) diff --git a/library/src/main/java/com/potyvideo/library/AndExoPlayerView.kt b/library/src/main/java/com/potyvideo/library/AndExoPlayerView.kt index 0d16039..4ddfd47 100644 --- a/library/src/main/java/com/potyvideo/library/AndExoPlayerView.kt +++ b/library/src/main/java/com/potyvideo/library/AndExoPlayerView.kt @@ -26,13 +26,13 @@ import com.potyvideo.library.utils.PublicValues class AndExoPlayerView( context: Context, attributeSet: AttributeSet -) : AndExoPlayerRoot(context, attributeSet), Player.EventListener { +) : AndExoPlayerRoot(context, attributeSet), /*Player.EventListener ,*/ Player.Listener { private lateinit var currSource: String private var player: SimpleExoPlayer = SimpleExoPlayer.Builder(context).build() private var andExoPlayerListener: AndExoPlayerListener? = null - private var currPlayWhenReady: Boolean = false + private var currPlayWhenReady: Boolean = true private var playbackPosition: Long = 0 private var currentWindow: Int = 0 private var currVolume: Float = 0f @@ -105,7 +105,7 @@ class AndExoPlayerView( setPlayWhenReady( typedArray.getBoolean( R.styleable.AndExoPlayerView_andexo_play_when_ready, - false + true ) ) } @@ -149,26 +149,26 @@ class AndExoPlayerView( ) { } - override fun onPlayerError(error: ExoPlaybackException) { - showRetryView(error.sourceException.message) + override fun onPlayerError(error: PlaybackException) { + showRetryView(error.message) andExoPlayerListener?.let { - andExoPlayerListener!!.onExoPlayerError(errorMessage = error.sourceException.message) + andExoPlayerListener!!.onExoPlayerError(errorMessage = error.message) } } override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { when (playbackState) { ExoPlayer.STATE_BUFFERING -> { - andExoPlayerListener?.let { andExoPlayerListener!!.onExoBuffering() } + andExoPlayerListener?.onExoBuffering() } ExoPlayer.STATE_ENDED -> { - andExoPlayerListener?.let { andExoPlayerListener!!.onExoEnded() } + andExoPlayerListener?.onExoEnded() } ExoPlayer.STATE_IDLE -> { - andExoPlayerListener?.let { andExoPlayerListener!!.onExoIdle() } + andExoPlayerListener?.onExoIdle() } ExoPlayer.STATE_READY -> { - andExoPlayerListener?.let { andExoPlayerListener!!.onExoReady() } + andExoPlayerListener?.onExoReady() } else -> { @@ -261,7 +261,7 @@ class AndExoPlayerView( val mediaItem = buildMediaItem(source, extraHeaders) playerView.player = player - player.playWhenReady = true + player.playWhenReady = currPlayWhenReady player.setMediaItem(mediaItem) player.prepare() } @@ -373,7 +373,7 @@ class AndExoPlayerView( } } - fun setPlayWhenReady(playWhenReady: Boolean = false) { + fun setPlayWhenReady(playWhenReady: Boolean = true) { this.currPlayWhenReady = playWhenReady player.playWhenReady = playWhenReady }