src/main/java/com/safestream/sdk/api/video/VideoAPI.java
/**
     * Creates a new video allowing a specific timeout while waiting for the video to downloaded and encoded.
     *
     * This will block until either the video is ingested OR the timeout is reached.
     *
     * @param video {@link Video}
     * @param waitForIngest Time in millis to wait for the video to be ingested
     * @return The newly created video {@link Video}
     * @throws VideoAPIException
     */
Creates a new video allowing a specific timeout while waiting for the video to downloaded and encoded.
This will block until either the video is ingested OR the timeout is reached.

@param video  Video
@param waitForIngest Time in millis to wait for the video to be ingested
@return The newly created video  Video
@throws VideoAPIException
Creates a new video allowing a specific timeout while waiting for the video to downloaded and encoded . This will block until either the video is ingested OR the timeout is reached . @param video Video @param waitForIngest Time in millis to wait for the video to be ingested @return The newly created video Video @throws VideoAPIException
public Video create(Video video, long waitForIngest) throws VideoAPIException {
        UrlValidator urlValidator = new UrlValidator(new String[]{"http", "https"});
        if(video.getSourceUrl() == null || video.getSourceUrl().isEmpty() || !urlValidator.isValid(video.getSourceUrl())) {
            throw new VideoAPIException("Invalid source URL. Cannot ingest video.");
        }
        final String ingestedStatus = "INGESTED";
        try {
            Video videoResponse = safeStreamHttpClient.post(apiResourcePath, video).getEntity(Video.class);
            if(waitForIngest > 0 && !ingestedStatus.equals(videoResponse.getStatus())) {
                long startTime = System.currentTimeMillis();
                boolean ingested = false;
                while(!ingested && (System.currentTimeMillis() - startTime) < waitForIngest) {
                    Video test = find(video.getKey());
                    if(ingestedStatus.equals(videoResponse.getStatus())) {
                        return test;
                    }
                    try {
                        Thread.sleep(1500);
                    } catch(InterruptedException e) {
                        throw new VideoAPIException("Thread interrupted while waiting for watermarking", e);
                    }
                }
                throw new VideoAPIException("Timeout reached waiting for video to be ingested");
            } else {
                return videoResponse;
            }
        } catch (SafeStreamHttpClientException e) {
            throw new VideoAPIException(e);
        }
    }
public Video create ( Video video , long waitForIngest ) throws VideoAPIException { UrlValidator urlValidator = new UrlValidator ( new String [ ] { "http" , "https" } ) ; if ( video . getSourceUrl ( ) == null || video . getSourceUrl ( ) . isEmpty ( ) || ! urlValidator . isValid ( video . getSourceUrl ( ) ) ) { throw new VideoAPIException ( "Invalid source URL. Cannot ingest video." ) ; } final String ingestedStatus = "INGESTED" ; try { Video videoResponse = safeStreamHttpClient . post ( apiResourcePath , video ) . getEntity ( Video . class ) ; if ( waitForIngest > 0 && ! ingestedStatus . equals ( videoResponse . getStatus ( ) ) ) { long startTime = System . currentTimeMillis ( ) ; boolean ingested = false ; while ( ! ingested && ( System . currentTimeMillis ( ) - startTime ) < waitForIngest ) { Video test = find ( video . getKey ( ) ) ; if ( ingestedStatus . equals ( videoResponse . getStatus ( ) ) ) { return test ; } try { Thread . sleep ( 1500 ) ; } catch ( InterruptedException e ) { throw new VideoAPIException ( "Thread interrupted while waiting for watermarking" , e ) ; } } throw new VideoAPIException ( "Timeout reached waiting for video to be ingested" ) ; } else { return videoResponse ; } } catch ( SafeStreamHttpClientException e ) { throw new VideoAPIException ( e ) ; } }
Creates a new video allowing a specific timeout while waiting for the video to downloaded and encoded.
Creates a new video allowing a specific timeout while waiting for the video to downloaded and encoded .
// We need a source URL before we can ingest the video // Make the request to the SafeStream REST API // Wait for the video to be ingested before returning // TODO: Have the ingest wait be on a separate thread