Skip to content

Instantly share code, notes, and snippets.

View halilozercan's full-sized avatar
🏛️
Learning

Halil Ozercan halilozercan

🏛️
Learning
View GitHub Profile
@Composable
fun <T: Comparable<T>> SlideInOutLayout(
targetState: T,
modifier: Modifier = Modifier,
animationSpec: FiniteAnimationSpec<Float> = tween(),
content: @Composable (T) -> Unit
) {
val items = remember { mutableStateListOf<CrossSlideAnimationItem<T>>() }
val transitionState = remember { MutableTransitionState(targetState) }
val targetChanged = (targetState != transitionState.targetState)
@Composable
fun VideoPlayer() {
// This is the official way to access current context from Composable functions
val context = ContextAmbient.current
// Do not recreate the player everytime this Composable commits
val exoPlayer = remember {
SimpleExoPlayer.Builder(context).build().apply {
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(context,
Util.getUserAgent(context, context.packageName))
@Composable
fun VideoPlayer(sourceUrl: String) {
// This is the official way to access current context from Composable functions
val context = LocalContext.current
// Do not recreate the player everytime this Composable commits
val exoPlayer = remember {
SimpleExoPlayer.Builder(context).build()
}
@Composable
fun VideoPlayer() {
// This is the official way to access current context from Composable functions
val context = LocalContext.current
// Do not recreate the player everytime this Composable commits
val exoPlayer = remember(context) {
SimpleExoPlayer.Builder(context).build().apply {
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(context,
Util.getUserAgent(context, context.packageName))
/**
* This interface marks the class for use of `Rizalt` library.
*/
interface Rizalt<P: Parcelable>
/**
* Creates a unique request key for given Fragment class. Key can be left empty
* to create a default instance.
*/
fun <T, P: Parcelable> KClass<T>.getRequestKeyNameFor(key: String): String where T: Fragment, T: Rizalt<P> {
> Task :app:compileDebugKotlin FAILED
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
object MediaControlButtons {
private val HIDDEN = "hidden"
private val VISIBLE = "visible"
private val alpha = FloatPropKey()
private val transitionDef by lazy {
transitionDefinition {
state(HIDDEN) {
this[alpha] = 0f
@Composable
fun MediaControlButtons(modifier: Modifier = Modifier) {
val controller = PlayerControllerAmbient.current
Stack(modifier = Modifier + modifier) {
Box(modifier = Modifier.gravity(Alignment.Center).fillMaxSize().clickable(indication = null) {
controller.setControlsVisible(false)
})
PlayPauseButton(modifier = Modifier.gravity(Alignment.Center))
@Composable
fun PlayPauseButton(modifier: Modifier = Modifier) {
val controller = PlayerControllerAmbient.current
val isPlaying by controller.isPlaying.collectAsState()
val playbackState by controller.playbackState.collectAsState()
IconButton(
onClick = { controller.playPause() },
modifier = Modifier + modifier
private val _isPlaying = MutableStateFlow(true)
val isPlaying: StateFlow<Boolean> = _isPlaying
private val _playbackState = MutableStateFlow(ExoPlayer.STATE_IDLE)
val playbackState: StateFlow<Int> = _playbackState
private val exoPlayer by lazy {
SimpleExoPlayer.Builder(context).build().apply {
addListener(object: Player.EventListener {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {