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 updateAudioDeviceState() { | |
// Check if any Bluetooth headset is connected. The internal BT state will | |
// change accordingly. | |
if (bluetoothManager.state == State.HEADSET_AVAILABLE || bluetoothManager.state == State.HEADSET_UNAVAILABLE || bluetoothManager.state == State.SCO_DISCONNECTING) { | |
bluetoothManager.updateDevice() | |
} | |
// Update the set of available audio devices. | |
val newAudioDevices: MutableSet<AudioDevice> = | |
HashSet() |
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
# A shell script to launch scrcpy automatically when a device is connected | |
# Device name selection is based on lines from `adb devices -l`. | |
# Script takes a single argument to match any of these lines. | |
# First matched devices' serial number is used for scrcpy device serial number. | |
while true | |
do | |
# Try to start scrcpy | |
scrcpy -s $(adb devices -l | awk -v j=$1 'index($0, j);' | awk '{print $1}') | |
# If scrcpy was closed by user, do not restart until device is replugged in. |
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
// Simply put the Demo composable in a Compose tree and observe the logs | |
// Focus on how dependency changes affect the recomposition. | |
// How does Ambient work? | |
// When basic callbacks fire: onCommit, launchInComposition, onActive, remember | |
@Composable | |
fun Demo() { | |
var textCounter by mutableStateOf(0) | |
Column { |
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
@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 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
@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)) |
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 MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
ComposeTubeTheme { | |
var source by remember { | |
mutableStateOf( | |
"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
@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() | |
} |
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 PlayerController( | |
private val context: Context | |
) { | |
private val exoPlayer by lazy { | |
SimpleExoPlayer.Builder(context).build() | |
} | |
fun prepare(sourceUrl: String) { | |
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(context, |
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
@Composable | |
fun PlayerSurface() { | |
val playerController = PlayerControllerAmbient.current | |
AndroidView(resId = R.layout.surface) { | |
val exoPlayerView = it.findViewById<PlayerView>(R.id.player_view) | |
playerController.setPlayerView(exoPlayerView) | |
} | |
} |