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
8cc2f486
Commit
8cc2f486
authored
Jul 28, 2022
by
刘鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: PlayService解绑
parent
c072cf3b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
21 deletions
+19
-21
build.gradle
build.gradle
+1
-1
MediaSessionManager.kt
ydl-media/src/main/java/com/ydl/media/audio/manager/MediaSessionManager.kt
+11
-11
NotifyManager.kt
ydl-media/src/main/java/com/ydl/media/audio/manager/NotifyManager.kt
+7
-9
No files found.
build.gradle
View file @
8cc2f486
...
...
@@ -14,7 +14,7 @@ buildscript {
ydlrouter_version
=
'1.2.3'
constrait_support_version
=
'1.0.2'
componentVersion
=
"0.3.0.
6
-SNAPSHOT"
componentVersion
=
"0.3.0.
8
-SNAPSHOT"
}
repositories
{
mavenCentral
()
...
...
ydl-media/src/main/java/com/ydl/media/audio/manager/MediaSessionManager.kt
View file @
8cc2f486
package
com.ydl.media.audio.manager
import
android.content.Context
import
android.graphics.Bitmap
import
android.os.Build
import
android.support.v4.media.MediaMetadataCompat
import
android.support.v4.media.session.MediaSessionCompat
import
android.support.v4.media.session.PlaybackStateCompat
import
com.ydl.media.audio.AudioPlayer
import
com.ydl.media.audio.PlayService
import
com.ydl.media.audio.model.Music
import
com.ydl.media.audio.utils.CoverImageUtils
...
...
@@ -17,7 +17,7 @@ import com.ydl.media.audio.utils.CoverImageUtils
*/
class
MediaSessionManager
private
constructor
()
{
private
var
playService
:
PlayService
?
=
null
private
var
mContext
:
Context
?
=
null
private
var
mediaSession
:
MediaSessionCompat
?
=
null
private
val
callback
=
object
:
MediaSessionCompat
.
Callback
()
{
...
...
@@ -50,22 +50,22 @@ class MediaSessionManager private constructor() {
val
instance
=
MediaSessionManager
()
}
fun
init
(
playService
:
PlayService
)
{
this
.
playService
=
playService
fun
init
(
context
:
Context
)
{
this
.
mContext
=
context
setupMediaSession
()
}
private
fun
setupMediaSession
()
{
mediaSession
=
MediaSessionCompat
(
playService
!!
,
TAG
)
mediaSession
!!
.
setFlags
(
MediaSessionCompat
.
FLAG_HANDLES_TRANSPORT_CONTROLS
or
MediaSessionCompat
.
FLAG_HANDLES_MEDIA_BUTTONS
)
mediaSession
!!
.
setCallback
(
callback
)
mediaSession
!!
.
isActive
=
true
mediaSession
=
MediaSessionCompat
(
mContext
,
TAG
)
mediaSession
?
.
setFlags
(
MediaSessionCompat
.
FLAG_HANDLES_TRANSPORT_CONTROLS
or
MediaSessionCompat
.
FLAG_HANDLES_MEDIA_BUTTONS
)
mediaSession
?
.
setCallback
(
callback
)
mediaSession
?
.
isActive
=
true
}
fun
updatePlaybackState
()
{
val
state
=
if
(
AudioPlayer
.
get
().
isPlaying
||
AudioPlayer
.
get
().
isPreparing
)
PlaybackStateCompat
.
STATE_PLAYING
else
PlaybackStateCompat
.
STATE_PAUSED
mediaSession
!!
.
setPlaybackState
(
mediaSession
?
.
setPlaybackState
(
PlaybackStateCompat
.
Builder
()
.
setActions
(
MEDIA_SESSION_ACTIONS
)
.
setState
(
state
,
AudioPlayer
.
get
().
audioPosition
,
1f
)
...
...
@@ -75,7 +75,7 @@ class MediaSessionManager private constructor() {
fun
updateMetaData
(
music
:
Music
?)
{
if
(
music
==
null
)
{
mediaSession
!!
.
setMetadata
(
null
)
mediaSession
?
.
setMetadata
(
null
)
return
}
...
...
@@ -95,7 +95,7 @@ class MediaSessionManager private constructor() {
// TODO: 2019-10-26 by:HaoRui
// metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, AppCache.get().getLocalMusicList().size());
}
mediaSession
!!
.
setMetadata
(
metaData
.
build
())
mediaSession
?
.
setMetadata
(
metaData
.
build
())
}
})
}
...
...
ydl-media/src/main/java/com/ydl/media/audio/manager/NotifyManager.kt
View file @
8cc2f486
...
...
@@ -18,7 +18,6 @@ import android.widget.TextView
import
com.bumptech.glide.Glide
import
com.bumptech.glide.request.target.NotificationTarget
import
com.ydl.media.R
import
com.ydl.media.audio.PlayService
import
com.ydl.media.audio.constants.Extras
import
com.ydl.media.audio.model.Music
import
com.ydl.media.audio.receiver.StatusBarReceiver
...
...
@@ -30,32 +29,31 @@ import java.util.*
* Des: 通知管理器
*/
class
NotifyManager
private
constructor
()
{
private
var
playService
:
PlayService
?
=
null
private
var
mContext
:
Context
?
=
null
private
var
notificationManager
:
NotificationManager
?
=
null
private
object
SingletonHolder
{
val
instance
=
NotifyManager
()
}
fun
init
(
playService
:
PlayService
)
{
this
.
playService
=
playService
fun
init
(
context
:
Context
)
{
this
.
mContext
=
context
notificationManager
=
playService
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
mContext
?
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
}
fun
showPlay
(
music
:
Music
?)
{
if
(
music
==
null
)
{
return
}
playService
?.
startForeground
(
NOTIFICATION_ID
,
buildNotification
(
playService
!!
,
music
,
true
))
}
fun
showPause
(
music
:
Music
?)
{
if
(
music
==
null
)
{
return
}
playService
?.
stopForeground
(
false
)
notificationManager
?.
notify
(
NOTIFICATION_ID
,
buildNotification
(
playService
!!
,
music
,
false
)
)
notificationManager
?.
notify
(
NOTIFICATION_ID
,
mContext
?.
let
{
buildNotification
(
it
,
music
,
false
)
}
)
}
fun
cancelAll
()
{
...
...
@@ -119,7 +117,7 @@ class NotifyManager private constructor() {
remoteViews
.
setTextViewText
(
R
.
id
.
tv_title
,
title
)
remoteViews
.
setTextViewText
(
R
.
id
.
tv_subtitle
,
subtitle
)
val
isLightNotificationTheme
=
isLightNotificationTheme
(
playService
)
val
isLightNotificationTheme
=
isLightNotificationTheme
(
mContext
)
val
playIntent
=
Intent
(
StatusBarReceiver
.
ACTION_STATUS_BAR
)
playIntent
.
setPackage
(
"com.cxzapp.xinlizixun"
)
...
...
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