Skip to content

Commit

Permalink
fix playerWhenReady issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Jan 27, 2022
1 parent 73e0a6b commit 8cf9086
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 68 deletions.
5 changes: 2 additions & 3 deletions .idea/gradle.xml

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

9 changes: 8 additions & 1 deletion .idea/misc.xml

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

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

25 changes: 15 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli

andExoPlayerView.setResizeMode(EnumResizeMode.ZOOM) // sync with attrs
andExoPlayerView.setAndExoPlayerListener(this)
andExoPlayerView.setPlayWhenReady(true)

findViewById<AppCompatButton>(R.id.local).setOnClickListener(this)
findViewById<AppCompatButton>(R.id.stream_mp4).setOnClickListener(this)
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -23,8 +23,8 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
jcenter()
}
}

Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
55 changes: 33 additions & 22 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -33,8 +27,12 @@ android {
}

compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '11'
}

buildFeatures {
Expand All @@ -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
Expand All @@ -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'
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions library/src/main/java/com/potyvideo/library/AndExoPlayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,7 +105,7 @@ class AndExoPlayerView(
setPlayWhenReady(
typedArray.getBoolean(
R.styleable.AndExoPlayerView_andexo_play_when_ready,
false
true
)
)
}
Expand Down Expand Up @@ -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 -> {

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -373,7 +373,7 @@ class AndExoPlayerView(
}
}

fun setPlayWhenReady(playWhenReady: Boolean = false) {
fun setPlayWhenReady(playWhenReady: Boolean = true) {
this.currPlayWhenReady = playWhenReady
player.playWhenReady = playWhenReady
}
Expand Down

0 comments on commit 8cf9086

Please sign in to comment.