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
class SimplePlaybackTransportControlGlue(...) { | |
... | |
override fun onPlayCompleted() { | |
super.onPlayCompleted() | |
playbackState = PlaybackStateCompat.STATE_NONE | |
} | |
fun onStartBuffering() { | |
playbackState = PlaybackStateCompat.STATE_BUFFERING | |
} |
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
private fun invalidatePlaybackState() { | |
val playbackStateBuilder = PlaybackStateCompat.Builder() | |
.setState(playbackState, currentPosition, 1.0F) | |
.setActions(mediaSessionSupportedActions()) | |
.setBufferedPosition(bufferedPosition) | |
mediaSession.setPlaybackState(playbackStateBuilder.build()) | |
} |
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
private var playbackState: Int = -1 | |
set(value) { | |
if (field != value) { | |
field = value | |
invalidatePlaybackState() // We'll cover this function later on. | |
} | |
} |
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
fun mediaSessionSupportedActions(): Long { | |
return PlaybackStateCompat.ACTION_PAUSE xor | |
PlaybackStateCompat.ACTION_PLAY xor | |
PlaybackStateCompat.ACTION_PLAY_PAUSE xor | |
PlaybackStateCompat.ACTION_REWIND xor | |
PlaybackStateCompat.ACTION_FAST_FORWARD xor | |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT xor | |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | |
} |
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
public final static int STATE_NONE = 0; | |
public final static int STATE_STOPPED = 1; | |
public final static int STATE_PAUSED = 2; | |
public final static int STATE_PLAYING = 3; | |
public final static int STATE_FAST_FORWARDING = 4; | |
public final static int STATE_REWINDING = 5; | |
public final static int STATE_BUFFERING = 6; | |
public final static int STATE_ERROR = 7; | |
public final static int STATE_CONNECTING = 8; | |
public final static int STATE_SKIPPING_TO_PREVIOUS = 9; |
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
private inner class SimpleMediaSessionCallback : MediaSessionCompat.Callback() { | |
override fun onPlay() = this@SimplePlaybackTransportControlGlue.play() | |
override fun onPause() = this@SimplePlaybackTransportControlGlue.pause() | |
override fun onSkipToNext() = this@SimplePlaybackTransportControlGlue.next() | |
override fun onSkipToPrevious() = this@SimplePlaybackTransportControlGlue.previous() | |
override fun onRewind() = this@SimplePlaybackTransportControlGlue.rewind() | |
override fun onFastForward() = this@SimplePlaybackTransportControlGlue.fastForward() | |
override fun onSeekTo(pos: Long) = this@SimplePlaybackTransportControlGlue.seekTo(pos) | |
} |
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
class SimplePlaybackTransportControlGlue( | |
context: Context, | |
playerAdapter: MediaPlayerAdapter, | |
) : PlaybackTransportControlGlue<MediaPlayerAdapter>(context, playerAdapter) { | |
private val mediaSession = MediaSessionCompat(context, "VideoPlayback") | |
init { | |
mediaSession.setCallback(SimpleMediaSessionCallback()) | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | |
... | |
<uses-permission android:name="com.amazon.permission.media.session.voicecommandcontrol" /> | |
... | |
<application> | |
<meta-data | |
android:name="com.amazon.voice.supports_background_media_session" | |
android:value="true" /> | |
<application/> |
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
<style name="Widget.Leanback.Headers.VerticalGridView"> | |
<item name="android:background">?attr/defaultBrandColor</item> | |
<item name="android:paddingStart">?attr/browsePaddingStart</item> | |
<item name="focusOutFront">true</item> | |
<item name="focusOutEnd">true</item> | |
<item name="android:verticalSpacing">@dimen/lb_browse_headers_vertical_spacing</item> | |
<item name="android:focusable">true</item> | |
<item name="android:focusableInTouchMode">true</item> | |
<item name="android:contentDescription">@string/lb_navigation_menu_contentDescription</item> | |
</style> |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60f, resources.displayMetrics).toInt() | |
val headerPresenterSelector = headersSupportFragment.presenterSelector as ClassPresenterSelector | |
headerPresenterSelector | |
.addClassPresenter(IconSectionRow::class.java, IconSectionPresenter()) | |
.addClassPresenter(DividerRow::class.java, SpaceDividerPresenter(height)) | |
} |
NewerOlder