Merge pull request #383 from Bnyro/master

cleanup
This commit is contained in:
Bnyro 2022-06-05 11:45:22 +02:00 committed by GitHub
commit e7f6706c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 33 deletions

View File

@ -15,7 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MY" android:theme="@style/Theme.MY"
android:name=".myApp" android:name=".MyApp"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:largeHeap="true" android:largeHeap="true"
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"

View File

@ -68,7 +68,7 @@ class BackgroundMode {
*/ */
private fun initializePlayerNotification(c: Context) { private fun initializePlayerNotification(c: Context) {
playerNotification = PlayerNotificationManager playerNotification = PlayerNotificationManager
.Builder(c, 1, "background_mode").build() .Builder(c, NOTIFICATION_ID, "background_mode").build()
playerNotification.setPlayer(player) playerNotification.setPlayer(player)
playerNotification.setUsePreviousAction(false) playerNotification.setUsePreviousAction(false)
playerNotification.setUseNextAction(false) playerNotification.setUseNextAction(false)

View File

@ -5,7 +5,9 @@ import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.os.Build import android.os.Build
class myApp : Application() { const val NOTIFICATION_ID = 1
class MyApp : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()

View File

@ -42,6 +42,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.IS_DOWNLOAD_RUNNING import com.github.libretube.IS_DOWNLOAD_RUNNING
import com.github.libretube.MainActivity import com.github.libretube.MainActivity
import com.github.libretube.NOTIFICATION_ID
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SponsorBlockSettings import com.github.libretube.SponsorBlockSettings
import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.CommentsAdapter
@ -118,7 +119,6 @@ class PlayerFragment : Fragment() {
private lateinit var mediaSession: MediaSessionCompat private lateinit var mediaSession: MediaSessionCompat
private lateinit var mediaSessionConnector: MediaSessionConnector private lateinit var mediaSessionConnector: MediaSessionConnector
private lateinit var playerNotification: PlayerNotificationManager private lateinit var playerNotification: PlayerNotificationManager
private val notificationId = 1
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -332,12 +332,15 @@ class PlayerFragment : Fragment() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
try { try {
exoPlayer.release() mediaSession.isActive = false
// kill notification mediaSession.release()
val nManager = context?.getSystemService( mediaSessionConnector.setPlayer(null)
playerNotification.setPlayer(null)
val notificationManager = context?.getSystemService(
Context.NOTIFICATION_SERVICE Context.NOTIFICATION_SERVICE
) as NotificationManager ) as NotificationManager
nManager.cancel(notificationId) notificationManager.cancel(NOTIFICATION_ID)
exoPlayer.release()
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
@ -430,13 +433,15 @@ class PlayerFragment : Fragment() {
} }
private fun prepareExoPlayerView() { private fun prepareExoPlayerView() {
exoPlayerView.setShowSubtitleButton(true) exoPlayerView.apply {
exoPlayerView.setShowNextButton(false) setShowSubtitleButton(true)
exoPlayerView.setShowPreviousButton(false) setShowNextButton(false)
exoPlayerView.setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL) setShowPreviousButton(false)
// exoPlayerView.controllerShowTimeoutMs = 1500 setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
exoPlayerView.controllerHideOnTouch = true // controllerShowTimeoutMs = 1500
exoPlayerView.player = exoPlayer controllerHideOnTouch = true
player = exoPlayer
}
} }
private fun initializePlayerView(view: View, response: Streams) { private fun initializePlayerView(view: View, response: Streams) {
@ -793,33 +798,29 @@ class PlayerFragment : Fragment() {
.build() .build()
exoPlayer.setAudioAttributes(audioAttributes, true) exoPlayer.setAudioAttributes(audioAttributes, true)
setMediaItem(requireContext())
initializePlayerNotification(requireContext()) initializePlayerNotification(requireContext())
} }
private fun setMediaItem(c: Context) { private fun initializePlayerNotification(c: Context) {
mediaSession = MediaSessionCompat(c, this.javaClass.name) mediaSession = MediaSessionCompat(c, this.javaClass.name)
mediaSession.isActive = true mediaSession.apply {
/* might be useful for setting the notification title isActive = true
mediaSession.setMetadata(MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "")
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, "")
.build()
)
*/
mediaSessionConnector = MediaSessionConnector(mediaSession)
mediaSessionConnector.setPlayer(exoPlayer)
} }
private fun initializePlayerNotification(c: Context) { mediaSessionConnector = MediaSessionConnector(mediaSession)
mediaSessionConnector.setPlayer(exoPlayer)
playerNotification = PlayerNotificationManager playerNotification = PlayerNotificationManager
.Builder(c, notificationId, "background_mode") .Builder(c, NOTIFICATION_ID, "background_mode")
.build() .build()
playerNotification.setPlayer(exoPlayer)
playerNotification.setUseNextAction(false) playerNotification.apply {
playerNotification.setUsePreviousAction(false) setPlayer(exoPlayer)
playerNotification.setMediaSessionToken(mediaSession.sessionToken) setUseNextAction(false)
setUsePreviousAction(false)
setMediaSessionToken(mediaSession.sessionToken)
}
} }
private fun isSubscribed(button: MaterialButton, channel_id: String) { private fun isSubscribed(button: MaterialButton, channel_id: String) {