parse and display external lrc

dev
xufuji456 3 years ago
parent 3c1c4e48e2
commit cdb33387e2
  1. 20
      app/src/main/java/com/frank/ffmpeg/activity/AudioPlayActivity.kt
  2. 7
      app/src/main/java/com/frank/ffmpeg/activity/BaseActivity.kt
  3. 5
      app/src/main/java/com/frank/ffmpeg/model/LrcInfo.kt
  4. 4
      app/src/main/java/com/frank/ffmpeg/view/LrcView.kt

@ -20,7 +20,9 @@ import com.frank.ffmpeg.util.FFmpegUtil
import com.frank.ffmpeg.util.TimeUtil import com.frank.ffmpeg.util.TimeUtil
import com.frank.ffmpeg.model.LrcLine import com.frank.ffmpeg.model.LrcLine
import com.frank.ffmpeg.tool.LrcLineTool import com.frank.ffmpeg.tool.LrcLineTool
import com.frank.ffmpeg.tool.LrcParser
import com.frank.ffmpeg.view.LrcView import com.frank.ffmpeg.view.LrcView
import java.io.File
class AudioPlayActivity : AppCompatActivity() { class AudioPlayActivity : AppCompatActivity() {
@ -147,10 +149,27 @@ class AudioPlayActivity : AppCompatActivity() {
private fun initLrc() { private fun initLrc() {
if (path.isNullOrEmpty()) return if (path.isNullOrEmpty()) return
var lrcPath: String? = null
if (path!!.contains(".")) {
lrcPath = path!!.substring(0, path!!.lastIndexOf(".")) + ".lrc"
Log.e(TAG, "lrcPath=$lrcPath")
}
if (!lrcPath.isNullOrEmpty() && File(lrcPath).exists()) {
// should parsing in work thread
val lrcParser = LrcParser()
val lrcInfo = lrcParser.readLrc(lrcPath)
Log.e(TAG, "title=${lrcInfo?.title},album=${lrcInfo?.album},artist=${lrcInfo?.artist}")
if (lrcInfo?.lrcLineList != null) {
lrcView?.setLrc(lrcInfo.lrcLineList!!)
}
txtTitle?.text = lrcInfo?.title
txtArtist?.text = lrcInfo?.artist
} else {
val ffmpegHandler = FFmpegHandler(mHandler) val ffmpegHandler = FFmpegHandler(mHandler)
val commandLine = FFmpegUtil.probeFormat(path) val commandLine = FFmpegUtil.probeFormat(path)
ffmpegHandler.executeFFprobeCmd(commandLine) ffmpegHandler.executeFFprobeCmd(commandLine)
} }
}
private fun isPlaying() :Boolean { private fun isPlaying() :Boolean {
return audioPlayer.isPlaying return audioPlayer.isPlaying
@ -159,6 +178,7 @@ class AudioPlayActivity : AppCompatActivity() {
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
try { try {
mHandler.removeCallbacksAndMessages(null)
audioPlayer.stop() audioPlayer.stop()
audioPlayer.release() audioPlayer.release()
} catch (e: Exception) { } catch (e: Exception) {

@ -16,6 +16,7 @@ import android.widget.Toast
import com.frank.ffmpeg.R import com.frank.ffmpeg.R
import com.frank.ffmpeg.util.ContentUtil import com.frank.ffmpeg.util.ContentUtil
import java.lang.Exception
/** /**
* base Activity * base Activity
@ -74,11 +75,15 @@ abstract class BaseActivity : AppCompatActivity(), View.OnClickListener {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
try {
if (data != null && data.data != null) { if (data != null && data.data != null) {
val filePath = ContentUtil.getPath(this, data.data) val filePath = ContentUtil.getPath(this, data.data!!)
Log.i(TAG, "filePath=" + filePath!!) Log.i(TAG, "filePath=" + filePath!!)
onSelectedFile(filePath) onSelectedFile(filePath)
} }
} catch (e : Exception) {
e.printStackTrace()
}
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {

@ -1,8 +1,5 @@
package com.frank.ffmpeg.model package com.frank.ffmpeg.model
import java.util.ArrayList
class LrcInfo { class LrcInfo {
var title: String? = null var title: String? = null
@ -14,5 +11,5 @@ class LrcInfo {
var version: String? = null var version: String? = null
var offset: Int = 0 var offset: Int = 0
var lrcLineList: ArrayList<LrcLine>? = null var lrcLineList: List<LrcLine>? = null
} }

@ -23,7 +23,7 @@ class LrcView(context: Context, attr: AttributeSet) : View(context, attr) {
private val mPadding = 10 private val mPadding = 10
private val mLrcFontSize = 35 private val mLrcFontSize = 45
private var mHighLightRow = 0 private var mHighLightRow = 0
@ -48,7 +48,7 @@ class LrcView(context: Context, attr: AttributeSet) : View(context, attr) {
annotation class HighLightMode annotation class HighLightMode
@HighLightMode @HighLightMode
private var mode = MODE_HIGH_LIGHT_KARAOKE private var mode = MODE_HIGH_LIGHT_NORMAL
init { init {

Loading…
Cancel
Save