-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
945789a
commit 91b858e
Showing
10 changed files
with
146 additions
and
8 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
23 changes: 23 additions & 0 deletions
23
haze/src/commonTest/kotlin/dev/chrisbanes/haze/HazeTest.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,23 @@ | ||
// Copyright 2024, Christopher Banes and the Haze project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dev.chrisbanes.haze | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isFalse | ||
import kotlin.test.Test | ||
|
||
class HazeTest { | ||
|
||
@Test | ||
fun assertNoLogging() { | ||
var blockCalled = false | ||
|
||
log("Foo") { | ||
blockCalled = true | ||
"foo" | ||
} | ||
|
||
assertThat(blockCalled).isFalse() | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
sample/android/src/main/kotlin/dev/chrisbanes/haze/sample/android/ExoPlayerSample.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,80 @@ | ||
// Copyright 2024, Christopher Banes and the Haze project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dev.chrisbanes.haze.sample.android | ||
|
||
import android.view.LayoutInflater | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.media3.common.MediaItem | ||
import androidx.media3.exoplayer.ExoPlayer | ||
import androidx.media3.ui.PlayerView | ||
import dev.chrisbanes.haze.HazeState | ||
import dev.chrisbanes.haze.haze | ||
import dev.chrisbanes.haze.hazeChild | ||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi | ||
import dev.chrisbanes.haze.materials.HazeMaterials | ||
import dev.chrisbanes.haze.sample.Navigator | ||
|
||
@OptIn(ExperimentalHazeMaterialsApi::class) | ||
@Composable | ||
fun ExoPlayerSample(navigator: Navigator) { | ||
val hazeState = remember { HazeState() } | ||
|
||
val context = LocalContext.current | ||
|
||
val exoPlayer = remember(context) { | ||
ExoPlayer.Builder(context).build() | ||
} | ||
|
||
DisposableEffect(Unit) { | ||
exoPlayer.setMediaItem(MediaItem.fromUri(BIG_BUCK_BUNNY)) | ||
exoPlayer.prepare() | ||
exoPlayer.play() | ||
|
||
onDispose { exoPlayer.release() } | ||
} | ||
|
||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.aspectRatio(16 / 9f), | ||
) { | ||
AndroidView( | ||
factory = { ctx -> | ||
// For Haze to work with video players, they need to be configured to use a TextureView. | ||
// For ExoPlayer that needs to be done via a layout file. | ||
val view = LayoutInflater.from(ctx) | ||
.inflate(R.layout.exoplayer, null) as PlayerView | ||
view.apply { | ||
player = exoPlayer | ||
} | ||
}, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.haze(hazeState), | ||
) | ||
|
||
Spacer( | ||
Modifier | ||
.fillMaxSize(0.5f) | ||
.align(Alignment.Center) | ||
.clip(MaterialTheme.shapes.large) | ||
.hazeChild(hazeState, HazeMaterials.ultraThin()), | ||
) | ||
} | ||
} | ||
|
||
private const val BIG_BUCK_BUNNY = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.media3.ui.PlayerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:surface_type="texture_view" /> |
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