parse and display external lrc

dev
xufuji456 3 years ago
parent 3c1c4e48e2
commit cdb33387e2
  1. 26
      app/src/main/java/com/frank/ffmpeg/activity/AudioPlayActivity.kt
  2. 13
      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.model.LrcLine
import com.frank.ffmpeg.tool.LrcLineTool
import com.frank.ffmpeg.tool.LrcParser
import com.frank.ffmpeg.view.LrcView
import java.io.File
class AudioPlayActivity : AppCompatActivity() {
@ -147,9 +149,26 @@ class AudioPlayActivity : AppCompatActivity() {
private fun initLrc() {
if (path.isNullOrEmpty()) return
val ffmpegHandler = FFmpegHandler(mHandler)
val commandLine = FFmpegUtil.probeFormat(path)
ffmpegHandler.executeFFprobeCmd(commandLine)
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 commandLine = FFmpegUtil.probeFormat(path)
ffmpegHandler.executeFFprobeCmd(commandLine)
}
}
private fun isPlaying() :Boolean {
@ -159,6 +178,7 @@ class AudioPlayActivity : AppCompatActivity() {
override fun onStop() {
super.onStop()
try {
mHandler.removeCallbacksAndMessages(null)
audioPlayer.stop()
audioPlayer.release()
} catch (e: Exception) {

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

@ -1,8 +1,5 @@
package com.frank.ffmpeg.model
import java.util.ArrayList
class LrcInfo {
var title: String? = null
@ -14,5 +11,5 @@ class LrcInfo {
var version: String? = null
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 mLrcFontSize = 35
private val mLrcFontSize = 45
private var mHighLightRow = 0
@ -48,7 +48,7 @@ class LrcView(context: Context, attr: AttributeSet) : View(context, attr) {
annotation class HighLightMode
@HighLightMode
private var mode = MODE_HIGH_LIGHT_KARAOKE
private var mode = MODE_HIGH_LIGHT_NORMAL
init {

Loading…
Cancel
Save