Skip to content

Commit

Permalink
Fix Player Pausing On Rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftWorksMC committed Mar 24, 2024
1 parent 41718d3 commit c86c3d2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
android:usesCleartextTraffic="true"
android:appCategory="audio"
android:enableOnBackInvokedCallback="true"

android:configChanges="keyboardHidden|orientation|screenSize"

tools:targetApi="31"
tools:ignore="UnusedAttribute">

Expand All @@ -45,6 +48,9 @@
android:exported="true"
android:theme="@style/Theme.MusicPlayer"
android:hardwareAccelerated="true"

android:configChanges="orientation|screenSize"

tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/com/craftworks/music/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
Expand Down Expand Up @@ -127,22 +126,23 @@ class MainActivity : ComponentActivity() {
}, 0, 1000)

WindowCompat.setDecorFitsSystemWindows(window, false)

val scaffoldState = BottomSheetScaffoldState(
bottomSheetState = SheetState(
skipPartiallyExpanded = false,
initialValue = SheetValue.PartiallyExpanded,
skipHiddenState = true
),
snackbarHostState = SnackbarHostState()
)
val snackbarHostState = SnackbarHostState()

setContent {

MusicPlayerTheme {

// BOTTOM NAVIGATION + NOW-PLAYING UI
navController = rememberNavController()
val scaffoldState = BottomSheetScaffoldState(
bottomSheetState = SheetState(
skipPartiallyExpanded = false,
density = LocalDensity.current, initialValue = SheetValue.PartiallyExpanded,
skipHiddenState = true
),
snackbarHostState = SnackbarHostState()
)


val bottomNavigationItems = listOf(
BottomNavigationItem(
Expand Down Expand Up @@ -203,7 +203,7 @@ class MainActivity : ComponentActivity() {
selectedItemIndex = index
navController.navigate(item.screenRoute)
coroutineScope.launch {
//scaffoldState.bottomSheetState.partialExpand()
scaffoldState.bottomSheetState.partialExpand()
} },
label = { Text(text = item.title) },
alwaysShowLabel = false,
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/com/craftworks/music/SongHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.annotation.OptIn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SheetValue
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -27,9 +25,6 @@ import com.craftworks.music.lyrics.getLyrics
import com.craftworks.music.providers.navidrome.markSongAsPlayed
import com.craftworks.music.providers.navidrome.useNavidromeServer
import com.craftworks.music.ui.bitmap
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.Calendar
import kotlin.math.abs

Expand Down Expand Up @@ -85,7 +80,6 @@ class SongHelper {
saveManager(context).loadSettings()
}

@kotlin.OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class)
fun playStream(context: Context, url: Uri, isRadio: Boolean ? = false) {
// Stop If It's Playing
if (player.isPlaying){
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/craftworks/music/ui/NowPlaying.kt
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fun NowPlayingContent(
@Composable
@Preview(showBackground = true)
fun LyricsView(isLandscape: Boolean = false) {
val topBottomFade = Brush.verticalGradient(0f to Color.Transparent, 0.25f to Color.Red, 0.85f to Color.Red, 1f to Color.Transparent)
val topBottomFade = Brush.verticalGradient(0f to Color.Transparent, 0.15f to Color.Red, 0.85f to Color.Red, 1f to Color.Transparent)
val state = rememberScrollState()
var currentLyricIndex by remember { mutableIntStateOf(0) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun NowPlayingPortraitCover (){
if (SongHelper.currentSong.isRadio == true)
it.split(" - ").last()
else
if (it.length > 24) it.substring(0, 21) + "..."
if (it.length > 21) it.substring(0, 18) + "..."
else it,
fontSize = MaterialTheme.typography.headlineMedium.fontSize,
fontWeight = FontWeight.SemiBold,
Expand All @@ -122,8 +122,8 @@ fun NowPlayingPortraitCover (){
Text(
text = //Limit the artist name length.
if (it.isBlank()) ""
else if (it.length > 24)
it.substring(0, 21) + "..." + "" + SongHelper.currentSong.year
else if (it.length > 20)
it.substring(0, 17) + "..." + "" + SongHelper.currentSong.year
else
it + "" + SongHelper.currentSong.year,
fontSize = MaterialTheme.typography.bodyLarge.fontSize,
Expand Down

0 comments on commit c86c3d2

Please sign in to comment.