Skip to content

Commit

Permalink
Merge pull request #83 from ZTFtrue/develope
Browse files Browse the repository at this point in the history
Develope
  • Loading branch information
ZTFtrue authored Nov 6, 2024
2 parents 8e24127 + 13cc61c commit 4600808
Show file tree
Hide file tree
Showing 27 changed files with 590 additions and 307 deletions.
67 changes: 33 additions & 34 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ android {

}
namespace = "com.ztftrue.music"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.ztftrue.music"
minSdk = 30
targetSdk = 34
targetSdk = 35
versionCode = 39
versionName = "0.1.39"

Expand Down Expand Up @@ -56,7 +56,7 @@ android {
tasks.named("mergeReleaseArtProfile").configure {
doLast {
copy {
from("$buildDir/outputs/mapping/release/mapping.txt")
from("${layout.buildDirectory}/outputs/mapping/release/mapping.txt")
into(variantOutput.outputFile.parent)
rename { "mapping.txt" }
}
Expand Down Expand Up @@ -102,56 +102,46 @@ android {

dependencies {

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7")
implementation("androidx.activity:activity-compose:1.9.3")
implementation("androidx.navigation:navigation-compose:2.8.3")
implementation("androidx.navigation:navigation-compose:2.9.0-alpha02")
implementation("androidx.media3:media3-exoplayer:1.4.1")
implementation ("androidx.media:media:1.7.0")
implementation("androidx.media:media:1.7.0")

implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.material3:material3:1.2.1")
implementation("androidx.compose.material3:material3-window-size-class:1.2.1")
implementation("androidx.compose.material:material-icons-extended:1.7.5")
implementation("androidx.compose.material3:material3:1.4.0-alpha03")
implementation("androidx.compose.material3:material3-window-size-class:1.4.0-alpha03")

// splash
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.1")
implementation("androidx.constraintlayout:constraintlayout-compose:1.1.0")

// load image
implementation("io.coil-kt:coil-compose:2.5.0")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.10.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2024.10.01"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
// debugImplementation ("com.squareup.leakcanary:leakcanary-android:2.14")
implementation ("com.github.bumptech.glide:compose:1.0.0-beta01")
// https://mvnrepository.com/artifact/pl.edu.icm/JLargeArrays
// implementation("pl.edu.icm:JLargeArrays:1.6")
// https://mvnrepository.com/artifact/commons-io/commons-io
// implementation("commons-io:commons-io:2.14.0")

// https://mvnrepository.com/artifact/com.github.wendykierp/JTransforms
implementation("com.github.wendykierp:JTransforms:3.1")
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation("org.apache.commons:commons-math3:3.6.1")
// implementation("be.tarsos.dsp:core:2.5")
// https://mvnrepository.com/artifact/org.bitbucket.ijabz/jaudiotagger
// implementation("net.jthink:jaudiotagger:3.0.1")

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.collection:collection-ktx:1.4.4")
implementation("androidx.fragment:fragment-ktx:1.8.4")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")

implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.collection:collection-ktx:1.4.5")
implementation("androidx.fragment:fragment-ktx:1.8.5")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
implementation("androidx.palette:palette-ktx:1.0.0")

// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation("org.apache.commons:commons-math3:3.6.1")
implementation("com.google.code.gson:gson:2.11.0")

val roomVersion = "2.6.1"
implementation("androidx.room:room-runtime:$roomVersion")
annotationProcessor("androidx.room:room-compiler:$roomVersion")
Expand All @@ -166,9 +156,18 @@ dependencies {
// optional - Paging 3 Integration
implementation("androidx.room:room-paging:$roomVersion")

implementation("com.google.code.gson:gson:2.11.0")

implementation("uk.me.berndporr:iirj:1.7")

// debugImplementation ("com.squareup.leakcanary:leakcanary-android:2.14")
// implementation("uk.me.berndporr:iirj:1.7")
// implementation ("com.github.bumptech.glide:compose:1.0.0-beta01")
// https://mvnrepository.com/artifact/pl.edu.icm/JLargeArrays
// implementation("pl.edu.icm:JLargeArrays:1.6")
// https://mvnrepository.com/artifact/commons-io/commons-io
// implementation("commons-io:commons-io:2.14.0")
// https://mvnrepository.com/artifact/com.github.wendykierp/JTransforms
// implementation("com.github.wendykierp:JTransforms:3.1")
// implementation("be.tarsos.dsp:core:2.5")
// https://mvnrepository.com/artifact/org.bitbucket.ijabz/jaudiotagger
// implementation("net.jthink:jaudiotagger:3.0.1")

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package com.ztftrue.music.effects

import android.os.Bundle
import android.support.v4.media.session.MediaSessionCompat
import android.util.Log
import androidx.media3.common.C
import androidx.media3.common.audio.AudioProcessor
import androidx.media3.common.audio.AudioProcessor.EMPTY_BUFFER
import androidx.media3.common.util.UnstableApi
import androidx.media3.common.util.Util
import be.tarsos.dsp.io.TarsosDSPAudioFloatConverter
import be.tarsos.dsp.io.TarsosDSPAudioFormat
import com.ztftrue.music.effects.SoundUtils.downsampleMagnitudes
import com.ztftrue.music.effects.SoundUtils.expandBuffer
import com.ztftrue.music.effects.SoundUtils.getBytePerSample
import com.ztftrue.music.effects.SoundUtils.getOutputSize
import com.ztftrue.music.play.EVENT_Visualization_Change
import com.ztftrue.music.utils.Utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.apache.commons.math3.util.FastMath
import java.nio.ByteBuffer
Expand Down Expand Up @@ -96,11 +92,17 @@ class EqualizerAudioProcessor : AudioProcessor {
return AudioProcessor.AudioFormat.NOT_SET
}
outputAudioFormat = inputAudioFormat
// single channel
bytePerSample = getBytePerSample(outputAudioFormat!!.encoding)
bufferSize = getOutputSize(outputAudioFormat!!, bytePerSample)
val perSecond = Util.getPcmFrameSize(
outputAudioFormat!!.encoding,
outputAudioFormat!!.channelCount
)* outputAudioFormat!!.sampleRate
Log.d("EqualizerAudioProcessor", "configure: ${outputAudioFormat!!.sampleRate}")
bufferSize = perSecond
dataBuffer = ByteBuffer.allocate(bufferSize * 8)
floatArray = FloatArray(bufferSize)
val size = bufferSize / bytePerSample / outputAudioFormat!!.channelCount
val size = bufferSize / (bytePerSample * outputAudioFormat!!.channelCount)
sampleBufferRealLeft = FloatArray(size)
sampleBufferRealRight = FloatArray(size)
visualizationBuffer = FloatArray(size)
Expand Down Expand Up @@ -178,7 +180,6 @@ class EqualizerAudioProcessor : AudioProcessor {
}
if (dataBuffer.remaining() < 1 || dataBuffer.remaining() < inputBuffer.limit()) {
dataBuffer = expandBuffer(dataBuffer.capacity() + inputBuffer.limit() * 2, dataBuffer)
// Log.d("ExpandBuffer", dataBuffer.remaining().toString())
}
dataBuffer.put(inputBuffer)
}
Expand Down Expand Up @@ -208,9 +209,6 @@ class EqualizerAudioProcessor : AudioProcessor {
private var changeDb = false
override fun getOutput(): ByteBuffer {
processData()
// if (outputBuffer.position() == 0) {
// return EMPTY_BUFFER;
// }
val outputBuffer: ByteBuffer = this.outputBuffer
this.outputBuffer = EMPTY_BUFFER
outputBuffer.flip()
Expand Down Expand Up @@ -244,9 +242,7 @@ class EqualizerAudioProcessor : AudioProcessor {
dataBuffer.limit(dataBuffer.position() + readSize) // 设置新 limit 来控制读取量
processedBuffer.put(dataBuffer)
dataBuffer.limit(oldLimit)

val byteArray = processedBuffer.array()

converter.toFloatArray(
byteArray,
floatArray,
Expand Down Expand Up @@ -341,28 +337,12 @@ class EqualizerAudioProcessor : AudioProcessor {
ind += 1
}
converter.toByteArray(floatArray, halfLength, byteArray)
processedBuffer.clear()
processedBuffer.put(byteArray)
processedBuffer.position(bufferSize)
processedBuffer.order(ByteOrder.nativeOrder())
this.outputBuffer = processedBuffer
}
dataBuffer.compact()
}
if (visualizationAudioActive && blockingQueue.size >= visualizationBuffer.size) {
visualizationBuffer.forEachIndexed { index, _ ->
visualizationBuffer[index] = blockingQueue.poll() ?: 0f
}
CoroutineScope(Dispatchers.IO).launch {
val magnitude: FloatArray =
pcmToFrequencyDomain.process(visualizationBuffer)
val m = downsampleMagnitudes(magnitude, 32)
val bundle = Bundle()
bundle.putInt("type", EVENT_Visualization_Change)
bundle.putFloatArray("magnitude", m)
mediaSession?.setExtras(bundle)
}
}
lock.unlock()
} else {
dataBuffer.flip()
Expand All @@ -387,13 +367,15 @@ class EqualizerAudioProcessor : AudioProcessor {
}

override fun flush() {
lock.lock()
if (outputBuffer != EMPTY_BUFFER) {
outputBuffer.clear()
}
dataBuffer.clear()
blockingQueue.clear()

inputEnded = false
lock.unlock()
}


Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/ztftrue/music/play/PlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
import android.widget.Toast
import androidx.core.net.toUri
import androidx.media.MediaBrowserServiceCompat
Expand All @@ -28,6 +27,7 @@ import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.common.util.Util
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.audio.AudioSink
Expand Down Expand Up @@ -171,7 +171,8 @@ class PlayService : MediaBrowserServiceCompat() {
equalizer = false,
equalizerBand = bandsValue
)
// private var subscribed = false

// private var subscribed = false
var remainingTime = 0L
var playCompleted = false
var needPlayPause = false
Expand Down Expand Up @@ -1244,10 +1245,10 @@ class PlayService : MediaBrowserServiceCompat() {
specifiedBufferSize: Int,
outputChannels: IntArray?
) {
// val bytesPerSec = Util.getPcmFrameSize(
// inputFormat.pcmEncoding,
// inputFormat.channelCount
// ) * inputFormat.sampleRate * 1 // 这里计算出的就是1s音频的缓冲长度
val bytesPerSec = Util.getPcmFrameSize(
inputFormat.pcmEncoding,
inputFormat.channelCount
) * inputFormat.sampleRate * 1 // 这里计算出的就是 1s音频的缓冲长度

CoroutineScope(Dispatchers.Main).launch {
if (needPlayPause) {
Expand All @@ -1259,8 +1260,7 @@ class PlayService : MediaBrowserServiceCompat() {
exoPlayer.duration
)
}

super.configure(inputFormat, specifiedBufferSize, outputChannels)
super.configure(inputFormat, bytesPerSec, outputChannels)
}

}
Expand Down
36 changes: 26 additions & 10 deletions app/src/main/java/com/ztftrue/music/ui/home/AlbumGridView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ import androidx.compose.ui.zIndex
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.media3.common.util.UnstableApi
import androidx.navigation.NavHostController
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import coil.compose.rememberAsyncImagePainter
import com.ztftrue.music.MusicViewModel
import com.ztftrue.music.R
import com.ztftrue.music.Router
Expand Down Expand Up @@ -126,7 +125,8 @@ fun AlbumGridView(
if (albumList.isEmpty()) {
Column(modifier = Modifier.fillMaxSize()) {
Text(
text = stringResource(R.string.there_is_no_any_album_in_here), Modifier.padding(start = 10.dp),
text = stringResource(R.string.there_is_no_any_album_in_here),
Modifier.padding(start = 10.dp),
color = MaterialTheme.colorScheme.onBackground
)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ fun AlbumGridView(
}


@OptIn(ExperimentalFoundationApi::class, ExperimentalGlideComposeApi::class)
@OptIn(ExperimentalFoundationApi::class)
@androidx.annotation.OptIn(UnstableApi::class)
@Composable
fun AlbumItemView(
Expand Down Expand Up @@ -277,12 +277,24 @@ fun AlbumItemView(
}) {
ConstraintLayout {
val (playIndicator) = createRefs()
GlideImage(

model = musicViewModel.getAlbumCover(
item.id,
context
Image(
// painter = painterResource(
// musicViewModel.getAlbumCover(
// item.id,
// context
// )
// ),
painter = rememberAsyncImagePainter(
musicViewModel.getAlbumCover(
item.id,
context
)
?: R.drawable.songs_thumbnail_cover
),
// model = musicViewModel.getAlbumCover(
// item.id,
// context
// ),
contentDescription = stringResource(id = R.string.album_cover),
modifier = Modifier
.zIndex(0f)
Expand Down Expand Up @@ -324,7 +336,11 @@ fun AlbumItemView(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = stringResource(R.string.song, number, if (number <= 1L) "" else "s"),
text = stringResource(
R.string.song,
number,
if (number <= 1L) "" else stringResource(id = R.string.s)
),
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fun ArtistItemView(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = stringResource(R.string.song, number, if (number <= 1L) "" else "s"),
text = stringResource(R.string.song, number, if (number <= 1L) "" else stringResource(id = R.string.s)),
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fun FolderItemView(
modifier = Modifier.horizontalScroll(rememberScrollState(0)),
)
Text(
text = stringResource(R.string.song, number, if (number <= 1L) "" else "s"),
text = stringResource(R.string.song, number, if (number <= 1L) "" else stringResource(id = R.string.s)),
color = MaterialTheme.colorScheme.onBackground,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fun GenreItemView(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = stringResource(R.string.song, number, if (number <= 1L) "" else "s"),
text = stringResource(R.string.song, number, if (number <= 1L) "" else stringResource(id = R.string.s)),
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fun PlayListItemView(
modifier = Modifier.horizontalScroll(rememberScrollState(0))
)
Text(
text = stringResource(R.string.song, number, if (number <= 1L) "" else "s"),
text = stringResource(R.string.song, number, if (number <= 1L) "" else stringResource(id = R.string.s)),
color = MaterialTheme.colorScheme.onBackground,
)
}
Expand Down
Loading

0 comments on commit 4600808

Please sign in to comment.