Commit fc94ddc1 by 王佳洋

修复一些悬浮窗线上存在的已知bug

如悬浮窗代码优化,不再只是为了结果而结果,如悬浮窗的可见性
如悬浮窗导致NewH5Activity上下文无法释放
如悬浮窗播放完当前音频之后,播放下一音频时,显式不正确
如悬浮窗跟随手势滑动异常
如悬浮窗关闭,但音频播放未停止
如悬浮窗跟随手势滑动后进入其他页面后再次回到初始位置
parent b818b158
......@@ -151,7 +151,7 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
}
private void showFloatView() {
if(!PlayerFloatHelper.Companion.isShow(getActivity())) {
if(!PlayerFloatHelper.Companion.isShow()) {
PlayerFloatHelper.Companion.show(getActivity(), PlayTypeEnum.PLAY_TYPE_FM,new HashMap<>());
}else {
PlayerFloatHelper.Companion.showIfPlaying(getActivity());
......@@ -267,7 +267,7 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
@Override
public void onDestroy() {
AudioPlayer.Companion.get().removeOnPlayEventListener(this);
PlayerFloatHelper.Companion.onDestroy();
PlayerFloatHelper.Companion.removeResetView();
super.onDestroy();
}
......
......@@ -184,9 +184,9 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo
mu.path = playUrl
mu.coverPath=confideIcon
AudioPlayer.get().singlePlay(mu)
if (PlayerFloatHelper.isShow(mContext!!)) {
if (PlayerFloatHelper.isShow()) {
if (AudioPlayer.get().playMode.value() == 1) {
PlayerFloatHelper.removeView(mContext!!)
PlayerFloatHelper.removeView()
PlayerFloatHelper.show(mContext!!)
} else {
......@@ -270,9 +270,7 @@ class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeCo
}
override fun destoryPlayer() {
PlayerFloatHelper.hide()
PlayerFloatHelper.playTempData = hashMapOf<String,String>()
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
floatViewClickListener?.let { PlayerFloatHelper.removeClickListener(it) };
}
......
......@@ -60,6 +60,6 @@ public class CourseActivity extends BaseActivity {
@Override
protected void onDestroy() {
super.onDestroy();
PlayerFloatHelper.Companion.onDestroy();
PlayerFloatHelper.Companion.removeResetView();
}
}
......@@ -738,9 +738,7 @@ class CourseListContainerActivity : BaseActivity(), PtrHandler, LoadMoreHandler
override fun onDestroy() {
super.onDestroy()
if (!PlayerFloatHelper.isCanClick) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(this)
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
}
}
......
......@@ -262,8 +262,8 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
override fun onResume() {
super.onResume()
if (PlayerFloatHelper.isShow(this)) {
PlayerFloatHelper.removeView(this)
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeView()
}
}
......
......@@ -622,8 +622,8 @@ class CoursePlayActivity : BaseActivity() {
playVideoView?.onResume()
playAudioView?.onResume()
if (PlayerFloatHelper.isShow(this)) {
PlayerFloatHelper.removeView(this)
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeView()
}
}
......
......@@ -122,9 +122,7 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
if (jumpUrl!!.startsWith("http")) {
val h5Params = H5Params(jumpUrl, "")
NewH5Activity.start(mFragment!!.activity, h5Params)
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
CourseSendPlugin.sendMsg(false)
return
}
......@@ -164,9 +162,7 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
}
else -> YDLRouterManager.router(jumpUrl)
}
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
CourseSendPlugin.sendMsg(false)
}
}
......@@ -194,9 +190,7 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
EventBus.getDefault().post(ScrollStatusChangeEvent(true))
}
IOSPOP -> {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
CourseSendPlugin.sendMsg(false)
mFragment!!.activity?.finish()
}
......@@ -204,12 +198,10 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
}
private fun playMedia(fileInfo: Map<*, *>) {
if (PlayerFloatHelper.isShow(mFragment!!.requireActivity())) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
AudioPlayer.get().resetPlayer()
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeResetView()
} else {
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
PlayerFloatHelper.removeView()
}
......@@ -245,10 +237,8 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
)
checkPermission()
if (PlayerFloatHelper.isShow(mFragment!!.requireActivity())) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mFragment!!.requireActivity())
AudioPlayer.get().resetPlayer()
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeResetView()
}
}
......@@ -262,8 +252,7 @@ class CoursePlugin : MethodChannel.MethodCallHandler {
}
override fun onPlayFinish() {
PlayerFloatHelper.hide()
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
CourseSendPlugin.sendMsg(false)
}
......
......@@ -22,9 +22,7 @@ class CoursePlayLifecycle : Application.ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity?) {
if (!PlayerFloatHelper.isCanClick) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(activity!!)
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
} else {
PlayerFloatHelper.showIfPlaying(activity!!)
if (!TextUtils.isEmpty(PlayerFloatHelper.playTempData["course_id"])) {
......
......@@ -8,6 +8,7 @@ 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
......@@ -67,7 +68,6 @@ class CourseServiceImp : ICourseService {
// Intent(activity, CoursePlayActivity::class.java)
// }
val intent = Intent(activity, AudioPlayActivity::class.java)
intent.putExtra("course_id", courseId)
intent.putExtra("coursePlayUrl", coursePlayUrl)
intent.putExtra("from", from)
......
......@@ -273,12 +273,10 @@ class CourseItemNewView : ConstraintLayout {
private fun playMedia() {
if (PlayerFloatHelper.isShow(mContext)) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mContext)
AudioPlayer.get().resetPlayer()
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeResetView()
} else {
PlayerFloatHelper.removeView(mContext)
PlayerFloatHelper.removeView()
}
val music = Music()
......@@ -310,10 +308,8 @@ class CourseItemNewView : ConstraintLayout {
)
checkPermission()
if (PlayerFloatHelper.isShow(mContext)) {
PlayerFloatHelper.hide()
PlayerFloatHelper.removeView(mContext)
AudioPlayer.get().resetPlayer()
if (PlayerFloatHelper.isShow()) {
PlayerFloatHelper.removeResetView()
}
}
......@@ -324,8 +320,7 @@ class CourseItemNewView : ConstraintLayout {
}
override fun onPlayFinish() {
PlayerFloatHelper.hide()
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
}
override fun onPauseClick() {
......
......@@ -552,8 +552,8 @@ public class FMDetailActivity extends BaseActivity implements View.OnClickListen
super.onResume();
fmSurfaceView.surfaceCreated(null);
if (PlayerFloatHelper.Companion.isShow(this)) {
PlayerFloatHelper.Companion.removeView(this);
if (PlayerFloatHelper.Companion.isShow()) {
PlayerFloatHelper.Companion.removeView();
}
}
......
......@@ -507,9 +507,9 @@ open class HomeBaseImpl : IHomeBaseEvent {
}
PlayerFloatHelper.isCanClick = true
if (PlayerFloatHelper.isShow(mContext!!)) {
if (PlayerFloatHelper.isShow()) {
if (PlayerFloatHelper.playingType != PlayTypeEnum.PLAY_TYPE_FM) {
PlayerFloatHelper.removeView(mContext!!)
PlayerFloatHelper.removeView()
PlayerFloatHelper.show(mContext!!)
} else {
......
......@@ -109,9 +109,7 @@ class PlayMeditationActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PlayerFloatHelper.removeView(mContext)
PlayerFloatHelper.playTempData.clear()
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
mMediaPlayer = MediaPlayerManager.getInstance(this)?.getMediaPlayer()
......
......@@ -5,6 +5,7 @@ import android.content.IntentFilter
import android.media.AudioManager
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.tencent.bugly.Bugly.applicationContext
import com.ydl.media.audio.enums.PlayModeEnum
import com.ydl.media.audio.manager.AudioFocusManager
......@@ -166,13 +167,16 @@ class AudioPlayer private constructor() {
}
when (playMode) {
PlayModeEnum.SINGLE -> { // 这是老逻辑
PlayModeEnum.SINGLE -> {
resetPlayer()
playMode = PlayModeEnum.LIST_LOOP
}
PlayModeEnum.LIST -> {
if (playPosition >= musicList.lastIndex) pausePlayer()
else next()
else {
Log.d("wjy", "====OnCompletion==== $playPosition")
next()
}
}
else -> next()
}
......@@ -395,6 +399,16 @@ class AudioPlayer private constructor() {
state = STATE_IDLE
}
fun getNextPosition(position: Int): Int {
return when (playMode) {
PlayModeEnum.SHUFFLE -> Random().nextInt(musicList.size)
PlayModeEnum.SINGLE_LOOP -> position
PlayModeEnum.LIST_LOOP -> if (position >= musicList.lastIndex) 0 else position + 1
PlayModeEnum.LIST -> if (position >= musicList.lastIndex) -1 else position + 1
else -> position + 1
}
}
/**
* 下一首
*/
......@@ -402,17 +416,12 @@ class AudioPlayer private constructor() {
if (musicList.isEmpty()) {
return
}
val position = when (playMode) {
PlayModeEnum.SHUFFLE -> Random().nextInt(musicList.size)
PlayModeEnum.SINGLE_LOOP -> playPosition
PlayModeEnum.LIST_LOOP -> if (playPosition >= musicList.lastIndex) 0 else playPosition + 1
PlayModeEnum.LIST -> if (playPosition >= musicList.lastIndex) -1 else playPosition + 1
else -> playPosition + 1
}
val position = getNextPosition(playPosition)
if (-1 == position) {
ToastUtil.toastShort("暂无内容")
return
}
Log.d("wjy", "next playPosition: $playPosition position: $position")
load(position)
}
......@@ -445,7 +454,7 @@ class AudioPlayer private constructor() {
fun seekTo(percent: Int = -1, position: Long = -1) {
if (isPlaying || isPausing) {
val duration = getDuration()
var currentPercent = 0
val currentPercent: Int
val currentPosition = if (position != -1L) {
val pos = when {
position > duration -> duration
......
package com.ydl.media.view
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.PixelFormat
import android.graphics.Point
import android.os.Bundle
import android.text.TextUtils
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import androidx.core.view.ViewCompat
import com.alibaba.android.arouter.launcher.ARouter
import com.ydl.media.audio.AudioPlayer
import com.yidianling.common.tools.RxImageTool
/**
* 音频播放悬浮窗 帮助类
......@@ -24,32 +15,19 @@ import com.yidianling.common.tools.RxImageTool
class PlayerFloatHelper {
companion object {
@SuppressLint("StaticFieldLeak")
private var mPlayerFloatView: PlayerFloatView? = null
//已添加悬浮窗页面全路径名
private var showingPageName: String? = null
private var wm: WindowManager? = null
var isCanClick = true
var playingType = PlayTypeEnum.PLAY_TYPE_NONE
var playTempData = hashMapOf<String,String>()
/**
* FM:
* fmId
* fmTitle
* fmAuthor
* fmImageUrl
*/
/**
* 如果有音频正在播放则显示
*/
fun showIfPlaying(context: Context) {
if (AudioPlayer.get().isPlaying) {
show(context)
mPlayerFloatView?.updatePlayState()
} else {
hide()
removeView()
}
}
......@@ -57,43 +35,15 @@ class PlayerFloatHelper {
* 显示悬浮控件
*/
fun show(context: Context, playTypeEnum: PlayTypeEnum = PlayTypeEnum.PLAY_TYPE_NONE, playData:HashMap<String,String> = hashMapOf()) {
playingType = playTypeEnum
if (playData.size>0){
if (playData.size > 0) {
this.playTempData.putAll(playData)
}
if (mPlayerFloatView == null) {
mPlayerFloatView = PlayerFloatView(context)
mPlayerFloatView?.addFloatClickListener(object :PlayerFloatView.FloatViewPlayListener{
override fun onPauseClick() {
}
override fun onStartClick() {
}
override fun onPlayFinish() {
}
})
}
if (showingPageName != context::class.qualifiedName) {
mPlayerFloatView?.resetLayoutParams()
addFloatToWm(context)
playingType = playTypeEnum
mPlayerFloatView = PlayerFloatView(context).show()
}
mPlayerFloatView?.resetFloatView()
mPlayerFloatView?.visibility = View.VISIBLE
mPlayerFloatView?.setPlayingState()
}
fun hide() {
mPlayerFloatView?.visibility = View.GONE
mPlayerFloatView?.updatePlayState()
}
fun addClickListener(listener: PlayerFloatView.FloatViewPlayListener) {
......@@ -104,31 +54,32 @@ class PlayerFloatHelper {
mPlayerFloatView?.removeFloatClickListener(listener)
}
fun isShow(context: Context): Boolean {
return !TextUtils.isEmpty(showingPageName) && showingPageName == context::class.qualifiedName && mPlayerFloatView?.visibility == View.VISIBLE
fun isShow(): Boolean {
return null != mPlayerFloatView
}
fun removeView(context: Context) {
// if (TextUtils.isEmpty(showingPageName) || showingPageName != context::class.qualifiedName) {
// return
// }
mPlayerFloatView?.visibility = View.GONE
wm?.removeViewImmediate(mPlayerFloatView)
showingPageName = ""
wm = null
/**
* 只移除悬浮窗
*/
fun removeView() {
playTempData.clear()
mPlayerFloatView?.let {
it.remove()
it.removeAllViews()
}
mPlayerFloatView = null
}
fun onDestroy() {
if (mPlayerFloatView != null) {
if (!TextUtils.isEmpty(showingPageName)) {
wm?.removeViewImmediate(mPlayerFloatView)
showingPageName = ""
}
mPlayerFloatView?.onDestroy()
mPlayerFloatView?.removeAllViews()
/**
* 移除悬浮窗 + 重置音频播放器
*/
fun removeResetView() {
playTempData.clear()
mPlayerFloatView?.let {
it.removeAndReset()
it.removeAllViews()
}
mPlayerFloatView = null
}
fun setPlayingState(context: Context) {
......@@ -140,46 +91,13 @@ class PlayerFloatHelper {
mPlayerFloatView?.updatePlayState()
}
private fun addFloatToWm(context: Context) {
if (wm != null && !TextUtils.isEmpty(showingPageName)) {
if (ViewCompat.isAttachedToWindow(mPlayerFloatView!!)){
// if (context is Activity && !(context.isFinishing)){
// wm?.removeViewImmediate(mPlayerFloatView)
// }
wm?.removeViewImmediate(mPlayerFloatView)
}
wm = null
}
//获取WindowManager
wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
//设置LayoutParams(全局变量)相关参数
val wmParams = mPlayerFloatView?.mFloatViewParams
wmParams?.type = WindowManager.LayoutParams.TYPE_APPLICATION //设置window type
wmParams?.format = PixelFormat.RGBA_8888 //设置图片格式,效果为背景透明
//设置Window flag
wmParams?.flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
wmParams?.gravity = Gravity.LEFT or Gravity.TOP //调整悬浮窗口至左上角
//以屏幕左上角为原点,设置x、y初始值
val size = Point()
wm?.defaultDisplay?.getSize(size)
wmParams?.x = 0
wmParams?.y = size.y * 5 / 6
//设置悬浮窗口长宽数据
wmParams?.width = WindowManager.LayoutParams.MATCH_PARENT
wmParams?.height = RxImageTool.dp2px(56f)
//显示myFloatView图像
wm?.addView(mPlayerFloatView, wmParams)
showingPageName = context::class.qualifiedName!!
}
/**
* 打开播放中的页面详情
*/
fun startPlayingActivity(context: Context?, fullScreen: Int = 0) {
if (playingType == PlayTypeEnum.PLAY_TYPE_FM) {
//FM播放页
startFMPlayActivity(context)
startFMPlayActivity()
} else if (playingType == PlayTypeEnum.PLAY_TYPE_COURSE) {
val url = AudioPlayer.get().playMusic?.path
//课程播放页
......@@ -212,7 +130,7 @@ class PlayerFloatHelper {
}
}
fun startFMPlayActivity(context: Context?) {
private fun startFMPlayActivity() {
val bundle = Bundle()
bundle.putInt("id", playTempData["fmId"]?.toInt()?:0)
ARouter.getInstance().build("/fm/detail")
......@@ -227,9 +145,6 @@ class PlayerFloatHelper {
return playTempData["fmId"]?.toInt()?:0
}
}
}
package com.ydl.media.view
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.graphics.PixelFormat
import android.graphics.Point
import android.os.Build
import android.text.TextUtils
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
import android.view.WindowManager
import android.util.Log
import android.view.*
import android.widget.FrameLayout
import com.bumptech.glide.Glide
import com.ydl.media.R
import com.ydl.media.audio.AudioPlayer
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 com.yidianling.common.tools.RxImageTool
import kotlinx.android.synthetic.main.item_playing_float_btn.view.*
import java.util.concurrent.CopyOnWriteArraySet
import kotlin.math.abs
import com.ydl.ydl_image.transform.GlideRoundTransform
class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
......@@ -38,16 +39,11 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(context)
fun resetLayoutParams() {
mFloatViewParams = WindowManager.LayoutParams()
}
init {
View.inflate(context, R.layout.item_playing_float_btn, this)
resetFloatView()
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context)
Glide.with(context)
.load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic)
......@@ -62,9 +58,7 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
mListeners.forEach {
it.onPauseClick()
}
PlayerFloatHelper.removeView(context)
PlayerFloatHelper.playTempData.clear()
AudioPlayer.get().resetPlayer()
PlayerFloatHelper.removeResetView()
}
play_state.setOnClickListener {
if (AudioPlayer.get().isPlaying) {
......@@ -84,7 +78,7 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
override fun onComplete() {
tv_start.text = getStringTime(AudioPlayer.get().getDuration().toInt())
play_state.setImageResource(R.drawable.ico_yyfc_play)
setPlayDrawable()
mListeners.forEach {
it.onPlayFinish()
}
......@@ -92,12 +86,15 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
override fun onPreLoad(playPosition: Int): Boolean {
AudioPlayer.get().getMusicList().elementAtOrNull(playPosition)?.let {
if (it.canPlay) {
return if (it.canPlay) {
Log.d("wjy", "onPreLoad true $playPosition")
tv_title.text = it.title
tv_name.text = it.artist
return true
true
} else {
AudioPlayer.get().next()
Log.d("wjy", "onPreLoad false $playPosition")
AudioPlayer.get().load(AudioPlayer.get().getNextPosition(playPosition))
false
}
}
return true
......@@ -107,11 +104,11 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
}
override fun onStartPlay() {
play_state.setImageResource(R.drawable.ico_yyfc_pause)
setPauseDrawable()
}
override fun onPausePlay() {
play_state.setImageResource(R.drawable.ico_yyfc_play)
setPlayDrawable()
}
@SuppressLint("SetTextI18n")
......@@ -134,9 +131,9 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
@SuppressLint("SetTextI18n")
fun resetFloatView() {
private fun resetFloatView() {
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context)
Glide.with(context)
.load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic)
......@@ -229,23 +226,58 @@ class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
fun updatePlayState() {
if (AudioPlayer.get().isPlaying) {
play_state.setImageResource(R.drawable.ico_yyfc_pause)
setPauseDrawable()
} else {
play_state.setImageResource(R.drawable.ico_yyfc_play)
setPlayDrawable()
for (listener in mListeners) {
listener.onPauseClick()
}
}
}
fun setPlayingState() {
private fun setPlayDrawable() {
play_state.setImageResource(R.drawable.ico_yyfc_play)
}
private fun setPauseDrawable() {
play_state.setImageResource(R.drawable.ico_yyfc_pause)
}
fun setPlayingState() {
setPauseDrawable()
resetFloatView()
}
fun onDestroy() {
fun show(): PlayerFloatView {
mWindowManager.addView(this, mFloatViewParams.apply {
type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
WindowManager.LayoutParams.TYPE_PHONE;
}
format = PixelFormat.RGBA_8888 // 设置图片格式,效果为背景透明
flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
gravity = Gravity.START or Gravity.TOP // 调整悬浮窗口至左上角
val size = Point() // 以屏幕左上角为原点,设置x、y初始值
mWindowManager.defaultDisplay?.getSize(size)
x = 0
y = size.y * 5 / 6
//设置悬浮窗口长宽数据
width = WindowManager.LayoutParams.MATCH_PARENT
height = RxImageTool.dp2px(56f)
})
return this
}
fun remove() {
mListeners.clear()
mStateChangeListener?.let { AudioPlayer.get().removeOnPlayEventListener(it) }
mWindowManager.removeViewImmediate(this)
}
fun removeAndReset() {
AudioPlayer.get().resetPlayer()
remove()
}
fun addFloatClickListener(floatClickListener: FloatViewPlayListener) {
......
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