Commit 3cd106b6 by 霍志良

feat:ydl-media升级

parent 602356c7
......@@ -14,7 +14,7 @@ ext {
"m-dynamic" : "0.0.7.29",
"m-article" : "0.0.0.10",
"m-muse" : "0.0.28.26",
"m-muse" : "0.0.28.27",
"m-tests" : "0.0.24.15",
"m-course" : "0.0.43.28",
......@@ -37,7 +37,7 @@ ext {
//第二步 若干
"ydl-webview" : "0.0.38.47",
"ydl-media" : "0.0.21.34",
"ydl-media" : "0.0.21.35",
"ydl-pay" : "0.0.18.19",
"m-audioim" : "0.0.49.29.41",
"ydl-flutter-base": "0.0.14.32",
......@@ -97,7 +97,7 @@ ext {
"m-dynamic" : "0.0.7.29",
"m-article" : "0.0.0.8",
"m-muse" : "0.0.28.26",
"m-muse" : "0.0.28.27",
"m-tests" : "0.0.24.15",
"m-course" : "0.0.42.70",
//-------------- 业务模块 API 层 --------------
......@@ -119,7 +119,7 @@ ext {
//第二步 若干
"ydl-webview" : "0.0.38.47",
"ydl-media" : "0.0.21.34",
"ydl-media" : "0.0.21.35",
"ydl-pay" : "0.0.18.19",
"m-audioim" : "0.0.49.29.41",
"ydl-flutter-base": "0.0.14.32",
......
......@@ -66,21 +66,25 @@ class MusePlugin : MethodChannel.MethodCallHandler {
}
// 播放音乐
ACTION_PLAY_MUSIC -> {
var musicUrl: String? = methodCall.argument<String>("url")
var mContinue: Boolean = methodCall.argument<Boolean>("mContinue")!!
try {
var musicUrl: String? = methodCall.argument<String>("url")
var mContinue: Boolean = methodCall.argument<Boolean>("mContinue")!!
if (mContinue) {
AudioPlayer.get().seekTo(-1, AudioPlayer.get().audioPosition)
AudioPlayer.get().startPlayer()
}else {
val music = Music()
music.path = musicUrl ?: currentMusicUrl
music.album = ""
music.artist = ""
music.coverPath = ""
music.title = ""
PlayerFloatHelper.playingType = PlayTypeEnum.PLAY_TYPE_MUSE
AudioPlayer.get().singleCirclePlay(music)
if (mContinue) {
AudioPlayer.get().seekTo(-1, AudioPlayer.get().audioPosition)
AudioPlayer.get().startPlayer()
}else {
val music = Music()
music.path = musicUrl ?: currentMusicUrl
music.album = ""
music.artist = ""
music.coverPath = ""
music.title = ""
PlayerFloatHelper.playingType = PlayTypeEnum.PLAY_TYPE_MUSE
AudioPlayer.get().singleCirclePlay(music)
}
}catch (e: Exception){
e.printStackTrace()
}
}
// 暂停音乐
......
......@@ -3,7 +3,6 @@ package com.ydl.media.audio
import android.content.Context
import android.content.IntentFilter
import android.media.AudioManager
import android.media.MediaPlayer
import android.os.Handler
import android.os.Looper
import com.tencent.bugly.Bugly.applicationContext
......@@ -14,7 +13,10 @@ import com.ydl.media.audio.manager.NotifyManager
import com.ydl.media.audio.model.Music
import com.ydl.media.audio.receiver.NoisyAudioStreamReceiver
import com.ydl.media.audio.utils.PlayProgressUtil
import com.ydl.ydlcommon.utils.LogUtil
import com.yidianling.common.tools.ToastUtil
import tv.danmaku.ijk.media.player.IMediaPlayer
import tv.danmaku.ijk.media.player.IjkMediaPlayer
import java.io.IOException
import java.util.*
import kotlin.collections.ArrayList
......@@ -28,7 +30,7 @@ class AudioPlayer private constructor() {
private var context: Context? = null
private var audioFocusManager: AudioFocusManager? = null
var mediaPlayer: MediaPlayer? = null
var mediaPlayer: IMediaPlayer? = null
private var handler: Handler? = null
private var noisyReceiver: NoisyAudioStreamReceiver? = null
private var noisyFilter: IntentFilter? = null
......@@ -117,7 +119,17 @@ class AudioPlayer private constructor() {
fun init(context: Context) {
this.context = context.applicationContext
audioFocusManager = AudioFocusManager(context)
mediaPlayer = MediaPlayer()
mediaPlayer = IjkMediaPlayer()
try {
(mediaPlayer as IjkMediaPlayer).setOption(
IjkMediaPlayer.OPT_CATEGORY_FORMAT,
"dns_cache_clear",
1
)
} catch (e: Exception) {
LogUtil.e(e.message)
}
mediaPlayer!!.setOnPreparedListener { mp ->
if (isPreparing) {
if (autoSaveProgress) {
......@@ -134,7 +146,7 @@ class AudioPlayer private constructor() {
}
}
for (listener in listeners) {
listener.onPrepared(mediaPlayer!!.duration.toLong())
listener.onPrepared(mediaPlayer!!.duration)
}
}
mediaPlayer!!.setOnBufferingUpdateListener { mp, percent ->
......@@ -256,7 +268,7 @@ class AudioPlayer private constructor() {
try {
mediaPlayer!!.reset()
mediaPlayer!!.setDataSource(music!!.path)
mediaPlayer!!.dataSource = music!!.path
mediaPlayer!!.prepareAsync()
state = STATE_PREPARING
for (listener in listeners) {
......@@ -422,10 +434,10 @@ class AudioPlayer private constructor() {
currentPosition = position
} else {
currentPosition = (percent * mediaPlayer!!.duration / 100).toLong()
currentPosition = percent * mediaPlayer!!.duration / 100
}
mediaPlayer!!.seekTo(currentPosition.toInt())//////
mediaPlayer!!.seekTo(currentPosition)
MediaSessionManager.get().updatePlaybackState()
if (autoSaveProgress) {
PlayProgressUtil.saveProgress(
......@@ -451,7 +463,7 @@ class AudioPlayer private constructor() {
* 获取音乐时长
*/
fun getDuration(): Long {
return mediaPlayer?.duration?.toLong() ?: 0
return mediaPlayer?.duration ?: 0
}
companion object {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment