Commit 91a4261a by 王佳洋

1,音频播放功能查漏补缺

2,音视频悬浮窗代码优化
parent 69bc9942
......@@ -7,6 +7,8 @@ package com.yidianling.course.bean
* @Company 壹点灵
* @date 2019/7/11
*/
const val COURSE_AUDIO = 1
const val COURSE_VIDEO = 2
data class CourseMediaBean(
/**
......@@ -19,6 +21,8 @@ data class CourseMediaBean(
var doctorName: String,
/**
* 资料类型 1.音频 2.视频 ,
* @see COURSE_AUDIO
* @see COURSE_VIDEO
*/
var mediaType: Int,
/**
......
......@@ -34,6 +34,7 @@ import com.yidianling.common.tools.ToastUtil
import com.yidianling.course.BuildConfig
import com.yidianling.course.CourseConstants
import com.yidianling.course.R
import com.yidianling.course.bean.COURSE_AUDIO
import com.yidianling.course.bean.CourseExtraBean
import com.yidianling.course.bean.CourseMediaBean
import com.yidianling.course.bean.CourseMediaDetailBean
......@@ -195,7 +196,7 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
if (!it.isDemo && !isBuy) {
if (AudioPlayer.get().isPlaying) AudioPlayer.get().pausePlayer()
buyCourseTipDialog()
} else if (it.mediaType == 1) {
} else if (it.mediaType == COURSE_AUDIO) {
return true
}
}
......@@ -228,6 +229,7 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
val hashMap = HashMap<String, String>()
hashMap["course_id"] = mCourseId.toString()
hashMap["media_type"] = COURSE_AUDIO.toString()
PlayerFloatHelper.playTempData.putAll(hashMap)
}
return true
......
......@@ -8,10 +8,12 @@ import com.alibaba.android.arouter.facade.annotation.Route
import com.ydl.course.api.ICourseService
import com.ydl.media.audio.AudioPlayer
import com.ydl.media.view.PlayerFloatHelper
import com.yidianling.course.bean.COURSE_AUDIO
import com.yidianling.course.courseNew.CourseTopicActivity
import com.yidianling.course.courseNew.mine.MyCourseActivity
import com.yidianling.course.coursePlay.AudioPlayActivity
import com.yidianling.course.coursePlay.CourseCommentActivity
import com.yidianling.course.coursePlay.CoursePlayActivity
import com.yidianling.course.coursePlay.CourseReplyListActivity
import com.yidianling.course.flutterPlugin.CourseSendPlugin
import com.yidianling.course.lifeCallback.CoursePlayLifecycle
......@@ -60,8 +62,11 @@ class CourseServiceImp : ICourseService {
}
override fun startCoursePlayActivity(activity: Activity, courseId: Int, coursePlayUrl: String?, from: Int, mediaType: String?) {
// val intent = Intent(activity, CoursePlayActivity::class.java)
val intent = Intent(activity, AudioPlayActivity::class.java)
val intent = if (COURSE_AUDIO.toString() == mediaType) {
Intent(activity, AudioPlayActivity::class.java)
} else {
Intent(activity, CoursePlayActivity::class.java)
}
intent.putExtra("course_id", courseId)
intent.putExtra("coursePlayUrl", coursePlayUrl)
intent.putExtra("from", from)
......
......@@ -188,9 +188,20 @@ class PlayerFloatHelper {
}
fun startCoursePlayActivity(context: Context?, from: Int, fullScreen: Int = 0, coursePlayUrl: String? = "", isFromFloatView: Boolean = false) {
val courseId = playTempData["course_id"]?.toInt() ?: 0
if ("1" == playTempData["media_type"]) { // 音频
ARouter.getInstance()
.build("/course/audioPlay")
.withInt("course_id", courseId)
.withString("coursePlayUrl", coursePlayUrl)
.withInt("from", from)
.withBoolean("isFromFloatView", isFromFloatView)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.navigation()
} else {
ARouter.getInstance()
.build("/course/play")
.withInt("course_id", playTempData["course_id"]?.toInt()?:0)
.withInt("course_id", courseId)
.withInt("course_type", 0)
.withString("coursePlayUrl", coursePlayUrl)
.withInt("from", from)
......@@ -199,6 +210,7 @@ class PlayerFloatHelper {
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.navigation()
}
}
fun startFMPlayActivity(context: Context?) {
val bundle = Bundle()
......
......@@ -5,7 +5,6 @@ import android.content.Context
import android.os.Handler
import android.os.Message
import android.text.TextUtils
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
......@@ -17,19 +16,18 @@ import com.ydl.media.audio.OnPlayerEventListener
import com.ydl.media.audio.model.Music
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_image.transform.GlideRoundTransform
import com.ydl.ydlcommon.utils.statusBar.StatusBarUtil
import java.util.*
import java.util.concurrent.CopyOnWriteArraySet
class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
private var mTouchStartX: Float = 0.toFloat()
private var mTouchStartY: Float = 0.toFloat()
private var mCurrX: Float = 0.toFloat()
private var mCurrY: Float = 0.toFloat()
private var mTouchDownX: Float = 0.toFloat()
private var mTouchDownY: Float = 0.toFloat()
private var mTouchX: Float = 0.toFloat()
private var mTouchY: Float = 0.toFloat()
private var playState: ImageView? = null
private var mAudioLayout: LinearLayout? = null
private var mInfoLayout: RelativeLayout? = null
private var playClose: ImageView? = null
private var playHead: ImageView? = null
private var titleView: TextView? = null
......@@ -54,7 +52,8 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
private var listeners: CopyOnWriteArraySet<FloatViewPlayListener> = CopyOnWriteArraySet()
private var mStateChangeListener: OnPlayerEventListener? = null
private var playData: HashMap<String, String> = hashMapOf<String, String>()
private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(mContext)
init {
init(context)
......@@ -74,8 +73,6 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
wm = getContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager
mTouchSlop = (ViewConfiguration.get(getContext()).scaledTouchSlop + 8) * 3
val view = View.inflate(context, R.layout.item_playing_float_btn, this)
mAudioLayout = view.findViewById(R.id.ll_audio_layout)
mInfoLayout = view.findViewById(R.id.rl_info)
playHead = view.findViewById(R.id.play_head)
playState = view.findViewById(R.id.play_state)
playClose = view.findViewById(R.id.play_close)
......@@ -97,23 +94,23 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
myHandler = MyHandler()
playHead!!.setOnTouchListener { _, event ->
mCurrX = event.rawX
mCurrY = event.rawY - 25
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop || Math.abs(event.y - mTouchStartY) > mTouchSlop) {
if (Math.abs(event.x - mTouchDownX) > mTouchSlop || Math.abs(event.y - mTouchDownY) > mTouchSlop) {
updateViewPosition()
isMove = true
}
}
MotionEvent.ACTION_UP -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop ||
Math.abs(event.y - mTouchStartY) > mTouchSlop || isMove
if (Math.abs(event.x - mTouchDownX) > mTouchSlop ||
Math.abs(event.y - mTouchDownY) > mTouchSlop || isMove
) {
updateViewPosition()
} else {
......@@ -124,31 +121,31 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
}
}
isMove = false
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
true
}
titleView!!.setOnTouchListener { _, event ->
mCurrX = event.rawX
mCurrY = event.rawY - 25
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop || Math.abs(event.y - mTouchStartY) > mTouchSlop) {
if (Math.abs(event.x - mTouchDownX) > mTouchSlop || Math.abs(event.y - mTouchDownY) > mTouchSlop) {
updateViewPosition()
isMove = true
}
}
MotionEvent.ACTION_UP -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop ||
Math.abs(event.y - mTouchStartY) > mTouchSlop || isMove
if (Math.abs(event.x - mTouchDownX) > mTouchSlop ||
Math.abs(event.y - mTouchDownY) > mTouchSlop || isMove
) {
updateViewPosition()
} else {
......@@ -159,31 +156,31 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
}
}
isMove = false
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
true
}
nameView!!.setOnTouchListener { _, event ->
mCurrX = event.rawX
mCurrY = event.rawY - 25
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop || Math.abs(event.y - mTouchStartY) > mTouchSlop) {
if (Math.abs(event.x - mTouchDownX) > mTouchSlop || Math.abs(event.y - mTouchDownY) > mTouchSlop) {
updateViewPosition()
isMove = true
}
}
MotionEvent.ACTION_UP -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop ||
Math.abs(event.y - mTouchStartY) > mTouchSlop || isMove
if (Math.abs(event.x - mTouchDownX) > mTouchSlop ||
Math.abs(event.y - mTouchDownY) > mTouchSlop || isMove
) {
updateViewPosition()
} else {
......@@ -194,31 +191,31 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
}
}
isMove = false
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
true
}
playClose!!.setOnTouchListener { _, event ->
mCurrX = event.rawX
mCurrY = event.rawY - 25
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop || Math.abs(event.y - mTouchStartY) > mTouchSlop) {
if (Math.abs(event.x - mTouchDownX) > mTouchSlop || Math.abs(event.y - mTouchDownY) > mTouchSlop) {
updateViewPosition()
isMove = true
}
}
MotionEvent.ACTION_UP -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop ||
Math.abs(event.y - mTouchStartY) > mTouchSlop || isMove
if (Math.abs(event.x - mTouchDownX) > mTouchSlop ||
Math.abs(event.y - mTouchDownY) > mTouchSlop || isMove
) {
updateViewPosition()
} else {
......@@ -235,31 +232,31 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
}
}
isMove = false
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
true
}
playState!!.setOnTouchListener { _, event ->
mCurrX = event.rawX
mCurrY = event.rawY - 25
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop || Math.abs(event.y - mTouchStartY) > mTouchSlop) {
if (Math.abs(event.x - mTouchDownX) > mTouchSlop || Math.abs(event.y - mTouchDownY) > mTouchSlop) {
updateViewPosition()
isMove = true
}
}
MotionEvent.ACTION_UP -> {
if (Math.abs(event.x - mTouchStartX) > mTouchSlop ||
Math.abs(event.y - mTouchStartY) > mTouchSlop || isMove
if (Math.abs(event.x - mTouchDownX) > mTouchSlop ||
Math.abs(event.y - mTouchDownY) > mTouchSlop || isMove
) {
updateViewPosition()
} else {
......@@ -282,8 +279,8 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
}
}
isMove = false
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
true
......@@ -347,8 +344,6 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
} else {
nameView!!.text = AudioPlayer.get().playMusic?.artist
}
mAudioLayout!!.visibility = View.VISIBLE
}
......@@ -375,20 +370,19 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
override fun onTouchEvent(event: MotionEvent): Boolean {
//获取相对屏幕的坐标,即以屏幕左上角为原点
mCurrX = event.rawX
mCurrY = event.rawY - 25
Log.i("currP", "currX$mCurrX====currY$mCurrY")
mTouchX = event.rawX
mTouchY = event.rawY
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//获取相对View的坐标,即以此View左上角为原点
mTouchStartX = event.x
mTouchStartY = event.y
mTouchDownX = event.x
mTouchDownY = event.y
}
MotionEvent.ACTION_MOVE -> updateViewPosition()
MotionEvent.ACTION_UP -> {
updateViewPosition()
mTouchStartY = 0f
mTouchStartX = mTouchStartY
mTouchDownY = 0f
mTouchDownX = mTouchDownY
}
}
return true
......@@ -396,8 +390,8 @@ class PlayerFloatView(var mContext: Context) : FrameLayout(mContext) {
private fun updateViewPosition() {
//更新浮动窗口位置参数
wmParams.x = (mCurrX - mTouchStartX).toInt()
wmParams.y = (mCurrY - mTouchStartY).toInt()
wmParams.x = (mTouchX - mTouchDownX).toInt()
wmParams.y = (mTouchY - mTouchDownY - mStatusBarHeight).toInt()
wm!!.updateViewLayout(this, wmParams)
}
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll_audio_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/play_float_background"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/play_float_background">
<ImageView
android:id="@+id/play_close"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginEnd="10dp"
android:padding="15dp"
android:src="@drawable/ico_play_float_pause"
android:visibility="visible" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/play_head"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginLeft="12.5dp"
android:src="@drawable/ico_play_float_pic" />
<RelativeLayout
android:id="@+id/rl_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/platform_dp_18"
android:layout_marginRight="@dimen/platform_dp_18"
android:layout_weight="1">
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:src="@drawable/ico_play_float_pic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_title"
app:layout_constraintStart_toEndOf="@id/play_close"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#FFFFFF"
android:textSize="14sp"
app:layout_constraintBottom_toTopOf="@id/tv_name"
app:layout_constraintEnd_toStartOf="@id/play_state"
app:layout_constraintStart_toEndOf="@id/play_head"
tools:text="丁sir说抑郁丁sir说抑郁:像心理学" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_title"
android:maxLines="1"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#BFBFBF"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/tv_title"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toTopOf="parent"
tools:text="丁sir" />
<TextView
android:id="@+id/tv_now_playing_time"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_name"
app:layout_constraintEnd_toEndOf="@id/tv_title"
app:layout_constraintStart_toStartOf="@id/tv_title"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintTop_toBottomOf="@id/tv_name"
android:textColor="#BFBFBF"
android:textSize="10sp"
tools:text="00:06" />
<TextView
android:id="@+id/tv_line_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/tv_now_playing_time"
android:layout_toRightOf="@+id/tv_now_playing_time"
android:text=" / "
android:textColor="#BFBFBF"
android:textSize="10sp" />
<TextView
android:layout_alignBaseline="@id/tv_now_playing_time"
android:id="@+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_title"
android:layout_toRightOf="@+id/tv_line_two"
android:textColor="#BFBFBF"
android:textSize="10sp"
tools:text="30:28" />
</RelativeLayout>
<ImageView
android:id="@+id/play_state"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="15dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:scaleType="centerCrop"
android:src="@drawable/ico_yyfc_play" />
</LinearLayout>
android:src="@drawable/ico_yyfc_play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_title"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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