mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
notification click && subtitles fix
This commit is contained in:
parent
a56ff97665
commit
fc2a001b45
@ -34,7 +34,8 @@
|
||||
android:supportsPictureInPicture="true"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||
android:hardwareAccelerated="true"
|
||||
android:screenOrientation="userPortrait">
|
||||
android:screenOrientation="userPortrait"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -77,7 +77,8 @@ class BackgroundMode {
|
||||
DescriptionAdapter(
|
||||
response?.title!!,
|
||||
response?.uploader!!,
|
||||
response?.thumbnailUrl!!
|
||||
response?.thumbnailUrl!!,
|
||||
c
|
||||
)
|
||||
)
|
||||
.build()
|
||||
|
@ -721,11 +721,11 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
// create a list of subtitles
|
||||
val subtitle = mutableListOf<SubtitleConfiguration>()
|
||||
if (response.subtitles!!.isNotEmpty()) {
|
||||
response.subtitles!!.forEach {
|
||||
subtitle.add(
|
||||
SubtitleConfiguration.Builder(response.subtitles[0].url!!.toUri())
|
||||
.setMimeType(response.subtitles[0].mimeType!!) // The correct MIME type (required).
|
||||
.setLanguage(response.subtitles[0].code) // The subtitle language (optional).
|
||||
SubtitleConfiguration.Builder(it.url!!.toUri())
|
||||
.setMimeType(it.mimeType!!) // The correct MIME type (required).
|
||||
.setLanguage(it.code) // The subtitle language (optional).
|
||||
.build()
|
||||
)
|
||||
}
|
||||
@ -867,7 +867,7 @@ class PlayerFragment : Fragment() {
|
||||
playerNotification = PlayerNotificationManager
|
||||
.Builder(c, 1, "background_mode")
|
||||
.setMediaDescriptionAdapter(
|
||||
DescriptionAdapter(title, uploader, thumbnailUrl)
|
||||
DescriptionAdapter(title, uploader, thumbnailUrl, requireContext())
|
||||
)
|
||||
.build()
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import com.github.libretube.MainActivity
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
||||
import java.net.URL
|
||||
@ -14,32 +17,58 @@ import java.net.URL
|
||||
class DescriptionAdapter(
|
||||
private val title: String,
|
||||
private val channelName: String,
|
||||
private val thumbnailUrl: String
|
||||
private val thumbnailUrl: String,
|
||||
private val context: Context
|
||||
) :
|
||||
PlayerNotificationManager.MediaDescriptionAdapter {
|
||||
/**
|
||||
* sets the title of the notification
|
||||
*/
|
||||
override fun getCurrentContentTitle(player: Player): CharSequence {
|
||||
// return controller.metadata.description.title.toString()
|
||||
return title
|
||||
}
|
||||
|
||||
/**
|
||||
* overrides the action when clicking the notification
|
||||
*/
|
||||
override fun createCurrentContentIntent(player: Player): PendingIntent? {
|
||||
// return controller.sessionActivity
|
||||
return null
|
||||
/**
|
||||
* starts a new MainActivity Intent when the player notification is clicked
|
||||
* it doesn't start a completely new MainActivity because the MainActivity's launchMode
|
||||
* is set to "singleTop" in the AndroidManifest (important!!!)
|
||||
* that's the only way to launch back into the previous activity (e.g. the player view
|
||||
*/
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
/**
|
||||
* the description of the notification (below the title)
|
||||
*/
|
||||
override fun getCurrentContentText(player: Player): CharSequence? {
|
||||
// return controller.metadata.description.subtitle.toString()
|
||||
return channelName
|
||||
}
|
||||
|
||||
/**
|
||||
* return the icon/thumbnail of the video
|
||||
*/
|
||||
override fun getCurrentLargeIcon(
|
||||
player: Player,
|
||||
callback: PlayerNotificationManager.BitmapCallback
|
||||
): Bitmap? {
|
||||
lateinit var bitmap: Bitmap
|
||||
|
||||
/**
|
||||
* running on a new thread to prevent a NetworkMainThreadException
|
||||
*/
|
||||
val thread = Thread {
|
||||
try {
|
||||
// try to parse the thumbnailUrl to a Bitmap
|
||||
/**
|
||||
* try to GET the thumbnail from the URL
|
||||
*/
|
||||
val inputStream = URL(thumbnailUrl).openStream()
|
||||
bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
} catch (ex: java.lang.Exception) {
|
||||
@ -48,9 +77,14 @@ class DescriptionAdapter(
|
||||
}
|
||||
thread.start()
|
||||
thread.join()
|
||||
// return bitmap if initialized
|
||||
/**
|
||||
* returns the scaled bitmap if it got fetched successfully
|
||||
*/
|
||||
return try {
|
||||
bitmap
|
||||
val resizedBitmap = Bitmap.createScaledBitmap(
|
||||
bitmap, 1080, 1080, false
|
||||
)
|
||||
resizedBitmap
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user