Package org.mozilla.geckoview
Class MediaSession
Object
org.mozilla.geckoview.MediaSession
The MediaSession API provides media controls and events for a GeckoSession. This includes support
for the DOM Media Session API and regular HTML media content.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplement this delegate to receive media session events.static classThe representation of a media element's metadata.static classFlags for supported media session features.static classThe representation of a media session's metadata.static @interfaceMedia session feature flag definitions for supported media operations.static classHolds the details of the media session's playback state.static @interfaceThe permitted values fornotifySystemAudioFocusChange(int): one ofSYSTEM_AUDIO_FOCUS_GAIN,SYSTEM_AUDIO_FOCUS_TRANSIENT_LOSS, orSYSTEM_AUDIO_FOCUS_PERMANENT_LOSS. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe platform regained audio focus; resume what an interruption silenced.static final intThe platform took audio focus for good; the interruption is not resumed.static final intThe platform took audio focus transiently (e.g. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMediaSession(GeckoSession session) Create a new MediaSession for the given GeckoSession. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisActive()Get whether the media session is active.voidmuteAudio(boolean mute) Set whether audio should be muted.voidSelect and play the next track.voidnotifySystemAudioFocusChange(int change) Route a system audio-focus change to the tab's Audio Session interrupt.voidpause()Pause playback for the media session.voidplay()Start playback for the media session.voidSelect and play the previous track.voidSeek backward by a sensible number of seconds.voidSeek forward by a sensible number of seconds.voidseekTo(double time, boolean fast) Seek to a specific time.voidskipAd()Skip the advertisement that is currently playing.voidstop()Stop playback for the media session.
-
Field Details
-
SYSTEM_AUDIO_FOCUS_GAIN
public static final int SYSTEM_AUDIO_FOCUS_GAINThe platform regained audio focus; resume what an interruption silenced.- See Also:
-
SYSTEM_AUDIO_FOCUS_TRANSIENT_LOSS
public static final int SYSTEM_AUDIO_FOCUS_TRANSIENT_LOSSThe platform took audio focus transiently (e.g. a call); resumable on gain.- See Also:
-
SYSTEM_AUDIO_FOCUS_PERMANENT_LOSS
public static final int SYSTEM_AUDIO_FOCUS_PERMANENT_LOSSThe platform took audio focus for good; the interruption is not resumed.- See Also:
-
-
Constructor Details
-
MediaSession
Create a new MediaSession for the given GeckoSession.- Parameters:
session- The GeckoSession this media session is associated with.
-
-
Method Details
-
isActive
public boolean isActive()Get whether the media session is active. Only active media sessions can be controlled.Changes in the active state are notified via
MediaSession.Delegate.onActivated(org.mozilla.geckoview.GeckoSession, org.mozilla.geckoview.MediaSession)andMediaSession.Delegate.onDeactivated(org.mozilla.geckoview.GeckoSession, org.mozilla.geckoview.MediaSession)respectively.- Returns:
- True if this media session is active, false otherwise.
- See Also:
-
pause
public void pause()Pause playback for the media session. -
stop
public void stop()Stop playback for the media session. -
play
public void play()Start playback for the media session. -
seekTo
public void seekTo(double time, boolean fast) Seek to a specific time. Prefer using fast seeking when calling this in a sequence. Don't use fast seeking for the last or only call in a sequence.- Parameters:
time- The time in seconds to move the playback time to.fast- Whether fast seeking should be used.
-
seekForward
public void seekForward()Seek forward by a sensible number of seconds. -
seekBackward
public void seekBackward()Seek backward by a sensible number of seconds. -
nextTrack
public void nextTrack()Select and play the next track. Move playback to the next item in the playlist when supported. -
previousTrack
public void previousTrack()Select and play the previous track. Move playback to the previous item in the playlist when supported. -
skipAd
public void skipAd()Skip the advertisement that is currently playing. -
muteAudio
public void muteAudio(boolean mute) Set whether audio should be muted. Muting audio is supported by default and does not require the media session to be active.- Parameters:
mute- True if audio for this media session should be muted.
-
notifySystemAudioFocusChange
public void notifySystemAudioFocusChange(int change) Route a system audio-focus change to the tab's Audio Session interrupt. A transient or permanent loss suspends the tab's audible sources (media elements, Web Audio, and Web Speech); a gain resumes what the interruption silenced. The user transport (pause()/play()) is a separate control surface for controllable media.- Parameters:
change- One ofSYSTEM_AUDIO_FOCUS_GAIN,SYSTEM_AUDIO_FOCUS_TRANSIENT_LOSS, orSYSTEM_AUDIO_FOCUS_PERMANENT_LOSS.
-