add skipping forward/backward by 2% at pressing the song progress text

This commit is contained in:
tibbi 2018-02-08 12:16:55 +01:00
parent b4e8a5a3a2
commit 38ba519c43
5 changed files with 26 additions and 4 deletions

View file

@ -115,6 +115,8 @@
<action android:name="com.simplemobiletools.musicplayer.action.PLAYPOS"/>
<action android:name="com.simplemobiletools.musicplayer.action.REFRESH_LIST"/>
<action android:name="com.simplemobiletools.musicplayer.action.SET_PROGRESS"/>
<action android:name="com.simplemobiletools.musicplayer.action.SKIP_BACKWARD"/>
<action android:name="com.simplemobiletools.musicplayer.action.SKIP_FORWARD"/>
</intent-filter>
</service>

View file

@ -89,8 +89,8 @@ class MainActivity : SimpleActivity(), SongListListener {
play_pause_btn.setOnClickListener { sendIntent(PLAYPAUSE) }
next_btn.setOnClickListener { sendIntent(NEXT) }
repeat_btn.setOnClickListener { toggleSongRepetition() }
song_progress_current.setOnClickListener { }
song_progress_max.setOnClickListener { }
song_progress_current.setOnClickListener { sendIntent(SKIP_BACKWARD) }
song_progress_max.setOnClickListener { sendIntent(SKIP_FORWARD) }
songs_playlist_empty_add_folder.setOnClickListener { addFolderToPlaylist() }
volumeControlStream = AudioManager.STREAM_MUSIC

View file

@ -285,8 +285,8 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, val list
play_pause_btn.setOnClickListener { activity.sendIntent(PLAYPAUSE) }
next_btn.setOnClickListener { activity.sendIntent(NEXT) }
repeat_btn.setOnClickListener { listener.listToggleSongRepetition() }
song_progress_current.setOnClickListener { }
song_progress_max.setOnClickListener { }
song_progress_current.setOnClickListener { activity.sendIntent(SKIP_BACKWARD) }
song_progress_max.setOnClickListener { activity.sendIntent(SKIP_FORWARD) }
previous_btn.applyColorFilter(textColor)
play_pause_btn.applyColorFilter(textColor)

View file

@ -19,6 +19,8 @@ const val PLAYPOS = PATH + "PLAYPOS"
const val REFRESH_LIST = PATH + "REFRESH_LIST"
const val SET_PROGRESS = PATH + "SET_PROGRESS"
const val SET_EQUALIZER = PATH + "SET_EQUALIZER"
const val SKIP_BACKWARD = PATH + "SKIP_BACKWARD"
const val SKIP_FORWARD = PATH + "SKIP_FORWARD"
// shared preferences
const val SHUFFLE = "shuffle"

View file

@ -177,6 +177,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
}
}
SKIP_BACKWARD -> skipBackward()
SKIP_FORWARD -> skipForward()
}
return START_NOT_STICKY
@ -636,4 +638,20 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
mProgressHandler!!.removeCallbacksAndMessages(null)
}
}
private fun skipBackward() {
skip(false)
}
private fun skipForward() {
skip(true)
}
private fun skip(forward: Boolean) {
val curr = mPlayer!!.currentPosition
val twoPercents = mPlayer!!.duration / 50
val newProgress = if (forward) curr + twoPercents else curr - twoPercents
mPlayer!!.seekTo(newProgress)
resumeSong()
}
}