AndroidMedia
| Kind | class |
| Package | android.platform |
| Full name | android.platform.AndroidMedia |
| Source | source/android/platform/AndroidMedia.hx |
Android media integration: Jetpack Media3 MediaSession / MediaSessionService (system media controls, lock screen, Bluetooth and Android Auto), MediaStyle notifications, audio focus and native audio output information.
Media actions from the system fire the signals below; the engine (see PlayState) maps them back onto gameplay/audio.
Public fields
| Name | Type | Static | Default | Notes |
|---|---|---|---|---|
STATE_STOPPED | Int | yes | 0 | final · Playback states accepted by setPlaybackState. |
STATE_PLAYING | Int | yes | 1 | final |
STATE_PAUSED | Int | yes | 2 | final |
STATE_BUFFERING | Int | yes | 3 | final |
onPlay | FlxSignal | yes | — | property (get, never) |
onPause | FlxSignal | yes | — | property (get, never) |
onStop | FlxSignal | yes | — | property (get, never) |
onNext | FlxSignal | yes | — | property (get, never) |
onPrevious | FlxSignal | yes | — | property (get, never) |
onSeek | FlxTypedSignal<Float->Void> | yes | — | property (get, never) · Seek request, position in milliseconds. |
onAudioFocusChanged | FlxTypedSignal<String->Void> | yes | — | property (get, never) · Audio focus changes: "gain", "loss", "lossTransient", "duck". Engines should pause on loss/lossTransient, lower volume on duck and restore on gain. |
Public methods
updateNowPlaying
static function updateNowPlaying(title:String, artist:String, durationMs:Float = -1, ?album:String, ?artworkPath:String):Void
Publishes the currently playing song to Android's Media3 session.
artworkPath may be null, an Android asset path, a local file path or a
content/file URI. The native bridge embeds small local artwork in the
metadata so system clients can render it without private-file access.
No-op outside of Android.
| Parameter | Type | Default |
|---|---|---|
title | String | — |
artist | String | — |
durationMs (optional) | Float | -1 |
album (optional) | String | — |
artworkPath (optional) | String | — |
setPlaybackState
static function setPlaybackState(state:Int, positionMs:Float, playbackSpeed:Float = 1.0):Void
Updates the playback state exposed to the media system.
| Parameter | Type | Default |
|---|---|---|
state | Int | — |
positionMs | Float | — |
playbackSpeed (optional) | Float | 1.0 |
updateNotification
static function updateNotification(title:String, artist:String, playing:Bool):Void
Compatibility helper for older callers. Media3 derives its notification
from updateNowPlaying and setPlaybackState; it requests its service
only if the native bridge already mirrors ready playback.
| Parameter | Type | Default |
|---|---|---|
title | String | — |
artist | String | — |
playing | Bool | — |
startForegroundService
static function startForegroundService(title:String, artist:String, playing:Bool = true):Void
Compatibility request for the Media3 MediaSessionService. It is ignored until the native bridge already mirrors ready playback; Media3 owns the foreground MediaStyle notification thereafter. Requires FOREGROUND_SERVICE_MEDIA_PLAYBACK (declared by the engine's manifest template). The Haxe audio player remains the audio owner.
| Parameter | Type | Default |
|---|---|---|
title | String | — |
artist | String | — |
playing (optional) | Bool | true |
stopForegroundService
static function stopForegroundService():Void
stop
static function stop():Void
Ends the media session entirely (playback fully over).
requestAudioFocus
static function requestAudioFocus():Bool
Requests audio focus with a listener forwarding interruptions to
onAudioFocusChanged. Returns true when granted immediately.
abandonAudioFocus
static function abandonAudioFocus():Void
getAudioInfo
static function getAudioInfo():Null<AudioOutputInfo>
Native audio output information used for rhythm-game timing / offset calibration. Returns null on non-Android targets.
Internals
Private / internal members
| Field | Type | Static |
|---|---|---|
_createSession | Dynamic | yes |
_setMetadata | Dynamic | yes |
_setPlaybackState | Dynamic | yes |
_setActive | Dynamic | yes |
_releaseSession | Dynamic | yes |
_notifyMedia | Dynamic | yes |
_startForegroundService | Dynamic | yes |
_stopForegroundService | Dynamic | yes |
_requestAudioFocus | Dynamic | yes |
_abandonAudioFocus | Dynamic | yes |
_getAudioInfo | Dynamic | yes |
| Method |
|---|
static inline function get_onPlay():FlxSignal |
static inline function get_onPause():FlxSignal |
static inline function get_onStop():FlxSignal |
static inline function get_onNext():FlxSignal |
static inline function get_onPrevious():FlxSignal |
static inline function get_onSeek():FlxTypedSignal<Float->Void> |
static inline function get_onAudioFocusChanged():FlxTypedSignal<String->Void> |
static function createSession_jni():Void |
static function setMetadata_jni(title:String, artist:String, album:String, durationMs:Int, artworkPath:String):Void |
static function setPlaybackState_jni(state:Int, positionMs:Int, speed:Float):Void |
static function setActive_jni(active:Bool):Void |
static function releaseSession_jni():Void |
static function notifyMedia_jni(title:String, artist:String, playing:Bool):Void |
static function startForegroundService_jni(title:String, artist:String, playing:Bool):Void |
static function stopForegroundService_jni():Void |
static function requestAudioFocus_jni():Int |
static function abandonAudioFocus_jni():Void |
static function getAudioInfo_jni():String |