Class MediaClient


  • public class MediaClient
    extends Object

    The MediaClient is used for loading media resources from Gluon CloudLink into the client application.

    • Constructor Detail

      • MediaClient

        public MediaClient()
        Constructs a new instance of MediaClient with local caching enabled.
      • MediaClient

        public MediaClient​(boolean cachingEnabled)
        Constructs a new instance of MediaClient.
        Parameters:
        cachingEnabled - true if the response from the media client should be cached in the private storage of the device platform
    • Method Detail

      • loadMedia

        public InputStream loadMedia​(String name)
                              throws IOException
        Load the media resource with the provided name into an InputStream. The caller of this method is responsible for closing the returned InputStream when it is no longer needed.
        Parameters:
        name - the name of the media resource to load
        Returns:
        an InputStream that can be used for reading the media resource
        Throws:
        IOException - if an I/O error occurs while loading the media resource.
      • loadImage

        public Image loadImage​(String name)
                        throws IOException
        A convenience method to directly load a media resource with the provided name into a JavaFX Image object. You can check Image.errorProperty() to see whether the returned image contains a valid image or not.
        Parameters:
        name - the name of the media resource to load
        Returns:
        an Image that can be used in an ImageView.
        Throws:
        IOException - if an I/O error occurs while loading the media resource.
      • loadResourceBundle

        public ResourceBundle loadResourceBundle​(String bundleName,
                                                 Locale locale)
                                          throws IOException
        Loads the resource bundle with the provided bundle name and locale from Gluon CloudLink. Gluon CloudLink will try to find the best matching resource bundle for the given locale, as explained in ResourceBundle#getBundle. When no match could be found, null will be returned instead.
        Parameters:
        bundleName - the name of the resource bundle
        locale - the locale of the resource bundle
        Returns:
        the resource bundle that matches the given bundle name and locale
        Throws:
        IOException - if an I/O error occurs while loading the resource bundle.
      • isCachingEnabled

        public boolean isCachingEnabled()
        Returns whether the media client has local caching enabled or not.

        When caching is enabled, calling a media client will cause the locally cached values to be returned if no updates has been made to the data in the cloud. If there is an update, the new data will be downloaded, local cache will be over-written and then returned.

        Returns:
        true if local caching is enabled or false if it is disabled.