@@ -60,6 +60,7 @@ import androidx.compose.material3.Checkbox
6060import androidx.compose.material3.Icon
6161import androidx.compose.material3.MaterialTheme
6262import androidx.compose.material3.RadioButton
63+ import androidx.compose.material3.Slider
6364import androidx.compose.material3.Surface
6465import androidx.compose.material3.Text
6566import androidx.compose.runtime.Composable
@@ -107,14 +108,15 @@ class MainActivity : ComponentActivity() {
107108 private lateinit var serviceIntent: Intent
108109 private var isMMapSupported: Boolean = false
109110 private var isOffloadSupported: Boolean = false
111+ private var sampleRate: Int = 48000 ;
110112
111113 override fun onCreate (savedInstanceState : Bundle ? ) {
112114 super .onCreate(savedInstanceState)
113115 setUpPowerPlayAudioPlayer()
114116
115117 val format = AudioFormat .Builder ()
116118 .setEncoding(AudioFormat .ENCODING_PCM_FLOAT )
117- .setSampleRate(48000 )
119+ .setSampleRate(sampleRate )
118120 .setChannelMask(AudioFormat .CHANNEL_OUT_STEREO )
119121 .build()
120122
@@ -171,6 +173,8 @@ class MainActivity : ComponentActivity() {
171173 val isPlaying = remember {
172174 mutableStateOf(false )
173175 }
176+ var sliderPosition by remember { mutableFloatStateOf(0f ) }
177+
174178
175179 LaunchedEffect (pagerState) {
176180 snapshotFlow { pagerState.currentPage }
@@ -240,13 +244,6 @@ class MainActivity : ComponentActivity() {
240244 }
241245 }
242246 Spacer (modifier = Modifier .height(54 .dp))
243- Column (
244- modifier = Modifier
245- .fillMaxWidth()
246- .padding(horizontal = 32 .dp),
247- ) {
248- }
249- Spacer (modifier = Modifier .height(8 .dp))
250247 Text (
251248 " Performance Modes"
252249 )
@@ -335,6 +332,47 @@ class MainActivity : ComponentActivity() {
335332 modifier = Modifier .padding(start = 8 .dp)
336333 )
337334 }
335+ if (offload.intValue == 3 ) {
336+ Column (
337+ modifier = Modifier
338+ .fillMaxWidth()
339+ .padding(horizontal = 32 .dp)
340+ .padding(top = 8 .dp),
341+ horizontalAlignment = Alignment .CenterHorizontally
342+ ) {
343+ val requestedFrames = remember { mutableIntStateOf(0 ) }
344+ val actualFrames = remember { mutableIntStateOf(0 ) }
345+
346+ Slider (
347+ value = sliderPosition,
348+ onValueChange = { newValue ->
349+ sliderPosition = newValue
350+ requestedFrames.intValue = sliderPosition.toInt()
351+ },
352+ onValueChangeFinished = {
353+ requestedFrames.intValue = sliderPosition.toInt()
354+ actualFrames.value = player.setBufferSizeInFrames(requestedFrames.intValue)
355+ },
356+ valueRange = 0f .. player.getBufferCapacityInFrames().toFloat(),
357+ )
358+
359+ val actualSeconds = actualFrames.value.toDouble() / sampleRate
360+ val formattedSeconds = " %.3f" .format(actualSeconds)
361+
362+ Column (horizontalAlignment = Alignment .CenterHorizontally ) {
363+ Text (
364+ text = " Requested: ${requestedFrames.intValue} Frames (BufferSize)" ,
365+ color = Color .Black ,
366+ style = MaterialTheme .typography.bodySmall
367+ )
368+ Text (
369+ text = " Actual: ${actualFrames.value} Frames ($formattedSeconds seconds)" ,
370+ color = Color .Black ,
371+ style = MaterialTheme .typography.bodySmall
372+ )
373+ }
374+ }
375+ }
338376 Spacer (modifier = Modifier .height(24 .dp))
339377 Row (
340378 horizontalArrangement = Arrangement .SpaceEvenly ,
0 commit comments