src/main/java/org/intellimate/izou/sdk/frameworks/music/user/PlayerRequest.java
@SuppressWarnings("unused")
    public static Optional<PlayerRequest> createPlayerRequest(Playlist playlist, boolean permanent, Identification player, AddOnModule source) {
        if (playlist == null ||player == null || source == null)
            return Optional.empty();
        try {
            return source.getContext().getResources()
                    .generateResource(new CapabilitiesResource(player))
                    .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                    .thenApply(list -> list.stream()
                                    .filter(resourceModel -> resourceModel.getProvider().equals(player))
                                    .findAny()
                                    .flatMap(resource -> Capabilities.importFromResource(resource, source.getContext()))
                    ).get(1, TimeUnit.SECONDS)
                    .filter(capabilities -> {
                        if (!capabilities.handlesPlayRequestFromOutside()) {
                            source.getContext().getLogger().error("player does not handle play-request from outside");
                            return false;
                        }
                        if (!capabilities.hasPlayRequestDetailed()) {
                            source.getContext().getLogger().error("player does not handle playlist-request from outside");
                            return false;
                        }
                        if (!playlist.verify(capabilities)) {
                            source.getContext().getLogger().error("player can not handle the playlist, probably illegal PlaybackModes");
                            return false;
                        }
                        return true;
                    })
                    .map(capabilities -> new PlayerRequest(null, playlist, permanent, player, capabilities, source.getContext(), source));
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            source.getContext().getLogger().debug("unable to obtain capabilities");
            return Optional.empty();
        }
    }
@SuppressWarnings("unused")
    public static Optional<PlayerRequest> createPlayerRequest(Playlist playlist, boolean permanent, Identification player, AddOnModule source) {
        if (playlist == null ||player == null || source == null)
            return Optional.empty();
        try {
            return source.getContext().getResources()
                    .generateResource(new CapabilitiesResource(player))
                    .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                    .thenApply(list -> list.stream()
                                    .filter(resourceModel -> resourceModel.getProvider().equals(player))
                                    .findAny()
                                    .flatMap(resource -> Capabilities.importFromResource(resource, source.getContext()))
                    ).get(1, TimeUnit.SECONDS)
                    .filter(capabilities -> {
                        if (!capabilities.handlesPlayRequestFromOutside()) {
                            source.getContext().getLogger().error("player does not handle play-request from outside");
                            return false;
                        }
                        if (!capabilities.hasPlayRequestDetailed()) {
                            source.getContext().getLogger().error("player does not handle playlist-request from outside");
                            return false;
                        }
                        if (!playlist.verify(capabilities)) {
                            source.getContext().getLogger().error("player can not handle the playlist, probably illegal PlaybackModes");
                            return false;
                        }
                        return true;
                    })
                    .map(capabilities -> new PlayerRequest(null, playlist, permanent, player, capabilities, source.getContext(), source));
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            source.getContext().getLogger().debug("unable to obtain capabilities");
            return Optional.empty();
        }
    }
@ SuppressWarnings ( "unused" ) public static Optional < PlayerRequest > createPlayerRequest ( Playlist playlist , boolean permanent , Identification player , AddOnModule source ) { if ( playlist == null || player == null || source == null ) return Optional . empty ( ) ; try { return source . getContext ( ) . getResources ( ) . generateResource ( new CapabilitiesResource ( player ) ) . orElse ( CompletableFuture . completedFuture ( new ArrayList <> ( ) ) ) . thenApply ( list -> list . stream ( ) . filter ( resourceModel -> resourceModel . getProvider ( ) . equals ( player ) ) . findAny ( ) . flatMap ( resource -> Capabilities . importFromResource ( resource , source . getContext ( ) ) ) ) . get ( 1 , TimeUnit . SECONDS ) . filter ( capabilities -> { if ( ! capabilities . handlesPlayRequestFromOutside ( ) ) { source . getContext ( ) . getLogger ( ) . error ( "player does not handle play-request from outside" ) ; return false ; } if ( ! capabilities . hasPlayRequestDetailed ( ) ) { source . getContext ( ) . getLogger ( ) . error ( "player does not handle playlist-request from outside" ) ; return false ; } if ( ! playlist . verify ( capabilities ) ) { source . getContext ( ) . getLogger ( ) . error ( "player can not handle the playlist, probably illegal PlaybackModes" ) ; return false ; } return true ; } ) . map ( capabilities -> new PlayerRequest ( null , playlist , permanent , player , capabilities , source . getContext ( ) , source ) ) ; } catch ( InterruptedException | ExecutionException | TimeoutException e ) { source . getContext ( ) . getLogger ( ) . debug ( "unable to obtain capabilities" ) ; return Optional . empty ( ) ; } }
creates a new PlayerRequest.
<p>
For this method to return a non-empty Optional the following criteria must be met:<br>
<ul>
<li>the player must exist and be support the standard defined through the sdk</li>
<li>the players-capabilities must allow requests from outside</li>
<li>the players-capabilities must allow a requests with specified a specified playlist/trackInfo</li>
</ul>
@param playlist the playlist to pass with the request
@param permanent true means the player can play indefinitely, but only if no one is currently using audio as
permanent. It will also not block. false is limited to 10 minutes playback, but will block.
@param player the player to target
@param source the addOnModule used for Context etc.
@return the optional PlayerRequest
creates a new PlayerRequest . <p > For this method to return a non - empty Optional the following criteria must be met : <br > <ul > <li > the player must exist and be support the standard defined through the sdk< / li > <li > the players - capabilities must allow requests from outside< / li > <li > the players - capabilities must allow a requests with specified a specified playlist / trackInfo< / li > < / ul >