Signed-off-by: Toldi Balázs Ádám <balazs@toldi.eu>
This commit is contained in:
parent
0943680271
commit
5672eab2bd
3 changed files with 32 additions and 10 deletions
|
@ -66,7 +66,11 @@ object ChromeCastHelper {
|
|||
if (mediaStatus != null) {
|
||||
try {
|
||||
withContext(IO) {
|
||||
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) {
|
||||
if(f >= 0.0f && f <= 1.0f) {
|
||||
try {
|
||||
chromeCast.setVolume(f)
|
||||
}catch (e:Exception) {
|
||||
Log.e(null,e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,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 = stringResource(id = R.string.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)
|
||||
|
@ -175,7 +175,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
|
||||
IconButton(onClick = {
|
||||
if (mediaStatus != null) {
|
||||
viewModel.seek(chromeCast.mediaStatus.currentTime - 10)
|
||||
viewModel.seek(mediaStatus.currentTime - 10)
|
||||
}
|
||||
}, enabled = mediaStatus != null) {
|
||||
Icon(
|
||||
|
@ -222,8 +222,8 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
}
|
||||
|
||||
IconButton(onClick = {
|
||||
if (chromeCast.mediaStatus != null) {
|
||||
viewModel.seek(chromeCast.mediaStatus.currentTime + 10)
|
||||
if (mediaStatus != null) {
|
||||
viewModel.seek(mediaStatus.currentTime + 10)
|
||||
}
|
||||
}, enabled = mediaStatus != null) {
|
||||
Icon(
|
||||
|
@ -272,7 +272,7 @@ class ChromecastManagerActivity : ComponentActivity() {
|
|||
}
|
||||
// val viewModel = ViewModelProvider(this).get(ChromecastManageViewmodel::class.java)
|
||||
PlayBackControl()
|
||||
Text(text = stringResource(id = R.string.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 })
|
||||
}
|
||||
|
@ -282,12 +282,12 @@ 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.setVolume(chromeCast.status.volume.level - 0.05f)
|
||||
viewModel.decreaseVolume()
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue