Commit 87eb5150 by 严久程

课程切换音视频播放问题修复

parent db858acd
......@@ -67,7 +67,8 @@ class CoursePlayActivity : BaseActivity() {
/*******************播放器模块*******************/
//音视频模块
var play_view: PlayViewInterface? = null
var playAudioView: PlayViewInterface? = null
var playVideoView: PlayViewInterface? = null
//当前播放模式 0音频播放 1视频播放
var play_type = 0
......@@ -241,22 +242,25 @@ class CoursePlayActivity : BaseActivity() {
0
)
if (play_type == 1) {
//暂停状态 开始播放
(play_view as CoursePlayItemViewVideo)?.play(position)
index = position
if (playList[index].mediaType == 2) {
play_type = 1
(playVideoView as CoursePlayItemViewVideo)?.play(position)
}
if (play_type == 0) {
if (playList[index].mediaType == 1) {
play_type = 0
if (RxNetTool.isWifi(this@CoursePlayActivity)) {
(play_view as CoursePlayItemViewAudio).playView!!.play(
(playAudioView as CoursePlayItemViewAudio).playView!!.play(
position
)
} else {
if ((play_view as CoursePlayItemViewAudio).hasEnsureNetStatus) {
(play_view as CoursePlayItemViewAudio).playView!!.play(
if ((playAudioView as CoursePlayItemViewAudio).hasEnsureNetStatus) {
(playAudioView as CoursePlayItemViewAudio).playView!!.play(
position
)
} else {
(play_view as CoursePlayItemViewAudio).setData(
(playAudioView as CoursePlayItemViewAudio).setData(
position,
playList,
courPlayBean!!.courseExtra,
......@@ -265,7 +269,6 @@ class CoursePlayActivity : BaseActivity() {
}
}
}
index = position
adapter?.notifyDataSetChanged()
}
}
......@@ -337,10 +340,6 @@ class CoursePlayActivity : BaseActivity() {
) {
receiverPlayUrl = AudioPlayer.get().playMusic?.path
}
// if (YDLMusicHelper.isCoursePlaying() && TextUtils.isEmpty(receiverPlayUrl)) {
// receiverPlayUrl = YDLMusicHelper.getCurrentData()?.url
// }
} catch (e: Exception) {
}
......@@ -426,24 +425,35 @@ class CoursePlayActivity : BaseActivity() {
}
}
} catch (e: Exception) {
e.printStackTrace()
}
if (play_type == 1) {//视频
play_view = CoursePlayItemViewVideo.create(this, play_type)
(play_view as CoursePlayItemViewVideo).hasEnsureNetStatus = isCancelNetCheck
frame_play.addView(play_view as CoursePlayItemViewVideo)
} else {//音频
play_view = CoursePlayItemViewAudio.create(this, play_type)
(play_view as CoursePlayItemViewAudio).hasEnsureNetStatus = isCancelNetCheck
frame_play.addView(play_view as CoursePlayItemViewAudio)
}
// if (play_type == 1) {//视频
// playVideoView = CoursePlayItemViewVideo.create(this, play_type)
// (playVideoView as CoursePlayItemViewVideo).hasEnsureNetStatus = isCancelNetCheck
// frame_video_play.addView(playVideoView as CoursePlayItemViewVideo)
// } else {//音频
// playAudioView = CoursePlayItemViewAudio.create(this, play_type)
// (playAudioView as CoursePlayItemViewAudio).hasEnsureNetStatus = isCancelNetCheck
// frame_audio_play.addView(playAudioView as CoursePlayItemViewVideo)
// }
//视频
playVideoView = CoursePlayItemViewVideo.create(this, play_type)
(playVideoView as CoursePlayItemViewVideo).hasEnsureNetStatus = isCancelNetCheck
frame_video_play.addView(playVideoView as CoursePlayItemViewVideo)
//音频
playAudioView = CoursePlayItemViewAudio.create(this, play_type)
(playAudioView as CoursePlayItemViewAudio).hasEnsureNetStatus = isCancelNetCheck
frame_audio_play.addView(playAudioView as CoursePlayItemViewVideo)
if (play_type == 0) {
play_view?.setData(index, playList, bean.courseExtra, from)
playAudioView?.setData(index, playList, bean.courseExtra, from)
frame_audio_play.visibility = View.VISIBLE
} else {
play_view?.setData(index, playList, bean.courseExtra, from)
playVideoView?.setData(index, playList, bean.courseExtra, from)
frame_audio_play.visibility = View.GONE
}
if (videoView != null && play_type == 1 && fullScreen == 1) {
......@@ -474,13 +484,13 @@ class CoursePlayActivity : BaseActivity() {
//设置播放列表数据
private fun setPlayList(bean: CourseMediaDetailBean) {
if (bean.voiceSample.courseMedia != null && bean.voiceSample.courseMedia.isNotEmpty()) {
if (bean.voiceSample.courseMedia.isNotEmpty()) {
for (voiceSampleData in bean.voiceSample.courseMedia) {
voiceSampleData.isDemo = true
playList.add(voiceSampleData)
}
}
if (bean.voiceWhole.courseMedia != null && bean.voiceWhole.courseMedia.isNotEmpty()) {
if (bean.voiceWhole.courseMedia.isNotEmpty()) {
for (voiceCourseData in bean.voiceWhole.courseMedia) {
playList.add(voiceCourseData)
}
......@@ -491,6 +501,20 @@ class CoursePlayActivity : BaseActivity() {
fun updatePlayingListStatus(index: Int) {
if (index < playList.size && this.index != index) {
if (playList[index].mediaType == 1) {
frame_video_play.visibility = View.GONE
frame_audio_play.visibility = View.VISIBLE
(playAudioView as CoursePlayItemViewAudio).playView?.play(
index
)
}
if (playList[index].mediaType == 2) {
frame_video_play.visibility = View.VISIBLE
frame_audio_play.visibility = View.GONE
(playVideoView as CoursePlayItemViewVideo)?.play(index)
}
this.index = index
adapter?.notifyDataSetChanged()
}
......@@ -573,18 +597,21 @@ class CoursePlayActivity : BaseActivity() {
private fun toTrend(share: ShareData) {
var url = if (TextUtils.isEmpty(share.url)) share.share_url else share.url
CourseIn.getDynamicService().publishArticleToTrend(this@CoursePlayActivity, url!!, share.cover!!, share.title!!)
CourseIn.getDynamicService()
.publishArticleToTrend(this@CoursePlayActivity, url!!, share.cover!!, share.title!!)
}
override fun onPause() {
super.onPause()
videoView?.onPause()
play_view?.onPause()
playVideoView?.onPause()
playAudioView?.onPause()
}
override fun onResume() {
super.onResume()
play_view?.onResume()
playVideoView?.onResume()
playAudioView?.onResume()
if (PlayerFloatHelper.isShow(this)) {
PlayerFloatHelper.removeView(this)
......@@ -653,7 +680,7 @@ class CoursePlayActivity : BaseActivity() {
VideoFloatHelper.setVideoInfo(
course_id.toString(),
(play_view as CoursePlayItemViewVideo).videoUrl!!,
(playVideoView as CoursePlayItemViewVideo).videoUrl!!,
true
)
VideoFloatHelper.defaultShowPattern = ShowPattern.FOREGROUND
......@@ -691,7 +718,9 @@ class CoursePlayActivity : BaseActivity() {
override fun onDestroy() {
super.onDestroy()
videoView?.onDestroy()
play_view?.onDestroy()
play_view = null
playAudioView?.onDestroy()
playVideoView?.onDestroy()
playAudioView = null
playVideoView = null
}
}
......@@ -61,7 +61,10 @@ class CoursePlayItemViewVideo : RelativeLayout, PlayViewInterface {
initView()
wakeLock = (activity!!.getSystemService(Context.POWER_SERVICE) as PowerManager)
.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE, "CoursePlayItemViewVideo")
.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE,
"CoursePlayItemViewVideo"
)
}
override fun onNewIntent() {
......@@ -140,20 +143,20 @@ class CoursePlayItemViewVideo : RelativeLayout, PlayViewInterface {
//未购买,判断是否是试听课程
//即未购买,也不是试听,弹窗提示
CommonDialog(activity)
.setMessage("\n购买课程,获取完整课程内容\n")
.setLeftOnclick("放弃") {
}
.setRightClick("购买") {
//跳转支付页
activity?.addCourseOrder()
}
.setCancelAble(false)
.show()
.setMessage("\n购买课程,获取完整课程内容\n")
.setLeftOnclick("放弃") {
}
.setRightClick("购买") {
//跳转支付页
activity?.addCourseOrder()
}
.setCancelAble(false)
.show()
}
}
if (canPlay) {
PlayerFloatHelper.playingType=PlayTypeEnum.PLAY_TYPE_COURSE
PlayerFloatHelper.playingType = PlayTypeEnum.PLAY_TYPE_COURSE
var url = playList[index].url
......@@ -164,63 +167,75 @@ class CoursePlayItemViewVideo : RelativeLayout, PlayViewInterface {
var hisTime = PlayProgressUtil.getProgress(context, url)
try {
activity?.videoView = PlayerView(activity)
.setScaleType(PlayStateParams.fitparent)
.hideMenu(true)
.hideRotation(true)
.setNetWorkTypeTie(!hasEnsureNetStatus)
.hideBack(true)
.hideSteam(true)
.setAutoReConnect(true, 3)
.forbidTouch(false)
.setOnInfoListener(object : IMediaPlayer.OnInfoListener {
override fun onInfo(mp: IMediaPlayer, what: Int, extra: Int): Boolean {
LogUtil.e("课程播放--状态-$what")
if (what == PlayStateParams.STATE_PAUSED) {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.rl_play_pause_layout).visibility = View.VISIBLE
} else {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.rl_play_pause_layout).visibility = View.GONE
}
.setScaleType(PlayStateParams.fitparent)
.hideMenu(true)
.hideRotation(true)
.setNetWorkTypeTie(!hasEnsureNetStatus)
.hideBack(true)
.hideSteam(true)
.setAutoReConnect(true, 3)
.forbidTouch(false)
.setOnInfoListener(object : IMediaPlayer.OnInfoListener {
override fun onInfo(mp: IMediaPlayer, what: Int, extra: Int): Boolean {
LogUtil.e("课程播放--状态-$what")
if (what == PlayStateParams.STATE_PAUSED) {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.rl_play_pause_layout)
.visibility = View.VISIBLE
} else {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.rl_play_pause_layout)
.visibility = View.GONE
}
if (what == PlayStateParams.STATE_PLAYING) {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.app_video_loading).visibility = View.GONE
}
if (what == PlayStateParams.MEDIA_INFO_BUFFERING_END
|| what == PlayStateParams.MEDIA_INFO_AUDIO_RENDERING_START
|| what == PlayStateParams.MEDIA_INFO_VIDEO_RENDERING_START
|| what == PlayStateParams.STATE_PLAYING
|| what == IMediaPlayer.MEDIA_INFO_VIDEO_SEEK_RENDERING_START
) {
activity?.isVideoPlay = true
this@CoursePlayItemViewVideo.findViewById<View>(R.id.ll_bg).visibility = View.GONE
this@CoursePlayItemViewVideo.findViewById<View>(R.id.ll_loading).visibility = View.GONE
this@CoursePlayItemViewVideo.findViewById<View>(R.id.app_video_loading).visibility = View.GONE
}
if (what == PlayStateParams.STATE_PLAYING) {
this@CoursePlayItemViewVideo.findViewById<View>(R.id.app_video_loading)
.visibility = View.GONE
}
if (what == PlayStateParams.MEDIA_INFO_BUFFERING_END
|| what == PlayStateParams.MEDIA_INFO_AUDIO_RENDERING_START
|| what == PlayStateParams.MEDIA_INFO_VIDEO_RENDERING_START
|| what == PlayStateParams.STATE_PLAYING
|| what == IMediaPlayer.MEDIA_INFO_VIDEO_SEEK_RENDERING_START
) {
activity?.isVideoPlay = true
this@CoursePlayItemViewVideo.findViewById<View>(R.id.ll_bg)
.visibility = View.GONE
this@CoursePlayItemViewVideo.findViewById<View>(R.id.ll_loading)
.visibility = View.GONE
this@CoursePlayItemViewVideo.findViewById<View>(R.id.app_video_loading)
.visibility = View.GONE
}
if (what == PlayStateParams.STATE_COMPLETED) {
isVideoPlaying = false
PlayProgressUtil.saveProgress(this@CoursePlayItemViewVideo.activity, videoUrl, 0)
if (playList.size - 1 > this@CoursePlayItemViewVideo.index) {
//播放下一曲
play(this@CoursePlayItemViewVideo.index + 1)
activity!!.updatePlayingListStatus(this@CoursePlayItemViewVideo.index)
}
} else {
isVideoPlaying = true
if (what == PlayStateParams.STATE_COMPLETED) {
isVideoPlaying = false
PlayProgressUtil.saveProgress(
this@CoursePlayItemViewVideo.activity,
videoUrl,
0
)
if (playList.size - 1 > this@CoursePlayItemViewVideo.index) {
//播放下一曲
// play(this@CoursePlayItemViewVideo.index + 1)
this@CoursePlayItemViewVideo.index =
this@CoursePlayItemViewVideo.index + 1
activity!!.updatePlayingListStatus(this@CoursePlayItemViewVideo.index)
}
return true
}
})
.showThumbnail { ivThumbnail ->
run {
ivThumbnail.alpha = 0.5f
GlideApp.with(context)
.load(courseExtra!!.pic)
.into(ivThumbnail)
} else {
isVideoPlaying = true
}
return true
}
})
.showThumbnail { ivThumbnail ->
run {
ivThumbnail.alpha = 0.5f
GlideApp.with(context)
.load(courseExtra!!.pic)
.into(ivThumbnail)
}
.setPlaySource(url)
.startPlay()
.seekTo(hisTime)
}
.setPlaySource(url)
.startPlay()
.seekTo(hisTime)
val layout = activity?.window?.attributes
layout?.screenBrightness = -1f
activity?.window?.attributes = layout
......@@ -234,7 +249,12 @@ class CoursePlayItemViewVideo : RelativeLayout, PlayViewInterface {
/**
* 设置显示数据
*/
override fun setData(index: Int, list: ArrayList<CourseMediaBean>, courseExtra: CourseExtraBean, from: Int) {
override fun setData(
index: Int,
list: ArrayList<CourseMediaBean>,
courseExtra: CourseExtraBean,
from: Int
) {
if (list.isEmpty()) return
playList.clear()
......
......@@ -37,7 +37,22 @@
android:id="@+id/frame_play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent" />
android:background="@color/transparent">
<FrameLayout
android:id="@+id/frame_audio_play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:visibility="gone" />
<FrameLayout
android:id="@+id/frame_video_play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:visibility="gone" />
</FrameLayout>
<RelativeLayout
android:id="@+id/title_bar_layout"
......
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