Skip to content

Commit

Permalink
添加一个重播当前音频的api
Browse files Browse the repository at this point in the history
  • Loading branch information
lizixian committed Apr 21, 2021
1 parent 742793b commit d08c0db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/lzx/musiclib/home/TestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import kotlinx.android.synthetic.main.activity_test.playMusicById
import kotlinx.android.synthetic.main.activity_test.playMusicByInfo
import kotlinx.android.synthetic.main.activity_test.playMusicByUrl
import kotlinx.android.synthetic.main.activity_test.querySongInfoInLocal
import kotlinx.android.synthetic.main.activity_test.replay
import kotlinx.android.synthetic.main.activity_test.restoreMusic
import kotlinx.android.synthetic.main.activity_test.rtmpBtn
import kotlinx.android.synthetic.main.activity_test.seekBarPro
Expand Down Expand Up @@ -302,6 +303,9 @@ open class TestActivity : AppCompatActivity() {
openN?.setOnClickListener {
StarrySky.openNotification()
}
replay?.setOnClickListener {
StarrySky.with().replayCurrMusic()
}

StarrySky.with().setOnPlayProgressListener(object : OnPlayProgressListener {
@SuppressLint("SetTextI18n")
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="同时播放多个音频2" />

<Button
android:id="@+id/replay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="重播当前音频" />
</LinearLayout>

<LinearLayout
Expand Down
6 changes: 3 additions & 3 deletions starrysky/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 261
versionName "2.6.1"
versionCode 263
versionName "2.6.3"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -39,7 +39,7 @@ android {
userOrg = 'lizixian'
groupId = 'com.lzx'
artifactId = 'StarrySkyX'
publishVersion = '2.6.1'
publishVersion = '2.6.3'
desc = 'A Powerful and Streamline MusicLibrary'
website = "https://github.com/lizixian18/StarrySky"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ class PlayerControl(
playMusicImpl(mediaList.getOrNull(index))
}

/**
* 重播当前音频
*/
fun replayCurrMusic() {
playbackManager.replayCurrMusic()
}

private fun playMusicImpl(songInfo: SongInfo?) {
if (songInfo == null) return
playbackManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ class PlaybackManager(private val provider: MediaSourceProvider,
StarrySky.getBinder()?.onStopByTimedOff(time, isPause, finishCurrSong)
}

/**
* 重播当前音频
*/
fun replayCurrMusic() {
player()?.getCurrPlayInfo()?.let {
player()?.currentMediaId = ""
player()?.play(it, true)
}
}

override fun onPlayerStateChanged(songInfo: SongInfo?, playWhenReady: Boolean, playbackState: Int) {
if (lastSongInfo?.songId != songInfo?.songId && !isActionStop) {
val state = PlaybackStage()
Expand Down

0 comments on commit d08c0db

Please sign in to comment.