Skip to content

Commit

Permalink
Merge pull request #89 from ZTFtrue/develope
Browse files Browse the repository at this point in the history
add feature and fix bugs
  • Loading branch information
ZTFtrue authored Nov 30, 2024
2 parents 4068466 + 31d5852 commit 23e2847
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 106 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ android {
applicationId = "com.ztftrue.music"
minSdk = 30
targetSdk = 35
versionCode = 41
versionName = "0.1.41"

versionCode = 42
versionName = "0.1.42"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/ztftrue/music/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.ztftrue.music.play.ACTION_IS_CONNECTED
import com.ztftrue.music.play.ACTION_PlayLIST_CHANGE
import com.ztftrue.music.play.ACTION_TRACKS_DELETE
import com.ztftrue.music.play.ACTION_WILL_DISCONNECTED
import com.ztftrue.music.play.EVENT_INPUT_FORTMAT_Change
import com.ztftrue.music.play.EVENT_MEDIA_ITEM_Change
import com.ztftrue.music.play.EVENT_SLEEP_TIME_Change
import com.ztftrue.music.play.EVENT_Visualization_Change
Expand Down Expand Up @@ -527,7 +528,7 @@ class MainActivity : ComponentActivity() {
}

public override fun onStop() {
musicViewModel.mediaBrowser?.sendCustomAction(ACTION_WILL_DISCONNECTED,null,null)
musicViewModel.mediaBrowser?.sendCustomAction(ACTION_WILL_DISCONNECTED, null, null)
MediaControllerCompat.getMediaController(this)?.unregisterCallback(callback)
musicViewModel.mediaController = null
mediaBrowser?.disconnect()
Expand Down Expand Up @@ -605,7 +606,15 @@ class MainActivity : ComponentActivity() {
musicViewModel.musicVisualizationData.clear()
musicViewModel.musicVisualizationData.addAll(magnitude)
}
// Log.d("magnitude", magnitude?.size.toString())
} else if (it.getInt("type") == EVENT_INPUT_FORTMAT_Change) {
val data = it.getSerializable("current")
musicViewModel.currentInputFormat.clear()
if (data != null) {
val d = data as HashMap<String, String>
d.forEach { formatItem ->
musicViewModel.currentInputFormat[formatItem.key] = formatItem.value
}
}
}
}
}
Expand Down Expand Up @@ -672,7 +681,7 @@ class MainActivity : ComponentActivity() {
}
MediaControllerCompat.setMediaController(this@MainActivity, mediaController)
mediaController?.registerCallback(callback)
musicViewModel.mediaBrowser?.sendCustomAction(ACTION_IS_CONNECTED,null,null)
musicViewModel.mediaBrowser?.sendCustomAction(ACTION_IS_CONNECTED, null, null)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/ztftrue/music/MusicViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MusicViewModel : ViewModel() {
// val genreItemsCount = mutableIntStateOf(2)
var mediaController: MediaControllerCompat? = null
var mediaBrowser: MediaBrowserCompat? = null

var currentInputFormat = mutableStateMapOf<String, String>() //mutableStateOf<LinkedHashMap<String, String>>(java.util.LinkedHashMap())
// val albumScrollDirection = mutableStateOf(ScrollDirectionType.GRID_VERTICAL)
// val artistScrollDirection = mutableStateOf(ScrollDirectionType.GRID_VERTICAL)
// val genreScrollDirection = mutableStateOf(ScrollDirectionType.GRID_VERTICAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CreateNotification(service: Service, private val mediaSession: MediaSessio
.setAutoCancel(false)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
builder.addAction(
R.drawable.skip_previous, "Previous", MediaButtonReceiver.buildMediaButtonPendingIntent(
R.drawable.play_previous_song, "Previous", MediaButtonReceiver.buildMediaButtonPendingIntent(
service,
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
)
Expand All @@ -138,7 +138,7 @@ class CreateNotification(service: Service, private val mediaSession: MediaSessio
)
)
builder.addAction(
R.drawable.next_song, "Next", MediaButtonReceiver.buildMediaButtonPendingIntent(
R.drawable.play_next_song, "Next", MediaButtonReceiver.buildMediaButtonPendingIntent(
service,
PlaybackStateCompat.ACTION_SKIP_TO_NEXT
)
Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/com/ztftrue/music/play/PlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.media3.common.MediaMetadata
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player
import androidx.media3.common.Tracks
import androidx.media3.common.util.UnstableApi
import androidx.media3.common.util.Util
import androidx.media3.exoplayer.DefaultRenderersFactory
Expand Down Expand Up @@ -123,7 +124,7 @@ const val EVENT_MEDIA_ITEM_Change = 3
const val EVENT_SLEEP_TIME_Change = 5
const val EVENT_DATA_READY = 6
const val EVENT_Visualization_Change = 7

const val EVENT_INPUT_FORTMAT_Change = 8

//@Suppress("deprecation")
@UnstableApi
Expand Down Expand Up @@ -180,7 +181,7 @@ class PlayService : MediaBrowserServiceCompat() {
var playCompleted = false
var needPlayPause = false
var sleepTime = 0L
var receiver: BluetoothConnectionReceiver? = null
private var receiver: BluetoothConnectionReceiver? = null
private var countDownTimer: CountDownTimer? = null
override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -1076,6 +1077,9 @@ class PlayService : MediaBrowserServiceCompat() {
}
updateNotify(position, currentPlayTrack?.duration)
}
exoPlayer.playWhenReady = false
exoPlayer.prepare()

}
setData(bundle, position.toFloat())
}
Expand Down Expand Up @@ -1330,6 +1334,25 @@ class PlayService : MediaBrowserServiceCompat() {
var errorCount = 0
private fun playerAddListener() {
exoPlayer.addListener(@UnstableApi object : Player.Listener {
override fun onTracksChanged(tracks: Tracks) {
val formatMap = HashMap<String, String>()
val audioTrackGroups = tracks.groups.filter { it.type == C.TRACK_TYPE_AUDIO }
for (trackGroup in audioTrackGroups) {
for (i in 0 until trackGroup.length) {
val format = trackGroup.getTrackFormat(i)
formatMap["Codec"] = format.codecs ?: ""
formatMap["SampleRate"] = format.sampleRate.toString()
formatMap["ChannelCount"] = format.channelCount.toString()
formatMap["Bitrate"] = format.bitrate.toString()
break
}
}
val bundle = Bundle()
bundle.putSerializable("current", formatMap)
bundle.putInt("type", EVENT_INPUT_FORTMAT_Change)
mediaSession?.setExtras(bundle)
}

@SuppressLint("ApplySharedPref")
override fun onIsPlayingChanged(isPlaying: Boolean) {
super.onIsPlayingChanged(isPlaying)
Expand Down
178 changes: 94 additions & 84 deletions app/src/main/java/com/ztftrue/music/ui/other/SearchPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -68,6 +70,7 @@ import kotlinx.coroutines.launch
/**
* show all music of playlist
*/
@OptIn(ExperimentalMaterial3Api::class)
@UnstableApi
@Composable
fun SearchPage(
Expand Down Expand Up @@ -171,93 +174,98 @@ fun SearchPage(
.padding(all = 0.dp)
.fillMaxSize(),
topBar = {
Column {
Row(
modifier = Modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
TopAppBar(
navigationIcon = {
BackButton(navController)
Row(verticalAlignment = Alignment.CenterVertically) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onBackground
) {
OutlinedTextField(
value = keywords,
onValueChange = {
val newText = it.ifEmpty {
""
}
if (keywords != newText) {
keywords = newText
}
},
placeholder = {
Text(stringResource(R.string.enter_text_to_search))
}, // Placeholder or hint text
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
),
keyboardActions = KeyboardActions(
onDone = {
focusRequester.freeFocus()
keyboardController?.hide()
}
),
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester)
.background(MaterialTheme.colorScheme.primary),
suffix = {

},
colors = TextFieldDefaults.colors(
errorTextColor = MaterialTheme.colorScheme.primary,
focusedTextColor = MaterialTheme.colorScheme.primary,
disabledTextColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
unfocusedTextColor = MaterialTheme.colorScheme.primary,
focusedContainerColor = MaterialTheme.colorScheme.background,
unfocusedContainerColor = MaterialTheme.colorScheme.background,
cursorColor = MaterialTheme.colorScheme.primary,
errorCursorColor = MaterialTheme.colorScheme.error,
focusedIndicatorColor = MaterialTheme.colorScheme.primary,
unfocusedIndicatorColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
disabledIndicatorColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.12f
},
title = {},
actions = {
Row(
modifier = Modifier
.width(configuration.screenWidthDp.dp - 60.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row(verticalAlignment = Alignment.CenterVertically) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onBackground
) {
OutlinedTextField(
value = keywords,
onValueChange = {
val newText = it.ifEmpty {
""
}
if (keywords != newText) {
keywords = newText
}
},
placeholder = {
Text(stringResource(R.string.enter_text_to_search))
}, // Placeholder or hint text
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
),
errorIndicatorColor = MaterialTheme.colorScheme.error,
disabledLeadingIconColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
keyboardActions = KeyboardActions(
onDone = {
focusRequester.freeFocus()
keyboardController?.hide()
}
),
errorLeadingIconColor = MaterialTheme.colorScheme.error,
disabledTrailingIconColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
errorTrailingIconColor = MaterialTheme.colorScheme.error,
focusedLabelColor = MaterialTheme.colorScheme.primary,
unfocusedLabelColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
disabledLabelColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester)
.background(MaterialTheme.colorScheme.primary),
suffix = {

},
colors = TextFieldDefaults.colors(
errorTextColor = MaterialTheme.colorScheme.primary,
focusedTextColor = MaterialTheme.colorScheme.primary,
disabledTextColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
unfocusedTextColor = MaterialTheme.colorScheme.primary,
focusedContainerColor = MaterialTheme.colorScheme.background,
unfocusedContainerColor = MaterialTheme.colorScheme.background,
cursorColor = MaterialTheme.colorScheme.primary,
errorCursorColor = MaterialTheme.colorScheme.error,
focusedIndicatorColor = MaterialTheme.colorScheme.primary,
unfocusedIndicatorColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
disabledIndicatorColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.12f
),
errorIndicatorColor = MaterialTheme.colorScheme.error,
disabledLeadingIconColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
errorLeadingIconColor = MaterialTheme.colorScheme.error,
disabledTrailingIconColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
errorTrailingIconColor = MaterialTheme.colorScheme.error,
focusedLabelColor = MaterialTheme.colorScheme.primary,
unfocusedLabelColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
disabledLabelColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
),
errorLabelColor = MaterialTheme.colorScheme.error,
disabledPlaceholderColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
)
),
errorLabelColor = MaterialTheme.colorScheme.error,
disabledPlaceholderColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = 0.38f
)
),
textStyle = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.onBackground),
)
textStyle = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.onBackground),
)
}
}
}
}
}
)
},
bottomBar = { Bottom(musicViewModel, navController) },
floatingActionButton = {},
Expand All @@ -272,9 +280,11 @@ fun SearchPage(
)
}
var height = localViewHeight
Box(modifier = Modifier
.fillMaxSize()
.padding(it)) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
TracksListView(
musicViewModel,
modeList, tracksList, remember {
Expand Down
Loading

0 comments on commit 23e2847

Please sign in to comment.