Commit edc7387d by 刘鹏

Merge branch 'd/lancet/4.3.93_muse' into 'd/4.3.93_muse'

fix switch play list

See merge request app_android_lib/YDL-Component!37
parents 1ae1e421 f54aa0a0
...@@ -9,12 +9,12 @@ ext { ...@@ -9,12 +9,12 @@ ext {
"m-consultant" : "0.0.60.25", "m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08", "m-fm" : "0.0.30.08",
"m-user" : "0.0.62.10", "m-user" : "0.0.62.10",
"m-home" : "0.0.23.50", "m-home" : "0.0.23.52",
"m-im" : "0.0.21.44", "m-im" : "0.0.21.44",
"m-dynamic" : "0.0.7.73", "m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.10", "m-article" : "0.0.0.10",
"m-muse" : "0.0.28.30", "m-muse" : "0.0.28.32",
"m-tests" : "0.0.24.18", "m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37", "m-course" : "0.0.43.37",
...@@ -94,12 +94,12 @@ ext { ...@@ -94,12 +94,12 @@ ext {
"m-consultant" : "0.0.60.25", "m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08", "m-fm" : "0.0.30.08",
"m-user" : "0.0.62.10", "m-user" : "0.0.62.10",
"m-home" : "0.0.23.50", "m-home" : "0.0.23.52",
"m-im" : "0.0.21.44", "m-im" : "0.0.21.44",
"m-dynamic" : "0.0.7.73", "m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.8", "m-article" : "0.0.0.8",
"m-muse" : "0.0.28.30", "m-muse" : "0.0.28.32",
"m-tests" : "0.0.24.18", "m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37", "m-course" : "0.0.43.37",
//-------------- 业务模块 API 层 -------------- //-------------- 业务模块 API 层 --------------
......
...@@ -64,6 +64,10 @@ class MeditationTypeAdapter( ...@@ -64,6 +64,10 @@ class MeditationTypeAdapter(
holder.cvLayout?.setOnClickListener { holder.cvLayout?.setOnClickListener {
if (meditationType == 0){ if (meditationType == 0){
if (Utils.isFastClick()) {
//防止连击
return@setOnClickListener
}
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) { if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener return@setOnClickListener
} }
...@@ -79,6 +83,9 @@ class MeditationTypeAdapter( ...@@ -79,6 +83,9 @@ class MeditationTypeAdapter(
//防止连击 //防止连击
return@setOnClickListener return@setOnClickListener
} }
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
val homeLink = "${homeLink}mark=$mark&cateId=$cateId&meditationId=${data[position].meditationId}" val homeLink = "${homeLink}mark=$mark&cateId=$cateId&meditationId=${data[position].meditationId}"
if (!homeLink.isNullOrBlank()) { if (!homeLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(homeLink, null)) NewH5Activity.start(context, H5Params(homeLink, null))
...@@ -92,6 +99,9 @@ class MeditationTypeAdapter( ...@@ -92,6 +99,9 @@ class MeditationTypeAdapter(
//防止连击 //防止连击
return@setOnClickListener return@setOnClickListener
} }
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
val moreLink = "${moreLink}mark=$mark&cateId=$cateId" val moreLink = "${moreLink}mark=$mark&cateId=$cateId"
if (!moreLink.isNullOrBlank()) { if (!moreLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(moreLink, null)) NewH5Activity.start(context, H5Params(moreLink, null))
......
...@@ -3,11 +3,15 @@ package com.yidianling.home.ui.view ...@@ -3,11 +3,15 @@ package com.yidianling.home.ui.view
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.SurfaceTexture
import android.graphics.Typeface import android.graphics.Typeface
import android.media.MediaPlayer import android.media.MediaPlayer
import android.os.Handler
import android.text.SpannableString import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.view.Surface
import android.view.TextureView
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
...@@ -18,13 +22,16 @@ import com.google.android.material.tabs.TabLayoutMediator ...@@ -18,13 +22,16 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.ydl.webview.H5Params import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity import com.ydl.webview.NewH5Activity
import com.ydl.ydl_image.module.GlideApp import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.utils.Utils import com.ydl.ydlcommon.utils.Utils
import com.yidianling.home.MeditationViewPagerAdapter import com.yidianling.home.MeditationViewPagerAdapter
import com.yidianling.home.R import com.yidianling.home.R
import com.yidianling.home.constract.HomeViewConfig import com.yidianling.home.constract.HomeViewConfig
import com.yidianling.home.event.IHomeEvent import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.MeditationModuleBean import com.yidianling.home.model.bean.MeditationModuleBean
import com.yidianling.user.api.service.IUserService
import kotlinx.android.synthetic.ydl.home_muse_view.view.* import kotlinx.android.synthetic.ydl.home_muse_view.view.*
import java.util.concurrent.Executors
/** /**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a> * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
...@@ -36,6 +43,11 @@ import kotlinx.android.synthetic.ydl.home_muse_view.view.* ...@@ -36,6 +43,11 @@ import kotlinx.android.synthetic.ydl.home_muse_view.view.*
class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEvent?) : class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEvent?) :
LinearLayout(mContext) { LinearLayout(mContext) {
private var mSurface: Surface? = null
private var mSurfaceTexture: SurfaceTexture? = null
private var mMediaPlayer:MediaPlayer? = null
private val meditationTitles = mutableListOf<String>() private val meditationTitles = mutableListOf<String>()
init { init {
...@@ -67,6 +79,9 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -67,6 +79,9 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
//防止连击 //防止连击
return@setOnClickListener return@setOnClickListener
} }
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
if (!moreLink.isNullOrBlank()) { if (!moreLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(moreLink, null)) NewH5Activity.start(context, H5Params(moreLink, null))
} }
...@@ -79,11 +94,11 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -79,11 +94,11 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
if (bean.mditationIndexInfo?.desc.isNullOrBlank()){ if (bean.mditationIndexInfo?.desc.isNullOrBlank()){
"无常的日子里,呼吸间拾起力量" "无常的日子里,呼吸间拾起力量"
}else{ }else{
bean?.mditationIndexInfo?.desc bean.mditationIndexInfo?.desc
} }
tv_meditation_slogan.text = slogan tv_meditation_slogan.text = slogan
val videoUrl = bean?.mditationIndexInfo?.videoLink val videoUrl = bean.mditationIndexInfo?.videoLink
if (videoUrl.isNullOrBlank()){ if (videoUrl.isNullOrBlank()){
Glide.with(this) Glide.with(this)
...@@ -94,31 +109,68 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -94,31 +109,68 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
.load(bean.mditationIndexInfo?.mditationIndexUrl) .load(bean.mditationIndexInfo?.mditationIndexUrl)
.into(iv_video_background) .into(iv_video_background)
video_view?.setVideoPath(videoUrl) video_view?.surfaceTextureListener = object: TextureView.SurfaceTextureListener{
override fun onSurfaceTextureAvailable(
surfaceTexture: SurfaceTexture?,
width: Int,
height: Int
) {
mSurface = Surface(surfaceTexture)
runnable.setParams(videoUrl,bean.mditationIndexInfo?.mditationIndexUrl?:"")
Executors.newSingleThreadExecutor().execute(runnable)
}
override fun onSurfaceTextureSizeChanged(
surface: SurfaceTexture?,
width: Int,
height: Int
) {
video_view?.setOnErrorListener { mp, what, extra ->
Glide.with(this)
.load(bean.mditationIndexInfo?.mditationIndexUrl)
.into(iv_video_background)
true
} }
video_view?.setOnPreparedListener {
it?.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING) override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
video_view?.setOnInfoListener { mp, what, extra -> // mSurface = null
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START){ // mSurfaceTexture = null
iv_video_background.visibility = View.GONE
video_view.setBackgroundColor(Color.TRANSPARENT) try {
mMediaPlayer?.stop()
mMediaPlayer?.release()
}catch (e:Exception){
} }
true return true
} }
it?.start()
it?.setVolume(0.0F,0.0F) override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {
}
} }
video_view?.setOnCompletionListener { video_view?.start() }
// video_view?.setVideoPath(videoUrl)
// video_view?.setOnErrorListener { mp, what, extra ->
// Glide.with(this)
// .load(bean.mditationIndexInfo?.mditationIndexUrl)
// .into(iv_video_background)
// true
// }
// video_view?.setOnPreparedListener {
// it?.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING)
// video_view?.setOnInfoListener { mp, what, extra ->
// if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START){
// iv_video_background.visibility = View.GONE
// video_view.setBackgroundColor(Color.TRANSPARENT)
// }
// true
// }
// it?.start()
// it?.setVolume(0.0F,0.0F)
// }
// video_view?.setOnCompletionListener { video_view?.start() }
} }
bean?.mditationListResponse?.forEach { bean.mditationListResponse?.forEach {
meditationTitles.add(it.comment) meditationTitles.add(it.comment)
} }
...@@ -126,7 +178,7 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -126,7 +178,7 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
tab_layout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{ tab_layout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
var text:String? = tab?.text.toString().trim() ?: return var text:String? = tab?.text.toString().trim()
val spStr = SpannableString(text) val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.BOLD) val styleSpan = StyleSpan(Typeface.BOLD)
spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE) spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
...@@ -134,7 +186,7 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -134,7 +186,7 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
} }
override fun onTabUnselected(tab: TabLayout.Tab?) { override fun onTabUnselected(tab: TabLayout.Tab?) {
var text:String? = tab?.text.toString().trim() ?: return var text:String? = tab?.text.toString().trim()
val spStr = SpannableString(text) val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.NORMAL) val styleSpan = StyleSpan(Typeface.NORMAL)
spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE) spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
...@@ -155,4 +207,45 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -155,4 +207,45 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
} }
} }
private var runnable = object : RunnableWithParams {
var videoUrl:String? = null
var imageUrl:String? = null
override fun setParams(videoUrl: String, imageUrl: String) {
this.videoUrl = videoUrl
this.imageUrl = imageUrl
}
override fun run() {
mMediaPlayer = MediaPlayer()
mMediaPlayer?.setDataSource(videoUrl)
mMediaPlayer?.setSurface(mSurface)
mMediaPlayer?.prepareAsync()
mMediaPlayer?.setVolume(0F, 0F)
mMediaPlayer?.setOnPreparedListener {
iv_video_background.visibility = GONE
mMediaPlayer?.start()
}
mMediaPlayer?.setOnErrorListener { mp, what, extra ->
Glide.with(this@HomeMuseView)
.load(videoUrl)
.into(iv_video_background)
true
}
mMediaPlayer?.setOnCompletionListener {
mMediaPlayer?.start()
}
}
}
interface RunnableWithParams:Runnable {
fun setParams(videoUrl:String,imageUrl:String){
}
}
} }
\ No newline at end of file
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextureView
<com.yidianling.home.widget.AdaptiveVideoView
android:id="@+id/video_view" android:id="@+id/video_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
...@@ -63,7 +63,7 @@ dependencies { ...@@ -63,7 +63,7 @@ dependencies {
// solve build problem // solve build problem
// cannot access 'androidx.lifecycle.hasdefaultviewmodelproviderfactory' // cannot access 'androidx.lifecycle.hasdefaultviewmodelproviderfactory'
// Comment out when compiling // Comment out when compiling
// implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "com.alibaba:arouter-api:$arouter_api" implementation "com.alibaba:arouter-api:$arouter_api"
// 注意此处的依赖方式:kotlin中使用和java中使用方式有不同 // 注意此处的依赖方式:kotlin中使用和java中使用方式有不同
......
...@@ -17,8 +17,10 @@ import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageVi ...@@ -17,8 +17,10 @@ import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageVi
import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode
import com.ydl.ydlcommon.utils.Utils import com.ydl.ydlcommon.utils.Utils
import com.ydl.ydlcommon.utils.remind.ToastHelper.Companion.show import com.ydl.ydlcommon.utils.remind.ToastHelper.Companion.show
import com.yidianling.common.tools.ToastUtil
import com.yidianling.home.http.MuseHttp import com.yidianling.home.http.MuseHttp
import com.yidianling.muse.R import com.yidianling.muse.R
import com.yidianling.muse.bean.MeditationPlayModuleBean
import com.yidianling.muse.helper.MediaPlayerManager import com.yidianling.muse.helper.MediaPlayerManager
import com.yidianling.muse.utils.MediaPlayerTimeUtil import com.yidianling.muse.utils.MediaPlayerTimeUtil
import com.yidianling.muse.widget.QuitMeditationDialog import com.yidianling.muse.widget.QuitMeditationDialog
...@@ -53,8 +55,8 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -53,8 +55,8 @@ class PlayMeditationActivity : BaseActivity() {
private var mediaListLink: String? = null private var mediaListLink: String? = null
private val newPath = private var meditations = mutableListOf<MeditationPlayModuleBean.MeditationDetail>()
"http://file.diyring.cc/UserRingWorksFile/0/50284096.mp3" private var currentMeditation: MeditationPlayModuleBean.MeditationDetail? = null
private var shareTitle = "" private var shareTitle = ""
private var shareUrl = "" private var shareUrl = ""
...@@ -118,10 +120,10 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -118,10 +120,10 @@ class PlayMeditationActivity : BaseActivity() {
.subscribe(Consumer { .subscribe(Consumer {
if (it.code.equals("200") && it.data != null) { if (it.code.equals("200") && it.data != null) {
val module = it.data val module = it.data
val currentMediaId = module.mediaId mediaId = module.mediaId
mediaListLink = module.playDetailUrl mediaListLink = module.playDetailUrl
module.mediaList?.forEach { meditationPlayBean -> module.mediaList?.forEach { meditationPlayBean ->
if (meditationPlayBean.mediaId == currentMediaId) { if (meditationPlayBean.mediaId == mediaId) {
mediaId = module?.mediaId ?: 0L mediaId = module?.mediaId ?: 0L
val title = meditationPlayBean.title ?: "未知标题" val title = meditationPlayBean.title ?: "未知标题"
val desc = meditationPlayBean.desc ?: "" val desc = meditationPlayBean.desc ?: ""
...@@ -173,9 +175,18 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -173,9 +175,18 @@ class PlayMeditationActivity : BaseActivity() {
if (it.code.equals("200") && it.data != null) { if (it.code.equals("200") && it.data != null) {
val module = it.data val module = it.data
val currentMediaId = module.mediaId mediaId = module.mediaId
meditations.clear()
module.mediaList?.forEach { meditationPlayBean -> module.mediaList?.forEach { meditationPlayBean ->
if (meditationPlayBean.mediaId == currentMediaId) {
meditations.add(meditationPlayBean)
if (meditationPlayBean.mediaId == mediaId) {
currentMeditation = meditationPlayBean
mediaId = module?.mediaId ?: 0L mediaId = module?.mediaId ?: 0L
val title = meditationPlayBean.title val title = meditationPlayBean.title
val desc = meditationPlayBean.desc ?: "" val desc = meditationPlayBean.desc ?: ""
...@@ -417,56 +428,75 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -417,56 +428,75 @@ class PlayMeditationActivity : BaseActivity() {
} }
exo_prev.setOnClickListener { exo_prev.setOnClickListener {
val currentPosition = meditations.indexOf(currentMeditation)
if (currentPosition > 0){
if (meditationId == null || mediaId == null) return@setOnClickListener if (meditationId == null || mediaId == null) return@setOnClickListener
postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0) postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0)
MediaPlayerManager.getInstance(this)?.setAudioPath(newPath) val meditation = meditations[currentPosition - 1]
isPlaying = if (MediaPlayerManager currentMeditation = meditation
.getInstance(this@PlayMeditationActivity)?.getMediaPlayer()?.isPlaying == true
) { mediaId = meditation.mediaId
exo_play.setImageResource(R.drawable.icon_pause_play) val mediaCoverUrl = meditation.coverImageUrl
if (duration != null) { val mediaUrl = meditation.mediaUrl
seekbar_play_progress.max = duration val currentPosition = meditation.broadcastTime
} val status = meditation.status
mTimer.schedule(object : TimerTask() {
override fun run() { Glide.with(this)
seekbar_play_progress.progress = MediaPlayerManager .load(mediaCoverUrl)
.getInstance(this@PlayMeditationActivity) .into(iv_bg)
?.getMediaPlayer()?.currentPosition ?: 0
} tv_title.text = meditation.title
}, 0, 50) tv_content.text = meditation.desc
true
iv_collect.setImageResource(
if (status == 0) {
R.drawable.icon_play_meditation_collect
} else { } else {
exo_play.setImageResource(R.drawable.icon_pause_meditation) R.drawable.icon_meditation_collected
false }
)
initMediaPlayer(mediaUrl,currentPosition)
}else{
ToastUtil.toastShort("当前已经是第一首")
} }
} }
exo_next.setOnClickListener { exo_next.setOnClickListener {
val currentPosition = meditations.indexOf(currentMeditation)
if (currentPosition < meditations.size - 1){
if (meditationId == null || mediaId == null) return@setOnClickListener if (meditationId == null || mediaId == null) return@setOnClickListener
postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0) postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0)
MediaPlayerManager.getInstance(this)?.setAudioPath(newPath) val meditation = meditations[currentPosition + 1]
isPlaying = if (MediaPlayerManager currentMeditation = meditation
.getInstance(this@PlayMeditationActivity)?.getMediaPlayer()?.isPlaying == true
) { mediaId = meditation.mediaId
exo_play.setImageResource(R.drawable.icon_pause_play) val mediaCoverUrl = meditation.coverImageUrl
if (duration != null) { val mediaUrl = meditation.mediaUrl
seekbar_play_progress.max = duration val currentPosition = meditation.broadcastTime
} val status = meditation.status
mTimer.schedule(object : TimerTask() {
override fun run() { Glide.with(this)
if (!isSeekbarChanging) { .load(mediaCoverUrl)
seekbar_play_progress.progress = MediaPlayerManager .into(iv_bg)
.getInstance(this@PlayMeditationActivity)
?.getMediaPlayer()?.currentPosition ?: 0 tv_title.text = meditation.title
} tv_content.text = meditation.desc
}
}, 0, 50) iv_collect.setImageResource(
true if (status == 0) {
R.drawable.icon_play_meditation_collect
} else { } else {
exo_play.setImageResource(R.drawable.icon_pause_meditation) R.drawable.icon_meditation_collected
false }
)
initMediaPlayer(mediaUrl,currentPosition)
}else{
ToastUtil.toastShort("当前已经是最后一首")
} }
} }
...@@ -565,10 +595,8 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -565,10 +595,8 @@ class PlayMeditationActivity : BaseActivity() {
if (mMediaPlayer?.isPlaying == true) { if (mMediaPlayer?.isPlaying == true) {
exo_play.setImageResource(R.drawable.icon_pause_play) exo_play.setImageResource(R.drawable.icon_pause_play)
true
} else { } else {
exo_play.setImageResource(R.drawable.icon_pause_meditation) exo_play.setImageResource(R.drawable.icon_pause_meditation)
false
} }
val currentPosition = mMediaPlayer?.currentPosition val currentPosition = mMediaPlayer?.currentPosition
...@@ -753,7 +781,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -753,7 +781,7 @@ class PlayMeditationActivity : BaseActivity() {
} }
private fun stopPlay() { private fun stopPlay() {
MediaPlayerManager.getInstance(this)?.stop()
} }
companion object { companion object {
......
package com.yidianling.muse.helper package com.yidianling.muse.helper
import android.content.Context import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
import android.media.MediaPlayer import android.media.MediaPlayer
import android.net.Uri
import kotlin.properties.Delegates import kotlin.properties.Delegates
class MediaPlayerManager private constructor() { class MediaPlayerManager private constructor() {
...@@ -10,9 +11,17 @@ class MediaPlayerManager private constructor() { ...@@ -10,9 +11,17 @@ class MediaPlayerManager private constructor() {
private var listener:OnMediaPlayerManagerListener?=null private var listener:OnMediaPlayerManagerListener?=null
fun setAudioPath(path: String){ fun setAudioPath(path: String){
val attrs = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.build()
mPath = path mPath = path
mMediaPlayer?.reset() mMediaPlayer?.reset()
mMediaPlayer?.setDataSource(mContext, Uri.parse(path)) mMediaPlayer?.setAudioAttributes(attrs)
mMediaPlayer?.setDataSource(path)
mMediaPlayer?.prepareAsync() mMediaPlayer?.prepareAsync()
mMediaPlayer?.setOnPreparedListener { mMediaPlayer?.setOnPreparedListener {
listener?.onPrepared(it) listener?.onPrepared(it)
...@@ -39,10 +48,8 @@ class MediaPlayerManager private constructor() { ...@@ -39,10 +48,8 @@ class MediaPlayerManager private constructor() {
} }
fun stop() { fun stop() {
if (mMediaPlayer?.isPlaying == true) {
mMediaPlayer?.reset() mMediaPlayer?.reset()
} }
}
fun release() { fun release() {
mMediaPlayer?.reset() mMediaPlayer?.reset()
......
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