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 {
"m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08",
"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-dynamic" : "0.0.7.73",
"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-course" : "0.0.43.37",
......@@ -94,12 +94,12 @@ ext {
"m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08",
"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-dynamic" : "0.0.7.73",
"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-course" : "0.0.43.37",
//-------------- 业务模块 API 层 --------------
......
......@@ -64,6 +64,10 @@ class MeditationTypeAdapter(
holder.cvLayout?.setOnClickListener {
if (meditationType == 0){
if (Utils.isFastClick()) {
//防止连击
return@setOnClickListener
}
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
......@@ -79,6 +83,9 @@ class MeditationTypeAdapter(
//防止连击
return@setOnClickListener
}
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
val homeLink = "${homeLink}mark=$mark&cateId=$cateId&meditationId=${data[position].meditationId}"
if (!homeLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(homeLink, null))
......@@ -92,6 +99,9 @@ class MeditationTypeAdapter(
//防止连击
return@setOnClickListener
}
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
val moreLink = "${moreLink}mark=$mark&cateId=$cateId"
if (!moreLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(moreLink, null))
......
......@@ -3,11 +3,15 @@ package com.yidianling.home.ui.view
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.graphics.SurfaceTexture
import android.graphics.Typeface
import android.media.MediaPlayer
import android.os.Handler
import android.text.SpannableString
import android.text.Spanned
import android.text.style.StyleSpan
import android.view.Surface
import android.view.TextureView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
......@@ -18,13 +22,16 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.utils.Utils
import com.yidianling.home.MeditationViewPagerAdapter
import com.yidianling.home.R
import com.yidianling.home.constract.HomeViewConfig
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.MeditationModuleBean
import com.yidianling.user.api.service.IUserService
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>
......@@ -36,6 +43,11 @@ import kotlinx.android.synthetic.ydl.home_muse_view.view.*
class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEvent?) :
LinearLayout(mContext) {
private var mSurface: Surface? = null
private var mSurfaceTexture: SurfaceTexture? = null
private var mMediaPlayer:MediaPlayer? = null
private val meditationTitles = mutableListOf<String>()
init {
......@@ -67,6 +79,9 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
//防止连击
return@setOnClickListener
}
if (!ModularServiceManager.provide(IUserService::class.java).loginByOneKeyLogin(context,true)) {
return@setOnClickListener
}
if (!moreLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(moreLink, null))
}
......@@ -79,11 +94,11 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
if (bean.mditationIndexInfo?.desc.isNullOrBlank()){
"无常的日子里,呼吸间拾起力量"
}else{
bean?.mditationIndexInfo?.desc
bean.mditationIndexInfo?.desc
}
tv_meditation_slogan.text = slogan
val videoUrl = bean?.mditationIndexInfo?.videoLink
val videoUrl = bean.mditationIndexInfo?.videoLink
if (videoUrl.isNullOrBlank()){
Glide.with(this)
......@@ -94,31 +109,68 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
.load(bean.mditationIndexInfo?.mditationIndexUrl)
.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)
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)
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
// mSurface = null
// mSurfaceTexture = null
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)
}
......@@ -126,7 +178,7 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
tab_layout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
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 styleSpan = StyleSpan(Typeface.BOLD)
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
}
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 styleSpan = StyleSpan(Typeface.NORMAL)
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
}
}
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 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yidianling.home.widget.AdaptiveVideoView
<TextureView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
......
......@@ -63,7 +63,7 @@ dependencies {
// solve build problem
// cannot access 'androidx.lifecycle.hasdefaultviewmodelproviderfactory'
// 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"
// 注意此处的依赖方式:kotlin中使用和java中使用方式有不同
......
......@@ -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.Utils
import com.ydl.ydlcommon.utils.remind.ToastHelper.Companion.show
import com.yidianling.common.tools.ToastUtil
import com.yidianling.home.http.MuseHttp
import com.yidianling.muse.R
import com.yidianling.muse.bean.MeditationPlayModuleBean
import com.yidianling.muse.helper.MediaPlayerManager
import com.yidianling.muse.utils.MediaPlayerTimeUtil
import com.yidianling.muse.widget.QuitMeditationDialog
......@@ -53,8 +55,8 @@ class PlayMeditationActivity : BaseActivity() {
private var mediaListLink: String? = null
private val newPath =
"http://file.diyring.cc/UserRingWorksFile/0/50284096.mp3"
private var meditations = mutableListOf<MeditationPlayModuleBean.MeditationDetail>()
private var currentMeditation: MeditationPlayModuleBean.MeditationDetail? = null
private var shareTitle = ""
private var shareUrl = ""
......@@ -118,10 +120,10 @@ class PlayMeditationActivity : BaseActivity() {
.subscribe(Consumer {
if (it.code.equals("200") && it.data != null) {
val module = it.data
val currentMediaId = module.mediaId
mediaId = module.mediaId
mediaListLink = module.playDetailUrl
module.mediaList?.forEach { meditationPlayBean ->
if (meditationPlayBean.mediaId == currentMediaId) {
if (meditationPlayBean.mediaId == mediaId) {
mediaId = module?.mediaId ?: 0L
val title = meditationPlayBean.title ?: "未知标题"
val desc = meditationPlayBean.desc ?: ""
......@@ -173,9 +175,18 @@ class PlayMeditationActivity : BaseActivity() {
if (it.code.equals("200") && it.data != null) {
val module = it.data
val currentMediaId = module.mediaId
mediaId = module.mediaId
meditations.clear()
module.mediaList?.forEach { meditationPlayBean ->
if (meditationPlayBean.mediaId == currentMediaId) {
meditations.add(meditationPlayBean)
if (meditationPlayBean.mediaId == mediaId) {
currentMeditation = meditationPlayBean
mediaId = module?.mediaId ?: 0L
val title = meditationPlayBean.title
val desc = meditationPlayBean.desc ?: ""
......@@ -417,56 +428,75 @@ class PlayMeditationActivity : BaseActivity() {
}
exo_prev.setOnClickListener {
val currentPosition = meditations.indexOf(currentMeditation)
if (currentPosition > 0){
if (meditationId == null || mediaId == null) return@setOnClickListener
postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0)
MediaPlayerManager.getInstance(this)?.setAudioPath(newPath)
isPlaying = if (MediaPlayerManager
.getInstance(this@PlayMeditationActivity)?.getMediaPlayer()?.isPlaying == true
) {
exo_play.setImageResource(R.drawable.icon_pause_play)
if (duration != null) {
seekbar_play_progress.max = duration
}
mTimer.schedule(object : TimerTask() {
override fun run() {
seekbar_play_progress.progress = MediaPlayerManager
.getInstance(this@PlayMeditationActivity)
?.getMediaPlayer()?.currentPosition ?: 0
}
}, 0, 50)
true
val meditation = meditations[currentPosition - 1]
currentMeditation = meditation
mediaId = meditation.mediaId
val mediaCoverUrl = meditation.coverImageUrl
val mediaUrl = meditation.mediaUrl
val currentPosition = meditation.broadcastTime
val status = meditation.status
Glide.with(this)
.load(mediaCoverUrl)
.into(iv_bg)
tv_title.text = meditation.title
tv_content.text = meditation.desc
iv_collect.setImageResource(
if (status == 0) {
R.drawable.icon_play_meditation_collect
} else {
exo_play.setImageResource(R.drawable.icon_pause_meditation)
false
R.drawable.icon_meditation_collected
}
)
initMediaPlayer(mediaUrl,currentPosition)
}else{
ToastUtil.toastShort("当前已经是第一首")
}
}
exo_next.setOnClickListener {
val currentPosition = meditations.indexOf(currentMeditation)
if (currentPosition < meditations.size - 1){
if (meditationId == null || mediaId == null) return@setOnClickListener
postPlayRecord(isQuit = 0, playTime = 0, isComplete = 0)
MediaPlayerManager.getInstance(this)?.setAudioPath(newPath)
isPlaying = if (MediaPlayerManager
.getInstance(this@PlayMeditationActivity)?.getMediaPlayer()?.isPlaying == true
) {
exo_play.setImageResource(R.drawable.icon_pause_play)
if (duration != null) {
seekbar_play_progress.max = duration
}
mTimer.schedule(object : TimerTask() {
override fun run() {
if (!isSeekbarChanging) {
seekbar_play_progress.progress = MediaPlayerManager
.getInstance(this@PlayMeditationActivity)
?.getMediaPlayer()?.currentPosition ?: 0
}
}
}, 0, 50)
true
val meditation = meditations[currentPosition + 1]
currentMeditation = meditation
mediaId = meditation.mediaId
val mediaCoverUrl = meditation.coverImageUrl
val mediaUrl = meditation.mediaUrl
val currentPosition = meditation.broadcastTime
val status = meditation.status
Glide.with(this)
.load(mediaCoverUrl)
.into(iv_bg)
tv_title.text = meditation.title
tv_content.text = meditation.desc
iv_collect.setImageResource(
if (status == 0) {
R.drawable.icon_play_meditation_collect
} else {
exo_play.setImageResource(R.drawable.icon_pause_meditation)
false
R.drawable.icon_meditation_collected
}
)
initMediaPlayer(mediaUrl,currentPosition)
}else{
ToastUtil.toastShort("当前已经是最后一首")
}
}
......@@ -565,10 +595,8 @@ class PlayMeditationActivity : BaseActivity() {
if (mMediaPlayer?.isPlaying == true) {
exo_play.setImageResource(R.drawable.icon_pause_play)
true
} else {
exo_play.setImageResource(R.drawable.icon_pause_meditation)
false
}
val currentPosition = mMediaPlayer?.currentPosition
......@@ -753,7 +781,7 @@ class PlayMeditationActivity : BaseActivity() {
}
private fun stopPlay() {
MediaPlayerManager.getInstance(this)?.stop()
}
companion object {
......
package com.yidianling.muse.helper
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
import android.media.MediaPlayer
import android.net.Uri
import kotlin.properties.Delegates
class MediaPlayerManager private constructor() {
......@@ -10,9 +11,17 @@ class MediaPlayerManager private constructor() {
private var listener:OnMediaPlayerManagerListener?=null
fun setAudioPath(path: String){
val attrs = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.build()
mPath = path
mMediaPlayer?.reset()
mMediaPlayer?.setDataSource(mContext, Uri.parse(path))
mMediaPlayer?.setAudioAttributes(attrs)
mMediaPlayer?.setDataSource(path)
mMediaPlayer?.prepareAsync()
mMediaPlayer?.setOnPreparedListener {
listener?.onPrepared(it)
......@@ -39,10 +48,8 @@ class MediaPlayerManager private constructor() {
}
fun stop() {
if (mMediaPlayer?.isPlaying == true) {
mMediaPlayer?.reset()
}
}
fun release() {
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