Skip to main content

AndroidMedia

Kindclass
Packageandroid.platform
Full nameandroid.platform.AndroidMedia
Sourcesource/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​

NameTypeStaticDefaultNotes
STATE_STOPPEDIntyes0final · Playback states accepted by setPlaybackState.
STATE_PLAYINGIntyes1final
STATE_PAUSEDIntyes2final
STATE_BUFFERINGIntyes3final
onPlayFlxSignalyes—property (get, never)
onPauseFlxSignalyes—property (get, never)
onStopFlxSignalyes—property (get, never)
onNextFlxSignalyes—property (get, never)
onPreviousFlxSignalyes—property (get, never)
onSeekFlxTypedSignal<Float->Void>yes—property (get, never) · Seek request, position in milliseconds.
onAudioFocusChangedFlxTypedSignal<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.

ParameterTypeDefault
titleString—
artistString—
durationMs (optional)Float-1
album (optional)String—
artworkPath (optional)String—

View source

setPlaybackState​

static function setPlaybackState(state:Int, positionMs:Float, playbackSpeed:Float = 1.0):Void

Updates the playback state exposed to the media system.

ParameterTypeDefault
stateInt—
positionMsFloat—
playbackSpeed (optional)Float1.0

View source

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.

ParameterTypeDefault
titleString—
artistString—
playingBool—

View source

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.

ParameterTypeDefault
titleString—
artistString—
playing (optional)Booltrue

View source

stopForegroundService​

static function stopForegroundService():Void

View source

stop​

static function stop():Void

Ends the media session entirely (playback fully over).

View source

requestAudioFocus​

static function requestAudioFocus():Bool

Requests audio focus with a listener forwarding interruptions to onAudioFocusChanged. Returns true when granted immediately.

View source

abandonAudioFocus​

static function abandonAudioFocus():Void

View source

getAudioInfo​

static function getAudioInfo():Null<AudioOutputInfo>

Native audio output information used for rhythm-game timing / offset calibration. Returns null on non-Android targets.

View source

Internals​

Private / internal members
FieldTypeStatic
_createSessionDynamicyes
_setMetadataDynamicyes
_setPlaybackStateDynamicyes
_setActiveDynamicyes
_releaseSessionDynamicyes
_notifyMediaDynamicyes
_startForegroundServiceDynamicyes
_stopForegroundServiceDynamicyes
_requestAudioFocusDynamicyes
_abandonAudioFocusDynamicyes
_getAudioInfoDynamicyes
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