-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate to media1, link heart button to rating, profile pic fixes, no…
…n intrusive "Scrobbler disabled" message, session tag blocklist, secure fileprovider, fixes
- Loading branch information
1 parent
f0c2a81
commit adc3b53
Showing
29 changed files
with
606 additions
and
288 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,138 @@ | ||
package com.arn.scrobble | ||
|
||
import android.media.Rating | ||
import android.media.session.MediaController | ||
import android.support.v4.media.RatingCompat | ||
import android.support.v4.media.session.MediaControllerCompat | ||
|
||
object PlayerActions { | ||
|
||
fun List<MediaController>.skip() { | ||
class CustomRatingAction( | ||
val love: String, | ||
val unlove: String, | ||
val unlovedLabel: String? = null, | ||
val extrasIsArgs: Boolean = false | ||
) { | ||
init { | ||
if (love == unlove && unlovedLabel == null) | ||
throw IllegalArgumentException("Love and unlove actions must be different or unlovedLabel must be provided.") | ||
} | ||
} | ||
|
||
private val customRatingActions = mapOf( | ||
Stuff.PACKAGE_SPOTIFY to CustomRatingAction("ADD_TO", "CHECK_FILL"), | ||
Stuff.PACKAGE_SOUNDCLOUD to CustomRatingAction( | ||
"com.soundcloud.android.playback.action.ACTION_LIKE_TRACK", | ||
"com.soundcloud.android.playback.action.ACTION_LIKE_TRACK", | ||
"UnLikeRatingAction" | ||
), | ||
// Stuff.PACKAGE_OTO_MUSIC to CustomRatingAction( | ||
// "com.piyush.music.togglefavorite", | ||
// ), | ||
// Stuff.PACKAGE_PI_MUSIC to CustomRatingAction("action_favorite"), | ||
// Stuff.PACKAGE_SYMFONIUM to CustomRatingAction("symfonium.action_favorite"), | ||
Stuff.PACKAGE_PLEXAMP to CustomRatingAction( | ||
"tv.plex.labs.commonandroid.LOVE_TRACK", | ||
"tv.plex.labs.commonandroid.INDIFFERENCE_TRACK" | ||
), | ||
// Stuff.PACKAGE_BANDCAMP to CustomRatingAction( | ||
// "bandcamp_wishlist", | ||
// "bandcamp_wishlist", | ||
// true | ||
// ), | ||
) | ||
|
||
fun List<MediaControllerCompat>.skip() { | ||
forEach { | ||
it.transportControls.skipToNext() | ||
} | ||
} | ||
|
||
// doesn't work in spotify, s2 | ||
// works in youtube, yt music, poweramp, | ||
fun List<MediaController>.love() { | ||
// default rating tested working on: | ||
// youtube, yt music, poweramp, aimp, musicolet, neutron, doubletwist, playerpro, pandora, | ||
// amazon music, iHeartRadio, apple music, nyx, | ||
|
||
// rating does not heart individual tracks on: | ||
// bandcamp (wishists the entire album), tunein radio (favorites the station), | ||
|
||
// tested not working on: | ||
// vlc, bandcamp, retro, vocacolle, shuttle 2, blackplayer, phonograph, pulsar, foobar, | ||
// jet audio, n7, plex, subtracks, listenbrainz, radio japan, media monkey, omnia, | ||
// gonemad, deezer, tidal, podcast addict, gensokyo radio, gaana, wynk, jiosaavn, DIFM, | ||
// antenna pod, hiby, fiio, | ||
|
||
fun List<MediaControllerCompat>.love() { | ||
forEach { | ||
// custom actions override the rating | ||
if (it.packageName in customRatingActions) { | ||
val customAction = customRatingActions[it.packageName]!! | ||
|
||
val customActionFromPlayer = it.playbackState?.customActions?.find { | ||
it.action == customAction.love && | ||
(customAction.unlovedLabel == null || | ||
customAction.unlovedLabel == it.name) | ||
} ?: return@forEach | ||
|
||
val args = if (customRatingActions[it.packageName]!!.extrasIsArgs) | ||
customActionFromPlayer.extras | ||
else | ||
null | ||
|
||
it.transportControls.sendCustomAction(customActionFromPlayer, args) | ||
|
||
return@forEach | ||
} | ||
|
||
val rating = when (it.ratingType) { | ||
Rating.RATING_THUMB_UP_DOWN -> Rating.newThumbRating(true) | ||
Rating.RATING_HEART -> Rating.newHeartRating(true) | ||
Rating.RATING_3_STARS -> Rating.newStarRating( | ||
Rating.RATING_3_STARS, | ||
3F | ||
) | ||
|
||
Rating.RATING_4_STARS -> Rating.newStarRating(Rating.RATING_4_STARS, 4F) | ||
Rating.RATING_5_STARS -> Rating.newStarRating(Rating.RATING_5_STARS, 5F) | ||
Rating.RATING_PERCENTAGE -> Rating.newPercentageRating(100F) | ||
RatingCompat.RATING_THUMB_UP_DOWN -> | ||
RatingCompat.newThumbRating(true) | ||
|
||
RatingCompat.RATING_HEART -> | ||
RatingCompat.newHeartRating(true) | ||
|
||
RatingCompat.RATING_3_STARS -> | ||
RatingCompat.newStarRating(RatingCompat.RATING_3_STARS, 3F) | ||
|
||
RatingCompat.RATING_4_STARS -> | ||
RatingCompat.newStarRating(RatingCompat.RATING_4_STARS, 4F) | ||
|
||
RatingCompat.RATING_5_STARS -> | ||
RatingCompat.newStarRating(RatingCompat.RATING_5_STARS, 5F) | ||
|
||
RatingCompat.RATING_PERCENTAGE -> | ||
RatingCompat.newPercentageRating(100F) | ||
|
||
else -> null | ||
} | ||
if (rating != null) | ||
it.transportControls.setRating(rating) | ||
|
||
Stuff.logD { "Rating type for ${it.packageName}: ${it.ratingType}" } | ||
Stuff.log("Rating type: ${it.ratingType}") | ||
} | ||
} | ||
|
||
fun List<MediaController>.unlove() { | ||
fun List<MediaControllerCompat>.unlove() { | ||
forEach { | ||
val ratingSupported = it.ratingType != Rating.RATING_NONE | ||
// custom actions override the rating | ||
if (it.packageName in customRatingActions) { | ||
val customAction = customRatingActions[it.packageName]!! | ||
|
||
val customActionFromPlayer = it.playbackState?.customActions?.find { | ||
it.action == customAction.unlove && | ||
(customAction.unlovedLabel == null || | ||
customAction.unlovedLabel != it.name) | ||
} ?: return@forEach | ||
|
||
val args = if (customRatingActions[it.packageName]!!.extrasIsArgs) | ||
customActionFromPlayer.extras | ||
else | ||
null | ||
it.transportControls.sendCustomAction(customActionFromPlayer, args) | ||
|
||
return@forEach | ||
} | ||
|
||
val ratingSupported = it.ratingType != RatingCompat.RATING_NONE | ||
if (ratingSupported) | ||
it.transportControls.setRating(Rating.newUnratedRating(it.ratingType)) | ||
it.transportControls.setRating(RatingCompat.newUnratedRating(it.ratingType)) | ||
} | ||
} | ||
} |
Oops, something went wrong.