Package com.craftmend.openaudiomc.api
Interface MediaApi
public interface MediaApi
The MediaApi is a collection of methods to interact with media, and get information about them
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clearPreloadedMedia
(Client client) Clear all preloaded media for a client, including entries with keepCopy set to true@NotNull Media
createMedia
(@NotNull String source) Create a new media instance with a source, and automatically translate the source (if needed) and register a normalized time for the start instant.static MediaApi
Get an instance of the media api.long
Get the current epoch time, but normalized to the start of the current media.void
Play a media for a clientvoid
preloadMedia
(Client client, Media media, boolean keepCopy) Force a client to preload a media, so it's ready to play when needed.void
preloadMediaSource
(Client client, String mediaSource, boolean keepCopy) Force a client to preload a media source, so it's ready to play when needed.void
registerMutation
(@NotNull String prefix, @NotNull UrlMutation mutation) URL mutations can be used to register custom server-side media hooks or source translators.void
Stop all media (except regions and speakers) for a clientvoid
Stop all media (except regions and speakers) for a clientvoid
Stop a specific media by ID for a clientvoid
Stop a specific media by ID for a client@NotNull String
translateSource
(@NotNull String source) Translate server-sided aliases, playlists or other sources to a valid source.
-
Method Details
-
getInstance
Get an instance of the media api. May be null if the plugin is not loaded yet- Returns:
- instance
-
createMedia
Create a new media instance with a source, and automatically translate the source (if needed) and register a normalized time for the start instant.- Parameters:
source
- the source of the media- Returns:
- a new media instance
-
preloadMediaSource
Force a client to preload a media source, so it's ready to play when needed. This will force the client to download the entire file and cache it. Once a media is played (through any method) it will look in the cache and take it from there if it's available. This method is useful for preloading media sources that are not played often, but should be ready to play at any time (like a sound effects, shows, etc). You can also make the client make a new copy after being taken by the pool so there'll always be a copy in the cache, which can be useful for frequently played media as long as you take really good care of clearing it too (to prevent memory leaks)- Parameters:
client
- the client to preload the media formediaSource
- the media source to preloadkeepCopy
- if the client should keep a copy of the media after being taken by the pool
-
preloadMedia
Force a client to preload a media, so it's ready to play when needed. This will force the client to download the entire file and cache it. Once a media is played (through any method) it will look in the cache and take it from there if it's available. This method is useful for preloading media sources that are not played often, but should be ready to play at any time (like a sound effects, shows, etc). You can also make the client make a new copy after being taken by the pool so there'll always be a copy in the cache, which can be useful for frequently played media as long as you take really good care of clearing it too (to prevent memory leaks)- Parameters:
client
- the client to preload the media formedia
- the media to preloadkeepCopy
- if the client should keep a copy of the media after being taken by the pool
-
clearPreloadedMedia
Clear all preloaded media for a client, including entries with keepCopy set to true- Parameters:
client
- the client to clear the preloaded media for
-
translateSource
Translate server-sided aliases, playlists or other sources to a valid source. This is automatically done by createMedia, but you might want to do this manually.- Parameters:
source
- the source to translate- Returns:
- the translated source
-
registerMutation
URL mutations can be used to register custom server-side media hooks or source translators. An example use case would be a custom media server aliased by hypixel:, which can be resolved to https://hypixel.com/media/* by a mutation.- Parameters:
prefix
- the prefix to register the mutation for, the mutation will only be called for media sources starting with this prefixmutation
- the mutation to register
-
getNormalizedCurrentEpoch
long getNormalizedCurrentEpoch()Get the current epoch time, but normalized to the start of the current media. This timecodes is normalized based on heartbeats from an open audio server, to eliminate timezone changes between this server and the web-client (because the player might be in a different timezone)- Returns:
- the current epoch time, but normalized to the start of the current media
-
playFor
Play a media for a client- Parameters:
clients
- Target clientsmedia
- Media instance
-
stopFor
Stop all media (except regions and speakers) for a client- Parameters:
clients
- Target clients
-
stopFor
Stop a specific media by ID for a client- Parameters:
id
- Media IDclients
- Target clients
-
stopFor
Stop a specific media by ID for a client- Parameters:
id
- Media IDfadeTime
- Fade time in millisecondsclients
- Target clients
-
stopFor
Stop all media (except regions and speakers) for a client- Parameters:
fadeTime
- Fade time in millisecondsclients
- Target clients
-