use a separate scope to update playheads
viewModelScope will be cleard when the activity is stopped, but the playhead update should be done anyway fixes #62
This commit is contained in:
parent
522b893dc8
commit
8eb737a831
|
@ -85,8 +85,6 @@ class PlayerActivity : AppCompatActivity() {
|
|||
hideBars() // Initial hide the bars
|
||||
|
||||
playerBinding = ActivityPlayerBinding.bind(findViewById(R.id.player_root))
|
||||
|
||||
println(findViewById(R.id.player_controls_root))
|
||||
controlsBinding = PlayerControlsBinding.bind(findViewById(R.id.player_controls_root))
|
||||
|
||||
model.loadMediaAsync(
|
||||
|
|
|
@ -32,10 +32,7 @@ import com.google.android.exoplayer2.ExoPlayer
|
|||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.crunchyroll.*
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
|
@ -276,7 +273,8 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
|||
val playhead = (player.currentPosition / 1000)
|
||||
|
||||
if (playhead > 0 && Preferences.updatePlayhead) {
|
||||
viewModelScope.launch { Crunchyroll.postPlayheads(currentEpisode.id, playhead.toInt()) }
|
||||
// don't use viewModelScope here. This task may needs to finish, when ViewModel will be cleared
|
||||
CoroutineScope(Dispatchers.IO).launch { Crunchyroll.postPlayheads(currentEpisode.id, playhead.toInt()) }
|
||||
Log.i(javaClass.name, "Set playhead for episode ${currentEpisode.id} to $playhead sec.")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue