Compare commits
2 commits
4c88992e5f
...
5672eab2bd
Author | SHA1 | Date | |
---|---|---|---|
5672eab2bd | |||
0943680271 |
8 changed files with 126 additions and 45 deletions
37
.idea/deploymentTargetDropDown.xml
Normal file
37
.idea/deploymentTargetDropDown.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_3a_XL_API_30.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2021-12-05T17:39:35.648801Z" />
|
||||
<targetsSelectedWithDialog>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_3a_XL_API_30.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Android_TV_720p_API_30.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetsSelectedWithDialog>
|
||||
</component>
|
||||
</project>
|
|
@ -31,6 +31,8 @@
|
|||
<entry key="../../../../../layout/compose-model-1638180237267.xml" value="0.3095439189189189" />
|
||||
<entry key="../../../../../layout/compose-model-1638183069943.xml" value="0.33" />
|
||||
<entry key="../../../../../layout/compose-model-1638183903572.xml" value="0.48703703703703705" />
|
||||
<entry key="../../../../../layout/compose-model-1638732634308.xml" value="0.29814814814814816" />
|
||||
<entry key="../../../../../layout/compose-model-1638733042047.xml" value="0.29814814814814816" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
@ -66,7 +66,11 @@ object ChromeCastHelper {
|
|||
if (mediaStatus != null) {
|
||||
try {
|
||||
withContext(IO) {
|
||||
chromeCast.seek(d * mediaStatus.media.duration)
|
||||
try {
|
||||
chromeCast.seek(d * mediaStatus.media.duration)
|
||||
}catch (e:Exception) {
|
||||
Log.e(null,e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(null, e.stackTraceToString())
|
||||
|
@ -96,7 +100,13 @@ object ChromeCastHelper {
|
|||
|
||||
suspend fun setVolume(f: Float) {
|
||||
withContext(IO) {
|
||||
chromeCast.setVolume(f)
|
||||
if(f >= 0.0f && f <= 1.0f) {
|
||||
try {
|
||||
chromeCast.setVolume(f)
|
||||
}catch (e:Exception) {
|
||||
Log.e(null,e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import androidx.compose.material.icons.filled.*
|
|||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -77,7 +78,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
onValueChange = {
|
||||
text = it
|
||||
},
|
||||
label = { Text("Cast URL") },
|
||||
label = { Text(stringResource(id = R.string.cast_url)) },
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
)
|
||||
var castEnabled by remember { mutableStateOf(true) }
|
||||
|
@ -91,7 +92,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
},
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
) {
|
||||
Text(text = "Cast")
|
||||
Text(text = stringResource(id = R.string.cast))
|
||||
}
|
||||
if (castEnabled.not()) {
|
||||
CircularProgressIndicator()
|
||||
|
@ -102,7 +103,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
if (mediaStatus != null) {
|
||||
val nowPlaying =
|
||||
if (mediaStatus.media.metadata != null) mediaStatus.media.metadata[Media.METADATA_TITLE] else ""
|
||||
Text(text = "Now playing: $nowPlaying")
|
||||
Text(text = stringResource(id = R.string.now_playing) + ": $nowPlaying")
|
||||
var sliderPosition by remember { mutableStateOf(0.0f) }
|
||||
var sliderMoving by remember { mutableStateOf(false) }
|
||||
if (!sliderMoving)
|
||||
|
@ -153,7 +154,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
IconButton(onClick = { finish() }) {
|
||||
Icon(
|
||||
Icons.Filled.ArrowBack,
|
||||
contentDescription = "Back"
|
||||
contentDescription = stringResource(id = R.string.back)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -174,12 +175,12 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
|
||||
IconButton(onClick = {
|
||||
if (mediaStatus != null) {
|
||||
viewModel.seek(chromeCast.mediaStatus.currentTime - 10)
|
||||
viewModel.seek(mediaStatus.currentTime - 10)
|
||||
}
|
||||
}, enabled = mediaStatus != null) {
|
||||
Icon(
|
||||
Icons.Filled.FastRewind,
|
||||
contentDescription = "FastRewind"
|
||||
contentDescription = stringResource(id = R.string.rewind)
|
||||
)
|
||||
}
|
||||
IconButton(onClick = {
|
||||
|
@ -197,15 +198,15 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
when {
|
||||
mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.PAUSED -> Icon(
|
||||
Icons.Filled.PlayArrow,
|
||||
contentDescription = "Resume"
|
||||
contentDescription = stringResource(id = R.string.resume)
|
||||
)
|
||||
mediaStatus.playerState == MediaStatus.PlayerState.PLAYING -> Icon(
|
||||
Icons.Filled.Pause,
|
||||
contentDescription = "Pause"
|
||||
contentDescription = stringResource(id = R.string.pause)
|
||||
)
|
||||
else -> Icon(
|
||||
Icons.Filled.PlayArrow,
|
||||
contentDescription = "Resume"
|
||||
contentDescription = stringResource(id = R.string.resume)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -216,18 +217,18 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
}, enabled = mediaStatus != null) {
|
||||
Icon(
|
||||
Icons.Filled.Stop,
|
||||
contentDescription = "Stop"
|
||||
contentDescription = stringResource(id = R.string.stop)
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(onClick = {
|
||||
if (chromeCast.mediaStatus != null) {
|
||||
viewModel.seek(chromeCast.mediaStatus.currentTime + 10)
|
||||
if (mediaStatus != null) {
|
||||
viewModel.seek(mediaStatus.currentTime + 10)
|
||||
}
|
||||
}, enabled = mediaStatus != null) {
|
||||
Icon(
|
||||
Icons.Filled.FastForward,
|
||||
contentDescription = "FastForward"
|
||||
contentDescription = stringResource(id = R.string.fastforward)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -260,18 +261,18 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
onValueChange = {
|
||||
text = it
|
||||
},
|
||||
label = { Text("Cast URL") },
|
||||
label = { Text(stringResource(id = R.string.cast_url)) },
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
)
|
||||
Button(
|
||||
onClick = {},
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
) {
|
||||
Text(text = "Cast")
|
||||
Text(text = stringResource(id = R.string.cast))
|
||||
}
|
||||
// val viewModel = ViewModelProvider(this).get(ChromecastManageViewmodel::class.java)
|
||||
PlayBackControl()
|
||||
Text(text = "Now playing: Some video")
|
||||
Text(text = stringResource(id = R.string.now_playing) + ": Some video")
|
||||
var sliderPosition by remember { mutableStateOf(0f) }
|
||||
Slider(value = sliderPosition, onValueChange = { sliderPosition = it })
|
||||
}
|
||||
|
@ -281,13 +282,13 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
viewModel.setVolume(chromeCast.status.volume.level + 0.05f)
|
||||
viewModel.increaseVolume()
|
||||
|
||||
return true
|
||||
}
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
viewModel.decreaseVolume()
|
||||
|
||||
viewModel.setVolume(chromeCast.status.volume.level - 0.05f)
|
||||
|
||||
return true
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.compose.runtime.*
|
|||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
@ -70,13 +71,13 @@ class MainActivity : ComponentActivity() {
|
|||
) {
|
||||
item {
|
||||
if (chromeCasts.isNotEmpty())
|
||||
Text(text = "Available chromecasts:")
|
||||
Text(text = stringResource(id = R.string.available_chromecasts))
|
||||
else {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("Looking for Chromecasts on your network...")
|
||||
Text(stringResource(id = R.string.looking_for_devices))
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +99,7 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
AlertDialog(onDismissRequest = dismiss,
|
||||
title = {
|
||||
Text(text = "Add Chromecast")
|
||||
Text(text = stringResource(id = R.string.add_chromecast))
|
||||
},
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
|
@ -106,7 +107,7 @@ class MainActivity : ComponentActivity() {
|
|||
onValueChange = {
|
||||
ipaddress = it
|
||||
},
|
||||
label = { Text("IP address of the chromecast") },
|
||||
label = { Text(stringResource(id = R.string.ip_address)) },
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
)
|
||||
}, buttons = {
|
||||
|
@ -121,10 +122,10 @@ class MainActivity : ComponentActivity() {
|
|||
},
|
||||
modifier = Modifier.padding(all = 8.dp)
|
||||
) {
|
||||
Text(text = "Add Chromecast")
|
||||
Text(text = stringResource(id = R.string.add_chromecast))
|
||||
}
|
||||
Button(onClick = dismiss, modifier = Modifier.padding(all = 8.dp)) {
|
||||
Text("Cancel")
|
||||
Text(stringResource(id = R.string.cancel))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -161,14 +162,14 @@ class MainActivity : ComponentActivity() {
|
|||
IconButton(onClick = refresh) {
|
||||
Icon(
|
||||
Icons.Filled.Refresh,
|
||||
contentDescription = "Refresh"
|
||||
contentDescription = stringResource(id = R.string.refresh)
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(onClick = add) {
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
contentDescription = "Add"
|
||||
contentDescription = stringResource(id = R.string.add_chromecast)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@ import android.os.Bundle
|
|||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
|
@ -73,7 +70,16 @@ class ShareRecieverActivity : ComponentActivity() {
|
|||
) {
|
||||
item {
|
||||
if (chromeCasts.isNotEmpty())
|
||||
Text(text = "Available chromecasts:")
|
||||
Text(text = stringResource(id = R.string.available_chromecasts))
|
||||
else {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(stringResource(id = R.string.looking_for_devices))
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
items(chromeCasts.size) { index ->
|
||||
showChromeCastButton(
|
||||
|
@ -116,7 +122,11 @@ class ShareRecieverActivity : ComponentActivity() {
|
|||
modifier = Modifier.padding(5.dp),
|
||||
enabled = enabled
|
||||
) {
|
||||
Text(text = chromeCast.model)
|
||||
when {
|
||||
chromeCast.title != null -> Text(text = chromeCast.title)
|
||||
chromeCast.name != null -> Text(text = chromeCast.name)
|
||||
else -> Text(text = chromeCast.address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,16 +141,7 @@ class ShareRecieverActivity : ComponentActivity() {
|
|||
IconButton(onClick = refresh) {
|
||||
Icon(
|
||||
Icons.Filled.Refresh,
|
||||
contentDescription = "Refresh"
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(onClick = {
|
||||
|
||||
}) {
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
contentDescription = "Add"
|
||||
contentDescription = stringResource(id = R.string.refresh)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,4 +83,16 @@ class ChromecastManageViewmodel : ViewModel() {
|
|||
ChromeCastHelper.setVolume(f)
|
||||
}
|
||||
}
|
||||
|
||||
fun increaseVolume(){
|
||||
viewModelScope.launch(IO) {
|
||||
setVolume(chromeCast.status.volume.level + 0.05f)
|
||||
}
|
||||
}
|
||||
|
||||
fun decreaseVolume(){
|
||||
viewModelScope.launch(IO) {
|
||||
setVolume(chromeCast.status.volume.level - 0.05f)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,4 +2,21 @@
|
|||
<string name="app_name">Caster</string>
|
||||
<string name="title_activity_chromecast_manager">ChromecastManagerActivity</string>
|
||||
<string name="title_activity_share_reciever">Choose Chromecast</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
<string name="add_chromecast">Add Chromecast</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="ip_address">IP address of the Chromecast</string>
|
||||
<string name="available_chromecasts">Available Chromecasts:</string>
|
||||
<string name="looking_for_devices">Looking for Chromecasts on your network...</string>
|
||||
<string name="cast">Cast</string>
|
||||
<string name="stop">Stop</string>
|
||||
<string name="pause">Pause</string>
|
||||
<string name="resume">Resume</string>
|
||||
<string name="play">Play</string>
|
||||
<string name="fastforward">Fast Forward</string>
|
||||
<string name="rewind">Rewind</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="now_playing">Now playing</string>
|
||||
<string name="cast_url">Cast URL</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in a new issue