Remote Volume Provider for Chromecast Service

This commit is contained in:
Balazs Toldi 2022-09-21 08:12:54 +02:00
parent 4a6d58301f
commit cee98fd0f4
Signed by: Bazsalanszky
GPG key ID: 6C7D440036F99D58
8 changed files with 90 additions and 4 deletions

View file

@ -73,6 +73,7 @@
<entry key="../../../../../layout/compose-model-1657532602169.xml" value="1.0" />
<entry key="../../../../../layout/compose-model-1657534975618.xml" value="0.33" />
<entry key="../../../../../layout/compose-model-1657549343896.xml" value="0.1" />
<entry key="../../../../../layout/compose-model-1662485842885.xml" value="0.11655405405405406" />
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.1" />
<entry key="app/src/main/res/drawable/forward.xml" value="0.1" />
<entry key="app/src/main/res/drawable/ic_launcher_adaptive_foreground.xml" value="0.1" />

View file

@ -0,0 +1,25 @@
package eu.toldi.balazs.caster.helpers
import android.media.VolumeProvider
import android.os.Parcel
import android.os.Parcelable
import androidx.media.VolumeProviderCompat
import eu.toldi.balazs.caster.ChromeCastHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class ChromecastVolumeProviderCompat(currentVolume: Float) : VolumeProviderCompat( VOLUME_CONTROL_ABSOLUTE,100,(currentVolume*100).toInt()) {
override fun onSetVolumeTo(volume: Int) {
GlobalScope.launch(Dispatchers.IO) {
ChromeCastHelper.setVolume(volume.toFloat() / 100.0f)
}
}
override fun onAdjustVolume(direction: Int) {
GlobalScope.launch(Dispatchers.IO) {
ChromeCastHelper.setVolume(ChromeCastHelper.chromeCast.status.volume.level + direction.toFloat()/1000.0f)
}
}
}

View file

@ -14,10 +14,12 @@ import android.support.v4.media.session.MediaSessionCompat
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.media.VolumeProviderCompat
import eu.toldi.balazs.caster.App.Companion.CHANNEL_ID
import eu.toldi.balazs.caster.ChromeCastHelper
import eu.toldi.balazs.caster.ChromecastManagerActivity
import eu.toldi.balazs.caster.R
import eu.toldi.balazs.caster.helpers.ChromecastVolumeProviderCompat
import eu.toldi.balazs.caster.model.SponsorBlock
import io.ktor.application.*
import io.ktor.features.*
@ -53,6 +55,7 @@ class ChromecastManagerService : Service() {
}
private val mMediaPlayer = MediaPlayer()
private lateinit var mVolmeProvider : VolumeProviderCompat;
private lateinit var mSession: MediaSessionCompat
private lateinit var mController: MediaControllerCompat
private lateinit var pendingIntent : PendingIntent
@ -163,7 +166,10 @@ class ChromecastManagerService : Service() {
"${chromeCast.name} is ready for casting"
}
mediaStatus = ChromeCastHelper.fetchMediaStatus()
Log.e("Caster_Service","Sb enabled: "+prefs.getBoolean("sponsorblock_enabled",false).toString()+ " yt: ${yt_video.toString()}")
if(mediaStatus != null) {
mVolmeProvider = ChromecastVolumeProviderCompat(mediaStatus!!.volume.level)
mSession.setPlaybackToRemote(mVolmeProvider)
}
if(prefs.getBoolean("sponsorblock_enabled",false) && yt_video != null){
try {
if(yt_video!!.url.startsWith("https://youtu.be/")){
@ -240,7 +246,7 @@ class ChromecastManagerService : Service() {
notification = if(mediaStatus!!.playerState == MediaStatus.PlayerState.PLAYING) {
NotificationCompat.Builder(baseContext, CHANNEL_ID)
.setContentTitle(status_message)
.setSmallIcon(R.drawable.ic_caster_logo)
.setSmallIcon(R.drawable.ic_caster_new_monochrome_notification)
.setContentText(mediaStatus!!.media.metadata[Media.METADATA_TITLE].toString())
.addAction(
generateAction(
@ -273,7 +279,7 @@ class ChromecastManagerService : Service() {
} else {
NotificationCompat.Builder(baseContext, CHANNEL_ID)
.setContentTitle(status_message)
.setSmallIcon(R.drawable.ic_caster_logo)
.setSmallIcon(R.drawable.ic_caster_new_monochrome_notification)
.setContentText(mediaStatus!!.media.metadata[Media.METADATA_TITLE].toString())
.addAction(
generateAction(
@ -311,7 +317,7 @@ class ChromecastManagerService : Service() {
} else {
notification = NotificationCompat.Builder(baseContext, CHANNEL_ID)
.setContentTitle(status_message)
.setSmallIcon(R.drawable.ic_caster_logo)
.setSmallIcon(R.drawable.ic_caster_new_monochrome_notification)
.setContentIntent(pendingIntent).build()
withContext(Dispatchers.Main) {

View file

@ -0,0 +1,54 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF">
<group android:scaleX="0.04043956"
android:scaleY="0.04043956"
android:translateX="1.8901099"
android:translateY="2.3113554">
<path
android:pathData="M125.67,37.64h361.61v220.93h-361.61z"
android:strokeLineJoin="round"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M217.94,298.36h177.75v54.12h-177.75z"
android:strokeLineJoin="round"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M282.15,261.97h48.97v36.25h-48.97z"
android:strokeLineJoin="round"
android:strokeWidth="20"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="m27.62,354.13a63.86,63.86 0,0 1,82.15 3.48,63.86 63.86,0 0,1 10.64,81.53"
android:strokeLineJoin="round"
android:strokeWidth="25"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="m34.3,401.3a27.68,30.75 90,0 1,39.56 1.51,27.68 30.75,90 0,1 5.12,35.34"
android:strokeLineJoin="round"
android:strokeWidth="25"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="m31.57,307.13a97.94,97.94 45,0 1,125.99 5.33,97.94 97.94,0 0,1 16.32,125.04"
android:strokeLineJoin="round"
android:strokeWidth="25"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</group>
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B