This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 BluetoothServiceListener : BluetoothProfile.ServiceListener { | |
// Called to notify the client when the proxy object has been connected to the service. | |
// Once we have the profile proxy object, we can use it to monitor the state of the | |
// connection and perform other operations that are relevant to the headset profile. | |
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) { | |
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { | |
return | |
} | |
// Android only supports one connected Bluetooth Headset at a time. | |
bluetoothHeadset = proxy as BluetoothHeadset |
This file contains hidden or 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
typealias OnAudioDeviceChanged = ( | |
selectedAudioDevice: AudioGenie.AudioDevice?, | |
availableAudioDevices: Set<AudioGenie.AudioDevice> | |
) -> Unit | |
val newAudioDevices: MutableSet<AudioDevice> = HashSet() | |
if (bluetoothManager.state == State.SCO_CONNECTED || bluetoothManager.state == State.SCO_CONNECTING || bluetoothManager.state == State.HEADSET_AVAILABLE | |
) { | |
newAudioDevices.add(AudioDevice.BLUETOOTH) | |
} |
This file contains hidden or 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 startPictureInPicture(): Boolean { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && shouldStart) { | |
enterPictureInPictureMode( | |
PictureInPictureParams.Builder() | |
.setAspectRatio(…) // This has lower and upper limitations | |
.build() | |
) | |
return true | |
} | |
return false |