-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some cleanup and enhancements to the Native Audio implementation (#75)
* Drops MediaSessionConnector & Subclasses PlayerNotificationManager for improved controls * Removes unnecessary exo player packages * Refactors Podcast bridge interface to handle JSON encoded messages & bug fixes
- Loading branch information
Showing
4 changed files
with
150 additions
and
91 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/to/dev/dev_android/media/PodcastPlayerNotificationManager.kt
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package to.dev.dev_android.media | ||
|
||
import android.content.Context | ||
import androidx.annotation.IntegerRes | ||
import com.google.android.exoplayer2.Player | ||
import com.google.android.exoplayer2.ui.PlayerNotificationManager | ||
import com.google.android.exoplayer2.util.NotificationUtil | ||
import java.util.* | ||
|
||
/* | ||
* This subclass of PlayerNotificationManager customizes the controls available in the | ||
* notification by overriding the getActions method. | ||
*/ | ||
class PodcastPlayerNotificationManager( | ||
context: Context, | ||
channelId: String, | ||
notificationId: Int, | ||
mediaDescriptionAdapter: MediaDescriptionAdapter, | ||
playerNotificationManager: NotificationListener | ||
): PlayerNotificationManager( | ||
context, | ||
channelId, | ||
notificationId, | ||
mediaDescriptionAdapter, | ||
playerNotificationManager) { | ||
|
||
companion object { | ||
fun createWithNotificationChannel( | ||
context: Context, | ||
channelId: String, | ||
channelName: Int, | ||
channelDescription: Int, | ||
notificationId: Int, | ||
mediaDescriptionAdapter: MediaDescriptionAdapter, | ||
playerNotificationManager: NotificationListener): PodcastPlayerNotificationManager { | ||
|
||
NotificationUtil.createNotificationChannel( | ||
context, channelId, channelName, channelDescription, NotificationUtil.IMPORTANCE_LOW | ||
) | ||
return PodcastPlayerNotificationManager( | ||
context, channelId, notificationId, mediaDescriptionAdapter, playerNotificationManager | ||
) | ||
} | ||
} | ||
|
||
override fun getActions(player: Player): List<String> { | ||
var stringActions: List<String> = ArrayList() | ||
stringActions += ACTION_REWIND | ||
stringActions += if (shouldShowPauseButton(player)) { | ||
ACTION_PAUSE | ||
} else { | ||
ACTION_PLAY | ||
} | ||
stringActions += ACTION_FAST_FORWARD | ||
return stringActions | ||
} | ||
|
||
private fun shouldShowPauseButton(player: Player): Boolean { | ||
val state = player.playbackState | ||
return state != Player.STATE_ENDED && state != Player.STATE_IDLE && player.playWhenReady | ||
} | ||
} |
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