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
7f7c465b
Commit
7f7c465b
authored
May 26, 2022
by
范玉宾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
meditation play float view done
parent
a3309601
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
5 deletions
+104
-5
FloatViewTouchListener.kt
m-muse/src/main/java/com/yidianling/muse/helper/FloatViewTouchListener.kt
+0
-2
MediaPlayerManager.kt
m-muse/src/main/java/com/yidianling/muse/helper/MediaPlayerManager.kt
+66
-1
MeditationWindowService.kt
m-muse/src/main/java/com/yidianling/muse/service/MeditationWindowService.kt
+37
-1
layout_meditation_play_float_view.xml
m-muse/src/main/res/layout/layout_meditation_play_float_view.xml
+1
-1
No files found.
m-muse/src/main/java/com/yidianling/muse/helper/FloatViewTouchListener.kt
View file @
7f7c465b
...
...
@@ -27,8 +27,6 @@ class FloatViewTouchListener(val wl: WindowManager.LayoutParams, val windowManag
x
+=
movedX
y
+=
movedY
}
LogUtil
.
d
(
"Lancet======="
,
"nowY=====$nowY"
)
LogUtil
.
d
(
"Lancet======="
,
"movedY=====$movedY"
)
//更新悬浮窗位置
windowManager
.
updateViewLayout
(
view
,
wl
)
}
...
...
m-muse/src/main/java/com/yidianling/muse/helper/MediaPlayerManager.kt
View file @
7f7c465b
...
...
@@ -4,13 +4,18 @@ import android.content.Context
import
android.media.AudioAttributes
import
android.media.AudioManager
import
android.media.MediaPlayer
import
com.yidianling.muse.helper.MediaPlayerManager.MediaPlayCallBack.Companion.TYPE_LIST
import
kotlin.properties.Delegates
class
MediaPlayerManager
private
constructor
()
{
private
var
listener
:
OnMediaPlayerManagerListener
?=
null
fun
setAudioPath
(
path
:
String
){
private
var
mCurrentListIndex
=
0
private
var
mMediaPlayCallBack
:
MediaPlayCallBack
?=
null
private
var
mAudioPaths
=
mutableListOf
<
String
>()
fun
setAudioPath
(
path
:
String
,
isLoop
:
Boolean
=
false
){
val
attrs
=
AudioAttributes
.
Builder
()
.
setContentType
(
AudioAttributes
.
CONTENT_TYPE_MUSIC
)
...
...
@@ -22,10 +27,34 @@ class MediaPlayerManager private constructor() {
mMediaPlayer
?.
reset
()
mMediaPlayer
?.
setAudioAttributes
(
attrs
)
mMediaPlayer
?.
setDataSource
(
path
)
mMediaPlayer
?.
isLooping
=
isLoop
mMediaPlayer
?.
prepareAsync
()
mMediaPlayer
?.
setOnPreparedListener
{
listener
?.
onPrepared
(
it
)
}
// mMediaPlayer?.setOnCompletionListener {
// if (it !=null){
// it.stop()
// it.release()
// }
//
// mMediaPlayer = null
// if (mAudioPaths!=null){
// mCurrentListIndex++
// if(mCurrentListIndex<mAudioPaths.size){
// mMediaPlayCallBack?.mediaPlayCallBack(TYPE_LIST,
// MediaPlayCallBack.STATE_CUT, mCurrentListIndex)
// setAudioPath(mAudioPaths[mCurrentListIndex])
// }else{
// mMediaPlayCallBack?.mediaPlayCallBack(TYPE_LIST,
// MediaPlayCallBack.STATE_STOP,mAudioPaths.size
// )
// }
// }
//
// }
}
fun
getMediaPlayer
():
MediaPlayer
?
=
mMediaPlayer
...
...
@@ -59,6 +88,22 @@ class MediaPlayerManager private constructor() {
this
.
listener
=
listener
}
fun
startPlayList
(
audioPaths
:
ArrayList
<
String
>,
playCallBack
:
MediaPlayCallBack
,
startIndex
:
Int
){
if
(
audioPaths
.
isNullOrEmpty
()
||
startIndex
>=
mAudioPaths
.
size
){
return
}
mMediaPlayCallBack
=
playCallBack
mAudioPaths
=
audioPaths
mCurrentListIndex
=
startIndex
mMediaPlayCallBack
?.
mediaPlayCallBack
(
TYPE_LIST
,
MediaPlayCallBack
.
STATE_START
,
mCurrentListIndex
)
setAudioPath
(
mAudioPaths
[
mCurrentListIndex
])
}
companion
object
{
private
var
mContext
:
Context
by
Delegates
.
notNull
()
...
...
@@ -90,4 +135,23 @@ class MediaPlayerManager private constructor() {
fun
onPrepared
(
mediaPlayer
:
MediaPlayer
)
}
interface
MediaPlayCallBack
{
companion
object
{
const
val
STATE_START
=
0
const
val
STATE_PLAY
=
1
const
val
STATE_PAUSE
=
2
const
val
STATE_STOP
=
3
const
val
STATE_CUT
=
4
const
val
TYPE_SINGLE
=
0
const
val
TYPE_LIST
=
1
}
fun
mediaPlayCallBack
(
type
:
Int
,
state
:
Int
,
position
:
Int
){}
}
}
\ No newline at end of file
m-muse/src/main/java/com/yidianling/muse/service/MeditationWindowService.kt
View file @
7f7c465b
package
com.yidianling.muse.service
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.content.ComponentName
import
android.content.Context
import
android.content.Intent
import
android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import
android.graphics.PixelFormat
...
...
@@ -13,6 +17,8 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import
android.view.WindowManager
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.core.app.NotificationCompat
import
androidx.core.content.getSystemService
import
androidx.lifecycle.LifecycleService
import
com.bumptech.glide.Glide
import
com.ydl.ydlcommon.data.http.ThrowableConsumer
...
...
@@ -51,6 +57,18 @@ class MeditationWindowService : LifecycleService() {
override
fun
onCreate
()
{
super
.
onCreate
()
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ECLAIR
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
){
val
manager
=
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
channel
=
NotificationChannel
(
"壹点灵"
,
"play"
,
NotificationManager
.
IMPORTANCE_LOW
)
manager
.
createNotificationChannel
(
channel
)
val
notification
=
NotificationCompat
.
Builder
(
this
,
"壹点灵"
).
build
()
startForeground
(
1
,
notification
)
}
}
EventBus
.
getDefault
().
register
(
this
)
}
...
...
@@ -199,17 +217,35 @@ class MeditationWindowService : LifecycleService() {
if
(
floatRootView
!=
null
&&
floatRootView
?.
windowToken
!=
null
)
{
if
(
mWindowManager
!=
null
)
{
windowIsShow
=
false
mTimer
.
cancel
()
mWindowManager
.
removeViewImmediate
(
floatRootView
)
}
}
}
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ECLAIR
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
){
startForegroundService
(
intent
)
}
else
{
startService
(
intent
)
}
}
return
super
.
onStartCommand
(
intent
,
flags
,
startId
)
}
override
fun
startForegroundService
(
service
:
Intent
?):
ComponentName
?
{
return
super
.
startForegroundService
(
service
)
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
if
(
EventBus
.
getDefault
().
isRegistered
(
this
))
{
EventBus
.
getDefault
().
unregister
(
this
)
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ECLAIR
)
{
stopForeground
(
true
)
}
}
private
fun
dp2px
(
dp
:
Float
):
Int
{
...
...
m-muse/src/main/res/layout/layout_meditation_play_float_view.xml
View file @
7f7c465b
...
...
@@ -2,7 +2,7 @@
<FrameLayout
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:background=
"@drawable/
bg_play_meditation_float_view
"
android:background=
"@drawable/
play_float_background
"
android:layout_marginHorizontal=
"16dp"
android:layout_marginBottom=
"20dp"
android:layout_width=
"match_parent"
...
...
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