Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fae8097a
authored
Mar 08, 2022
by
christosts
Committed by
Ian Baker
Mar 09, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Custom notification actions start the service in background
PiperOrigin-RevId: 433172330
parent
aa22bc2d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
14 deletions
libraries/session/src/main/java/androidx/media3/session/DefaultActionFactory.java
libraries/session/src/main/java/androidx/media3/session/MediaSessionService.java
libraries/session/src/main/java/androidx/media3/session/DefaultActionFactory.java
View file @
fae8097a
...
@@ -65,7 +65,7 @@ import androidx.media3.common.util.Util;
...
@@ -65,7 +65,7 @@ import androidx.media3.common.util.Util;
intent
.
setComponent
(
new
ComponentName
(
service
,
service
.
getClass
()));
intent
.
setComponent
(
new
ComponentName
(
service
,
service
.
getClass
()));
intent
.
putExtra
(
Intent
.
EXTRA_KEY_EVENT
,
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
intent
.
putExtra
(
Intent
.
EXTRA_KEY_EVENT
,
new
KeyEvent
(
KeyEvent
.
ACTION_DOWN
,
keyCode
));
if
(
Util
.
SDK_INT
>=
26
&&
command
!=
COMMAND_PAUSE
&&
command
!=
COMMAND_STOP
)
{
if
(
Util
.
SDK_INT
>=
26
&&
command
!=
COMMAND_PAUSE
&&
command
!=
COMMAND_STOP
)
{
return
Api26
.
createPendingIntent
(
service
,
/* requestCode= */
keyCode
,
intent
);
return
Api26
.
createPendingIntent
(
service
,
keyCode
,
intent
);
}
else
{
}
else
{
return
PendingIntent
.
getService
(
return
PendingIntent
.
getService
(
service
,
service
,
...
@@ -80,16 +80,12 @@ import androidx.media3.common.util.Util;
...
@@ -80,16 +80,12 @@ import androidx.media3.common.util.Util;
intent
.
setComponent
(
new
ComponentName
(
service
,
service
.
getClass
()));
intent
.
setComponent
(
new
ComponentName
(
service
,
service
.
getClass
()));
intent
.
putExtra
(
EXTRAS_KEY_ACTION_CUSTOM
,
action
);
intent
.
putExtra
(
EXTRAS_KEY_ACTION_CUSTOM
,
action
);
intent
.
putExtra
(
EXTRAS_KEY_ACTION_CUSTOM_EXTRAS
,
extras
);
intent
.
putExtra
(
EXTRAS_KEY_ACTION_CUSTOM_EXTRAS
,
extras
);
if
(
Util
.
SDK_INT
>=
26
)
{
// Custom actions always start the service in the background.
return
Api26
.
createPendingIntent
(
return
PendingIntent
.
getService
(
service
,
/* requestCode= */
KeyEvent
.
KEYCODE_UNKNOWN
,
intent
);
service
,
}
else
{
/* requestCode= */
KeyEvent
.
KEYCODE_UNKNOWN
,
return
PendingIntent
.
getService
(
intent
,
service
,
Util
.
SDK_INT
>=
23
?
PendingIntent
.
FLAG_IMMUTABLE
:
0
);
/* requestCode= */
KeyEvent
.
KEYCODE_UNKNOWN
,
intent
,
Util
.
SDK_INT
>=
23
?
PendingIntent
.
FLAG_IMMUTABLE
:
0
);
}
}
}
/** Returns whether {@code intent} was part of a {@link #createMediaAction media action}. */
/** Returns whether {@code intent} was part of a {@link #createMediaAction media action}. */
...
...
libraries/session/src/main/java/androidx/media3/session/MediaSessionService.java
View file @
fae8097a
...
@@ -339,10 +339,19 @@ public abstract class MediaSessionService extends Service {
...
@@ -339,10 +339,19 @@ public abstract class MediaSessionService extends Service {
}
}
}
else
if
(
actionFactory
.
isCustomAction
(
intent
))
{
}
else
if
(
actionFactory
.
isCustomAction
(
intent
))
{
@Nullable
String
customAction
=
actionFactory
.
getCustomAction
(
intent
);
@Nullable
String
customAction
=
actionFactory
.
getCustomAction
(
intent
);
if
(
session
!=
null
&&
customAction
!=
null
)
{
if
(
customAction
==
null
)
{
Bundle
customExtras
=
actionFactory
.
getCustomActionExtras
(
intent
);
return
START_STICKY
;
getMediaNotificationManager
().
onCustomAction
(
session
,
customAction
,
customExtras
);
}
}
if
(
session
==
null
)
{
ControllerInfo
controllerInfo
=
ControllerInfo
.
createLegacyControllerInfo
();
session
=
onGetSession
(
controllerInfo
);
if
(
session
==
null
)
{
return
START_STICKY
;
}
addSession
(
session
);
}
Bundle
customExtras
=
actionFactory
.
getCustomActionExtras
(
intent
);
getMediaNotificationManager
().
onCustomAction
(
session
,
customAction
,
customExtras
);
}
}
return
START_STICKY
;
return
START_STICKY
;
}
}
...
...
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