Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
8f1f52f0
Commit
8f1f52f0
authored
Aug 02, 2022
by
王佳洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,音视频悬浮窗代码优化
2,音频播放页逻辑修正
parent
91a4261a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
132 additions
and
164 deletions
+132
-164
PlayFragment.java
app/src/main/java/com/ydl/component/music/PlayFragment.java
+1
-1
AudioPlayActivity.kt
m-course/src/main/java/com/yidianling/course/coursePlay/AudioPlayActivity.kt
+18
-21
CourseServiceImp.kt
m-course/src/main/java/com/yidianling/course/modular_service/CourseServiceImp.kt
+7
-5
AudioPlayView.kt
m-course/src/main/java/com/yidianling/course/widget/AudioPlayView.kt
+30
-39
HPlayView.kt
m-course/src/main/java/com/yidianling/course/widget/HPlayView.kt
+2
-2
course_seekbar.xml
m-course/src/main/res/drawable/course_seekbar.xml
+1
-1
mask.xml
m-course/src/main/res/drawable/mask.xml
+0
-25
audio_play_view.xml
m-course/src/main/res/layout/audio_play_view.xml
+2
-2
dialog_course_list.xml
m-course/src/main/res/layout/dialog_course_list.xml
+0
-8
FMDetailActivity.java
m-fm/src/main/java/com/yidianling/fm/FMDetailActivity.java
+1
-1
MeditationFloatWindow.kt
m-muse/src/main/java/com/yidianling/muse/helper/MeditationFloatWindow.kt
+1
-1
AudioPlayer.kt
ydl-media/src/main/java/com/ydl/media/audio/AudioPlayer.kt
+29
-28
OnPlayerEventListener.kt
ydl-media/src/main/java/com/ydl/media/audio/OnPlayerEventListener.kt
+16
-16
MediaSessionManager.kt
ydl-media/src/main/java/com/ydl/media/audio/manager/MediaSessionManager.kt
+1
-0
PlayerFloatHelper.kt
ydl-media/src/main/java/com/ydl/media/view/PlayerFloatHelper.kt
+4
-4
PlayerFloatView.kt
ydl-media/src/main/java/com/ydl/media/view/PlayerFloatView.kt
+0
-0
item_playing_float_btn.xml
ydl-media/src/main/res/layout/item_playing_float_btn.xml
+15
-8
platform_bottom_dialog_slide_hide.xml
ydl-platform/src/main/res/anim/platform_bottom_dialog_slide_hide.xml
+2
-1
platform_bottom_dialog_slide_show.xml
ydl-platform/src/main/res/anim/platform_bottom_dialog_slide_show.xml
+2
-1
No files found.
app/src/main/java/com/ydl/component/music/PlayFragment.java
View file @
8f1f52f0
...
...
@@ -91,7 +91,7 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
}
@Override
public
void
on
Change
(
Music
music
)
{
public
void
on
Load
(
Music
music
)
{
onChangeImpl
(
music
);
}
...
...
m-course/src/main/java/com/yidianling/course/coursePlay/AudioPlayActivity.kt
View file @
8f1f52f0
...
...
@@ -3,7 +3,6 @@ package com.yidianling.course.coursePlay
import
android.content.Intent
import
android.graphics.drawable.Drawable
import
android.text.TextUtils
import
android.util.Log
import
android.view.ViewGroup
import
androidx.constraintlayout.widget.ConstraintLayout
import
com.alibaba.android.arouter.facade.annotation.Route
...
...
@@ -61,9 +60,9 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
private
val
ROUTER_PARAMS
=
"routerParam"
private
var
mCourseId
=
0
// 课程id
private
var
r
eceiverPlayUrl
:
String
?
=
null
// 外部选中要播放的音/视频文件地址
private
var
i
sFromFloatView
=
false
// 是否是悬浮窗进入
private
var
f
rom
:
Int
=
0
private
var
mR
eceiverPlayUrl
:
String
?
=
null
// 外部选中要播放的音/视频文件地址
private
var
mI
sFromFloatView
=
false
// 是否是悬浮窗进入
private
var
mF
rom
:
Int
=
0
private
var
mCourPlayBean
:
CourseMediaDetailBean
?
=
null
private
val
mPlayList
:
ArrayList
<
CourseMediaBean
>
=
ArrayList
()
// 播放列表
private
var
mCourseSpeedDialog
:
CourseSpeedDialog
?
=
null
...
...
@@ -113,20 +112,20 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
//正常跳转所传参数
mCourseId
=
it
.
getIntExtra
(
"course_id"
,
0
)
r
eceiverPlayUrl
=
it
.
getStringExtra
(
"coursePlayUrl"
)
i
sFromFloatView
=
it
.
getBooleanExtra
(
"isFromFloatView"
,
false
)
if
(!
TextUtils
.
isEmpty
(
receiverPlayUrl
)
&&
i
sFromFloatView
)
mR
eceiverPlayUrl
=
it
.
getStringExtra
(
"coursePlayUrl"
)
mI
sFromFloatView
=
it
.
getBooleanExtra
(
"isFromFloatView"
,
false
)
if
(!
TextUtils
.
isEmpty
(
mReceiverPlayUrl
)
&&
mI
sFromFloatView
)
audio_play
.
mNonWifiTips
=
false
try
{
if
(
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
&&
AudioPlayer
.
get
().
isPlaying
&&
TextUtils
.
isEmpty
(
r
eceiverPlayUrl
)
&&
audio_play
.
isPlaying
()
&&
TextUtils
.
isEmpty
(
mR
eceiverPlayUrl
)
)
{
receiverPlayUrl
=
AudioPlayer
.
get
().
playMusic
?.
path
mReceiverPlayUrl
=
audio_play
.
getAudioMusic
()
?.
path
}
}
catch
(
e
:
Exception
)
{
}
f
rom
=
it
.
getIntExtra
(
"from"
,
0
)
mF
rom
=
it
.
getIntExtra
(
"from"
,
0
)
if
(
mCourseId
==
0
)
{
ToastUtil
.
toastShort
(
"参数错误"
)
finish
()
...
...
@@ -179,11 +178,9 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
private
fun
togglePlaying
(
playPosition
:
Int
)
{
Log
.
d
(
"wjy===="
,
"mCurrentPosition -> $mCurrentPosition index -> $playPosition"
)
if
(
playPosition
>=
mPlayList
.
size
||
playPosition
<
0
)
{
ToastUtil
.
toastShort
(
"暂无内容"
)
}
else
if
(
mCurrentPosition
!=
playPosition
)
{
Log
.
d
(
"wjy===="
,
"audio_play.play"
)
mCurrentPosition
=
playPosition
mCourPlayBean
?.
courseExtra
?.
let
{
if
(
isCanPlay
(
it
.
isBuy
))
audio_play
.
play
(
mCurrentPosition
)
...
...
@@ -194,7 +191,7 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
private
fun
isCanPlay
(
isBuy
:
Boolean
):
Boolean
{
mPlayList
.
elementAtOrNull
(
mCurrentPosition
)
?.
let
{
if
(!
it
.
isDemo
&&
!
isBuy
)
{
if
(
AudioPlayer
.
get
().
isPlaying
)
AudioPlayer
.
get
().
pausePlayer
()
if
(
audio_play
.
isPlaying
())
audio_play
.
pausePlay
()
buyCourseTipDialog
()
}
else
if
(
it
.
mediaType
==
COURSE_AUDIO
)
{
return
true
...
...
@@ -221,9 +218,9 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
private
fun
showFloatView
():
Boolean
{
if
(
AudioPlayer
.
get
().
isPlaying
&&
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
)
{
AudioPlayer
.
get
().
playMusic
?.
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
AudioPlayer
.
get
().
playMusic
?.
artist
=
mCourPlayBean
?.
courseExtra
?.
doctorName
if
(
audio_play
.
isPlaying
()
&&
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
)
{
audio_play
.
getAudioMusic
()
?.
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
audio_play
.
getAudioMusic
()
?.
artist
=
mCourPlayBean
?.
courseExtra
?.
doctorName
PlayerFloatHelper
.
playTempData
.
clear
()
...
...
@@ -276,10 +273,10 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
mCourPlayBean
=
bean
mPlayList
.
clear
()
setPlayList
(
bean
)
if
(!
TextUtils
.
isEmpty
(
r
eceiverPlayUrl
))
{
if
(!
TextUtils
.
isEmpty
(
mR
eceiverPlayUrl
))
{
mCurrentPosition
=
mPlayList
.
indexOfLast
{
TextUtils
.
equals
(
r
eceiverPlayUrl
,
it
.
url
)
||
TextUtils
.
equals
(
r
eceiverPlayUrl
!!
.
replace
(
TextUtils
.
equals
(
mR
eceiverPlayUrl
,
it
.
url
)
||
TextUtils
.
equals
(
mR
eceiverPlayUrl
!!
.
replace
(
"http"
,
"https"
),
it
.
url
...
...
@@ -312,7 +309,7 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
tv_list
.
setOnClickListener
{
listClick
()
}
iv_list
.
setOnClickListener
{
listClick
()
}
}
audio_play
.
setData
(
mCurrentPosition
,
convertToMusics
(
mPlayList
),
bean
.
courseExtra
.
isBuy
,
f
rom
)
audio_play
.
setData
(
mCurrentPosition
,
convertToMusics
(
mPlayList
),
bean
.
courseExtra
.
isBuy
,
mF
rom
)
}
private
fun
convertToMusics
(
list
:
List
<
CourseMediaBean
>):
ArrayList
<
Music
>
{
...
...
m-course/src/main/java/com/yidianling/course/modular_service/CourseServiceImp.kt
View file @
8f1f52f0
...
...
@@ -62,11 +62,13 @@ class CourseServiceImp : ICourseService {
}
override
fun
startCoursePlayActivity
(
activity
:
Activity
,
courseId
:
Int
,
coursePlayUrl
:
String
?,
from
:
Int
,
mediaType
:
String
?)
{
val
intent
=
if
(
COURSE_AUDIO
.
toString
()
==
mediaType
)
{
Intent
(
activity
,
AudioPlayActivity
::
class
.
java
)
}
else
{
Intent
(
activity
,
CoursePlayActivity
::
class
.
java
)
}
// val intent = if (COURSE_AUDIO.toString() == mediaType) {
// Intent(activity, AudioPlayActivity::class.java)
// } else {
// 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
)
...
...
m-course/src/main/java/com/yidianling/course/widget/AudioPlayView.kt
View file @
8f1f52f0
package
com.yidianling.course.widget
import
android.annotation.SuppressLint
import
android.content.Context
import
android.text.TextUtils
import
android.util.AttributeSet
import
android.util.Log
import
android.view.View
import
android.widget.FrameLayout
import
android.widget.SeekBar
...
...
@@ -81,7 +83,7 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
if
(
playList
.
isEmpty
())
return
setAutoNext
(
isAuto
)
AudioPlayer
.
get
().
addPlayList
(
playList
)
if
(
AudioPlayer
.
get
().
isPlaying
)
mNonWifiTips
=
false
if
(
isPlaying
()
)
mNonWifiTips
=
false
if
(
RxNetTool
.
isWifi
(
context
))
{
playAudio
(
from
,
playPosition
,
playList
)
}
else
{
...
...
@@ -101,9 +103,10 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
}
private
fun
playAudio
(
from
:
Int
,
playPosition
:
Int
,
playList
:
ArrayList
<
Music
>)
{
if
(
AudioPlayer
.
get
().
isPlaying
&&
(
from
==
1
||
from
==
2
))
{
if
(
isPlaying
()
&&
(
from
==
1
||
from
==
2
))
{
if
(
TextUtils
.
equals
(
getCurrentUrl
(),
playList
[
playPosition
].
path
))
{
updateView
(
playPosition
)
seekbar
.
max
=
AudioPlayer
.
get
().
getDuration
().
toInt
()
tv_duration
.
text
=
getStringTime
(
seekbar
.
max
)
}
else
{
play
(
playPosition
)
}
...
...
@@ -112,16 +115,6 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
}
}
private
fun
updateView
(
playPosition
:
Int
)
{
if
(
AudioPlayer
.
get
().
isPlaying
)
{
seekbar
.
max
=
AudioPlayer
.
get
().
getDuration
().
toInt
()
tv_end
.
text
=
getStringTime
(
seekbar
.
max
)
if
(
AudioPlayer
.
get
().
isPlaying
)
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
}
}
}
/**
* 获取当前播放url
*/
...
...
@@ -131,10 +124,7 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
fun
play
(
index
:
Int
)
{
PlayerFloatHelper
.
playingType
=
PlayTypeEnum
.
PLAY_TYPE_COURSE
AudioPlayer
.
get
().
play
(
index
)
if
(
AudioPlayer
.
get
().
isPlaying
)
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
}
AudioPlayer
.
get
().
load
(
index
)
}
/**
...
...
@@ -148,47 +138,41 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
}
}
override
fun
on
Change
(
music
:
Music
)
{
@SuppressLint
(
"SetTextI18n"
)
override
fun
on
Load
(
music
:
Music
)
{
displayPlayStatus
(
R
.
drawable
.
course_loading5
,
true
)
seekbar
.
progress
=
0
tv_start
.
text
=
"00:00"
}
override
fun
onPlayerStart
()
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
}
override
fun
onPlayerPause
()
{
if
(
AudioPlayer
.
get
().
isPlaying
)
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
}
else
{
displayPlayStatus
(
R
.
drawable
.
course_play
)
}
override
fun
onPrepared
(
duration
:
Long
)
{
seekbar
.
max
=
duration
.
toInt
()
tv_duration
.
text
=
getStringTime
(
seekbar
.
max
)
mListener
?.
invoke
(
AudioPlayer
.
get
().
playPosition
)
}
override
fun
onBufferingUpdate
(
percent
:
Int
)
{
seekbar
.
secondaryProgress
=
percent
*
seekbar
.
max
/
100
}
override
fun
onPublish
(
percent
:
Int
,
currentPosition
:
Long
)
{
if
(!
mSeekBarIsTouch
)
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
seekbar
.
progress
=
currentPosition
.
toInt
()
tv_start
.
text
=
getStringTime
(
currentPosition
.
toInt
())
}
}
override
fun
onBufferingUpdate
(
percent
:
Int
)
{
if
(!
AudioPlayer
.
get
().
isPlaying
)
{
displayPlayStatus
(
R
.
drawable
.
course_loading5
,
true
)
}
seekbar
.
secondaryProgress
=
percent
*
seekbar
.
max
/
100
}
override
fun
onPrepared
(
duration
:
Long
)
{
seekbar
.
max
=
duration
.
toInt
()
tv_end
.
text
=
getStringTime
(
seekbar
.
max
)
mListener
?.
invoke
(
AudioPlayer
.
get
().
playPosition
)
override
fun
onComplete
()
{
}
override
fun
onComplete
()
{
if
(
AudioPlayer
.
get
().
isPlaying
)
{
override
fun
onPlayerPause
()
{
if
(
isPlaying
())
{
displayPlayStatus
(
R
.
drawable
.
course_pause
)
}
else
{
displayPlayStatus
(
R
.
drawable
.
course_play
)
}
}
...
...
@@ -230,4 +214,10 @@ class AudioPlayView(context: Context, attrs: AttributeSet?) :
AudioPlayer
.
get
().
setSpeed
(
speed
)
}
fun
isPlaying
()
=
AudioPlayer
.
get
().
isPlaying
fun
pausePlay
()
=
AudioPlayer
.
get
().
pausePlayer
()
fun
getAudioMusic
()
=
AudioPlayer
.
get
().
playMusic
}
\ No newline at end of file
m-course/src/main/java/com/yidianling/course/widget/HPlayView.kt
View file @
8f1f52f0
...
...
@@ -117,7 +117,7 @@ class HPlayView : RelativeLayout, OnPlayerEventListener {
fun
play
(
index
:
Int
)
{
PlayerFloatHelper
.
playingType
=
PlayTypeEnum
.
PLAY_TYPE_COURSE
AudioPlayer
.
get
().
play
(
index
)
AudioPlayer
.
get
().
load
(
index
)
updateButton
()
}
...
...
@@ -140,7 +140,7 @@ class HPlayView : RelativeLayout, OnPlayerEventListener {
@SuppressLint
(
"SetTextI18n"
)
override
fun
on
Change
(
music
:
Music
)
{
override
fun
on
Load
(
music
:
Music
)
{
if
(
mContext
!=
null
)
{
displayImage
(
com
.
yidianling
.
course
.
R
.
drawable
.
course_loading5
,
img_gif
,
true
)
}
...
...
m-course/src/main/res/drawable/course_seekbar.xml
View file @
8f1f52f0
...
...
@@ -11,7 +11,7 @@
<clip>
<shape>
<corners
android:radius=
"3dp"
/>
<solid
android:color=
"
#ECF0F1
"
/>
<solid
android:color=
"
@color/color_FAFAFF
"
/>
</shape>
</clip>
</item>
...
...
m-course/src/main/res/drawable/mask.xml
deleted
100644 → 0
View file @
91a4261a
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:aapt=
"http://schemas.android.com/aapt"
android:width=
"375dp"
android:height=
"90dp"
android:viewportWidth=
"375"
android:viewportHeight=
"90"
>
<path
android:pathData=
"M0,0h375v90h-375z"
android:strokeWidth=
"1"
android:fillType=
"evenOdd"
android:strokeColor=
"#00000000"
>
<aapt:attr
name=
"android:fillColor"
>
<gradient
android:startY=
"0"
android:startX=
"187.5"
android:endY=
"90"
android:endX=
"187.5"
android:type=
"linear"
>
<item
android:offset=
"0"
android:color=
"#C7FFFFFF"
/>
<item
android:offset=
"0.45317963"
android:color=
"#FFFFFFFF"
/>
<item
android:offset=
"1"
android:color=
"#FFFFFFFF"
/>
</gradient>
</aapt:attr>
</path>
</vector>
m-course/src/main/res/layout/audio_play_view.xml
View file @
8f1f52f0
...
...
@@ -36,7 +36,7 @@
android:minHeight=
"3dp"
android:progressDrawable=
"@drawable/course_seekbar"
android:thumb=
"@drawable/course_seekbar_dot"
tools
:progress=
"0"
/>
android
:progress=
"0"
/>
<TextView
android:id=
"@+id/tv_start"
...
...
@@ -49,7 +49,7 @@
android:textColor=
"@android:color/white"
/>
<TextView
android:id=
"@+id/tv_
end
"
android:id=
"@+id/tv_
duration
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
tools:text=
"00:00"
...
...
m-course/src/main/res/layout/dialog_course_list.xml
View file @
8f1f52f0
...
...
@@ -26,11 +26,4 @@
app:layoutManager=
"androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf=
"@id/tv_title"
/>
<View
android:layout_width=
"match_parent"
android:layout_height=
"55dp"
android:background=
"@drawable/mask"
app:layout_constraintBottom_toBottomOf=
"@id/recycler_list"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
m-fm/src/main/java/com/yidianling/fm/FMDetailActivity.java
View file @
8f1f52f0
...
...
@@ -591,7 +591,7 @@ public class FMDetailActivity extends BaseActivity implements View.OnClickListen
}
@Override
public
void
on
Change
(
@NotNull
Music
music
)
{
public
void
on
Load
(
@NotNull
Music
music
)
{
}
...
...
m-muse/src/main/java/com/yidianling/muse/helper/MeditationFloatWindow.kt
View file @
8f1f52f0
...
...
@@ -292,7 +292,7 @@ class MeditationFloatWindow(var mContext: Context) : FrameLayout(mContext) {
myHandler
?.
sendEmptyMessage
(
UPDATE_VIEW_COMPLETE
)
}
override
fun
on
Change
(
music
:
Music
)
{
override
fun
on
Load
(
music
:
Music
)
{
}
override
fun
onPlayerStart
()
{
...
...
ydl-media/src/main/java/com/ydl/media/audio/AudioPlayer.kt
View file @
8f1f52f0
...
...
@@ -122,17 +122,14 @@ class AudioPlayer private constructor() {
fun
init
(
context
:
Context
)
{
this
.
context
=
context
.
applicationContext
audioFocusManager
=
AudioFocusManager
(
context
)
mediaPlayer
=
IjkMediaPlayer
()
try
{
(
mediaPlayer
as
IjkMediaPlayer
).
setOption
(
IjkMediaPlayer
.
OPT_CATEGORY_FORMAT
,
"dns_cache_clear"
,
1
)
mediaPlayer
=
IjkMediaPlayer
().
also
{
it
.
setOption
(
IjkMediaPlayer
.
OPT_CATEGORY_FORMAT
,
"dns_cache_clear"
,
1
)
it
.
setOption
(
IjkMediaPlayer
.
OPT_CATEGORY_PLAYER
,
"enable-accurate-seek"
,
1
)
}
}
catch
(
e
:
Exception
)
{
LogUtil
.
e
(
e
.
message
)
}
mediaPlayer
!!
.
setOnPreparedListener
{
if
(
isPreparing
)
{
if
(
autoSaveProgress
)
{
...
...
@@ -217,7 +214,7 @@ class AudioPlayer private constructor() {
musicList
.
add
(
music
)
playMode
=
PlayModeEnum
.
SINGLE
autoSaveProgress
=
isAutoSaveProgress
play
(
0
)
load
(
0
)
}
/**
...
...
@@ -228,7 +225,7 @@ class AudioPlayer private constructor() {
musicList
.
add
(
music
)
playMode
=
PlayModeEnum
.
SINGLE_LOOP
autoSaveProgress
=
false
play
(
0
)
load
(
0
)
}
/**
...
...
@@ -240,20 +237,20 @@ class AudioPlayer private constructor() {
musicList
.
add
(
music
)
position
=
musicList
.
size
-
1
}
play
(
position
)
load
(
position
)
}
/**
* 播放第一首
*/
fun
play
()
{
play
(
0
)
load
(
0
)
}
/**
* 加载指定索引的音乐
*/
fun
play
(
index
:
Int
)
{
fun
load
(
index
:
Int
)
{
var
position
=
index
if
(
musicList
.
isEmpty
())
{
return
...
...
@@ -275,7 +272,7 @@ class AudioPlayer private constructor() {
mediaPlayer
!!
.
prepareAsync
()
state
=
STATE_PREPARING
for
(
listener
in
listeners
)
{
listener
.
on
Change
(
music
)
listener
.
on
Load
(
music
)
}
if
(
isShowNotify
)
{
NotifyManager
.
get
().
showPlay
(
music
)
...
...
@@ -303,7 +300,7 @@ class AudioPlayer private constructor() {
}
else
{
stopPlayer
()
for
(
listener
in
listeners
)
{
listener
.
on
Change
(
playMusic
!!
)
listener
.
on
Load
(
playMusic
!!
)
}
}
}
...
...
@@ -324,7 +321,7 @@ class AudioPlayer private constructor() {
startPlayer
()
}
else
->
{
play
(
playPosition
)
load
(
playPosition
)
}
}
}
...
...
@@ -408,7 +405,7 @@ class AudioPlayer private constructor() {
PlayModeEnum
.
LIST_LOOP
->
playPosition
+
1
else
->
playPosition
+
1
}
play
(
position
)
load
(
position
)
}
/**
...
...
@@ -424,7 +421,7 @@ class AudioPlayer private constructor() {
PlayModeEnum
.
LIST_LOOP
->
playPosition
-
1
else
->
playPosition
-
1
}
play
(
playPosition
)
load
(
playPosition
)
}
/**
...
...
@@ -434,20 +431,24 @@ class AudioPlayer private constructor() {
*/
fun
seekTo
(
percent
:
Int
=
-
1
,
position
:
Long
=
-
1
)
{
if
(
isPlaying
||
isPausing
)
{
var
currentPosition
=
0L
val
duration
=
getDuration
()
var
currentPercent
=
0
if
(
position
!=
(-
1
).
toLong
())
{
val
current
=
(
currentPosition
*
1.0
).
toFloat
()
val
du
=
mediaPlayer
!!
.
duration
.
toFloat
()
currentPercent
=
(
current
*
100
/
du
).
toInt
()
currentPosition
=
position
val
currentPosition
=
if
(
position
!=
-
1L
)
{
val
pos
=
when
{
position
>
duration
->
duration
position
<
0
->
0L
else
->
position
}
currentPercent
=
(
pos
/
duration
).
toInt
()
pos
}
else
{
currentPosition
=
percent
*
mediaPlayer
!!
.
duration
/
100
currentPercent
=
when
{
percent
>
100
->
100
percent
<
0
->
0
else
->
percent
}
currentPercent
*
duration
/
100
}
mediaPlayer
!!
.
seekTo
(
currentPosition
)
MediaSessionManager
.
get
().
updatePlaybackState
()
if
(
autoSaveProgress
)
{
...
...
ydl-media/src/main/java/com/ydl/media/audio/OnPlayerEventListener.kt
View file @
8f1f52f0
...
...
@@ -10,26 +10,21 @@ import com.ydl.media.audio.model.Music
interface
OnPlayerEventListener
{
/**
*
切换
歌曲
*
加载
歌曲
*/
fun
on
Change
(
music
:
Music
)
fun
on
Load
(
music
:
Music
)
/**
*
继续
播放
*
开始
播放
*/
fun
onPlayerStart
()
/**
* 暂停播放
*/
fun
onPlayerPause
()
/**
* 更新进度
* percent : 播放百分比
* currentPosition:当前播放位置
* 准备完成
*
* duration:音乐时长
*/
fun
onP
ublish
(
percent
:
Int
,
currentPosition
:
Long
)
fun
onP
repared
(
duration
:
Long
)
/**
* 缓冲百分比
...
...
@@ -37,14 +32,19 @@ interface OnPlayerEventListener {
fun
onBufferingUpdate
(
percent
:
Int
)
/**
*
准备完成
*
*
duration:音乐时长
*
更新进度
*
percent : 播放百分比
*
currentPosition:当前播放位置
*/
fun
onP
repared
(
duration
:
Long
)
fun
onP
ublish
(
percent
:
Int
,
currentPosition
:
Long
)
/**
* 单曲播放完成
*/
fun
onComplete
()
/**
* 暂停播放
*/
fun
onPlayerPause
()
}
ydl-media/src/main/java/com/ydl/media/audio/manager/MediaSessionManager.kt
View file @
8f1f52f0
...
...
@@ -14,6 +14,7 @@ import com.ydl.media.audio.utils.CoverImageUtils
/**
* Created by haorui on 2019-10-27 .
* Des:
* 线控
*/
class
MediaSessionManager
private
constructor
()
{
...
...
ydl-media/src/main/java/com/ydl/media/view/PlayerFloatHelper.kt
View file @
8f1f52f0
...
...
@@ -6,11 +6,11 @@ import android.content.Intent
import
android.graphics.PixelFormat
import
android.graphics.Point
import
android.os.Bundle
import
androidx.core.view.ViewCompat
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
...
...
@@ -82,11 +82,11 @@ class PlayerFloatHelper {
}
if
(
showingPageName
!=
context
::
class
.
qualifiedName
)
{
mPlayerFloatView
?.
reset
Wm
(
context
)
mPlayerFloatView
?.
reset
LayoutParams
(
)
addFloatToWm
(
context
)
}
mPlayerFloatView
?.
resetView
()
mPlayerFloatView
?.
reset
Float
View
()
mPlayerFloatView
?.
visibility
=
View
.
VISIBLE
mPlayerFloatView
?.
setPlayingState
()
...
...
@@ -153,7 +153,7 @@ class PlayerFloatHelper {
//获取WindowManager
wm
=
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
)
as
WindowManager
//设置LayoutParams(全局变量)相关参数
val
wmParams
=
mPlayerFloatView
?.
wm
Params
val
wmParams
=
mPlayerFloatView
?.
mFloatView
Params
wmParams
?.
type
=
WindowManager
.
LayoutParams
.
TYPE_APPLICATION
//设置window type
wmParams
?.
format
=
PixelFormat
.
RGBA_8888
//设置图片格式,效果为背景透明
//设置Window flag
...
...
ydl-media/src/main/java/com/ydl/media/view/PlayerFloatView.kt
View file @
8f1f52f0
This diff is collapsed.
Click to expand it.
ydl-media/src/main/res/layout/item_playing_float_btn.xml
View file @
8f1f52f0
...
...
@@ -2,6 +2,7 @@
<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:id=
"@+id/cl"
android:layout_width=
"match_parent"
android:layout_height=
"56dp"
android:layout_marginStart=
"15dp"
...
...
@@ -22,7 +23,6 @@
android:id=
"@+id/play_head"
android:layout_width=
"36dp"
android:layout_height=
"36dp"
android:layout_marginStart=
"12dp"
android:layout_marginEnd=
"12dp"
android:src=
"@drawable/ico_play_float_pic"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
@@ -59,23 +59,30 @@
<TextView
android:id=
"@+id/tv_now_playing_time"
android:layout_width=
"
0dp
"
android:layout_width=
"
wrap_content
"
android:layout_height=
"wrap_content"
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_duration"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:layout_constraintBaseline_toBaselineOf=
"@id/tv_now_playing_time"
app:layout_constraintStart_toEndOf=
"@id/tv_now_playing_time"
android:textColor=
"#BFBFBF"
android:textSize=
"10sp"
tools:text=
" / 30:28"
/>
<ImageView
android:id=
"@+id/play_state"
android:layout_width=
"
30
dp"
android:layout_width=
"
57
dp"
android:layout_height=
"30dp"
android:
layout_marginStart=
"15
dp"
android:
layout_margin
End=
"15dp"
android:
paddingStart=
"12
dp"
android:
padding
End=
"15dp"
android:scaleType=
"centerCrop"
android:src=
"@drawable/ico_yyfc_play"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
ydl-platform/src/main/res/anim/platform_bottom_dialog_slide_hide.xml
View file @
8f1f52f0
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"@android:integer/config_
long
AnimTime"
android:duration=
"@android:integer/config_
medium
AnimTime"
android:fromYDelta=
"0"
android:toYDelta=
"100%p"
/>
</set>
\ No newline at end of file
ydl-platform/src/main/res/anim/platform_bottom_dialog_slide_show.xml
View file @
8f1f52f0
...
...
@@ -2,7 +2,7 @@
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"@android:integer/config_
long
AnimTime"
android:duration=
"@android:integer/config_
medium
AnimTime"
android:fromYDelta=
"100%p"
android:toYDelta=
"0"
/>
</set>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment