mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-04 07:09:53 +00:00
Updated Spotify and possible fix for media session being killed after 10 minutes of inactivity.
This commit is contained in:
parent
36b53d490f
commit
8766ae176e
3 changed files with 16 additions and 2 deletions
|
@ -15,7 +15,9 @@ import android.media.AudioManager
|
||||||
import android.media.AudioManager.OnAudioFocusChangeListener
|
import android.media.AudioManager.OnAudioFocusChangeListener
|
||||||
import android.media.MediaMetadata
|
import android.media.MediaMetadata
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.os.Looper
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.support.v4.media.MediaMetadataCompat
|
import android.support.v4.media.MediaMetadataCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
|
@ -57,6 +59,15 @@ class MediaPlaybackService : Service() {
|
||||||
private var _audioFocusLossTime_ms: Long? = null
|
private var _audioFocusLossTime_ms: Long? = null
|
||||||
private var _playbackState = PlaybackStateCompat.STATE_NONE;
|
private var _playbackState = PlaybackStateCompat.STATE_NONE;
|
||||||
|
|
||||||
|
private val _updateIntervalMs: Long = 5 * 60 * 1000
|
||||||
|
private val _handler: Handler = Handler(Looper.getMainLooper())
|
||||||
|
private val _updateRunnable: Runnable = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
updateMediaSession(null)
|
||||||
|
_handler.postDelayed(this, _updateIntervalMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
Logger.v(TAG, "onStartCommand");
|
Logger.v(TAG, "onStartCommand");
|
||||||
|
|
||||||
|
@ -74,6 +85,8 @@ class MediaPlaybackService : Service() {
|
||||||
|
|
||||||
_callOnStarted?.invoke(this);
|
_callOnStarted?.invoke(this);
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
|
_handler.postDelayed(_updateRunnable, _updateIntervalMs)
|
||||||
}
|
}
|
||||||
catch(ex: Throwable) {
|
catch(ex: Throwable) {
|
||||||
Logger.e(TAG, "Failed to start MediaPlaybackService due to: " + ex.message, ex);
|
Logger.e(TAG, "Failed to start MediaPlaybackService due to: " + ex.message, ex);
|
||||||
|
@ -143,6 +156,7 @@ class MediaPlaybackService : Service() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Logger.v(TAG, "onDestroy");
|
Logger.v(TAG, "onDestroy");
|
||||||
_instance = null;
|
_instance = null;
|
||||||
|
_handler.removeCallbacks(_updateRunnable)
|
||||||
MediaControlReceiver.onPauseReceived.emit();
|
MediaControlReceiver.onPauseReceived.emit();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e826dcb6a237313e32ec81b0e973a4f69c429c3
|
Subproject commit c700081466038ee4782610feaa05cd4d34d024d8
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e826dcb6a237313e32ec81b0e973a4f69c429c3
|
Subproject commit c700081466038ee4782610feaa05cd4d34d024d8
|
Loading…
Add table
Add a link
Reference in a new issue