Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video Uploading Status in Vimeo

I am uploading video in Vimeo using my Application,But some of my videos status are not getting updated Screenshot of the video in Vimeo website

I have followed the api document provided in this link: https://developer.vimeo.com/api/upload/videos:

I am using below code:

public  boolean sendVideo(String file1, String completeURi, String     endpoint, String id) throws FileNotFoundException, IOException {

    File file = new File(file1);

    long contentLength = file.length();
    String contentLengthString = Long.toString(contentLength);
    FileInputStream is = new FileInputStream(file);

    int bufferSize = 20485760; 
    byte[] bytesPortion = new byte[bufferSize];
    int byteNumber = 0;

    while (is.read(bytesPortion, 0, bufferSize) != -1) {
        String contentRange = Integer.toString(byteNumber);
        boolean success = false;
        int bytesOnServer = 0;

        while (!success) {
            long bytesLeft = contentLength - (bytesOnServer);
            System.out.println(newline + newline + "Bytes Left: " + bytesLeft);
            if (bytesLeft < bufferSize) {
                //copy the bytesPortion array into a smaller array containing only the remaining bytes
                bytesPortion = Arrays.copyOf(bytesPortion, (int) bytesLeft);
                //This just makes it so it doesn't throw an IndexOutOfBounds exception on the next while iteration. It shouldn't get past another iteration
                bufferSize = (int) bytesLeft;
            }
             bytesOnServer = sendVideoBytes("Vimeo Video upload", endpoint, contentLengthString, "video/mp4", contentRange, bytesPortion, first,isuploaded);

            AppLog.e("bytesOnServer", "===contentLength===" + bytesOnServer +"&&=="+contentLengthString);

            if (bytesOnServer >= Integer.parseInt(contentLengthString)) {

                System.out.println("Success is  true!");
                return true;

            } else {
                contentRange = (bytesOnServer + 1) + "-" + (Integer.parseInt(contentLengthString)) + "/" + (Integer.parseInt(contentLengthString));

                System.out.println(bytesOnServer + " != " + contentLength);
                System.out.println("Success is not true!"+contentRange);

                success=false;
                first = true;
            }

        }



    }
    return true;
}

/**
 * Sends the given bytes to the given endpoint
 *
 * @return the last byte on the server (from verifyUpload(endpoint))
 */
private static int sendVideoBytes(String videoTitle, String endpoint, String contentLength, String fileType, String contentRange, byte[] fileBytes, boolean addContentRange,boolean isuploaded) throws FileNotFoundException, IOException {
    OAuthRequest request = new OAuthRequest(Verb.PUT, endpoint);
    request.addHeader("Content-Length", contentLength);
    request.addHeader("Content-Type", fileType);


    if (addContentRange) {
        request.addHeader("Content-Range", "bytes " + contentRange);
    }


    request.addPayload(fileBytes);

    Response response = signAndSendToVimeo(request, "sendVideo with file bytes " + videoTitle, false);



    if (response.getCode() != 200 && !response.isSuccessful()) {
        return -1;
    }


    return verifyUpload(endpoint, contentLength, contentRange,isuploaded);
}

/**
 * Verifies the upload and returns whether it's successful
 *
 * @param
 * @param contentLength
 * @param endpoint      to verify upload to  @return the last byte on the server
 */
public static int verifyUpload(String endpoint, String contentLength, String contentRange,boolean isuploaded) {
    // Verify the upload
    OAuthRequest request = new OAuthRequest(Verb.PUT, endpoint);
    request.addHeader("Content-Length", "0");
    request.addHeader("Content-Range", "bytes */*");

    Response response = signAndSendToVimeo(request, "verifyUpload to " + endpoint, true);

    AppLog.e("verifyUpload", "" + response.getCode());
    if (response.getCode() != 308 || !response.isSuccessful()) {
        return -1;
    }
    String range = response.getHeader("Range");

    AppLog.e("After verify","==range header contains"+Integer.parseInt(range.substring(range.lastIndexOf("-") + 1)));
    //range = "bytes=0-10485759"
    return Integer.parseInt(range.substring(range.lastIndexOf("-") + 1)); //+1 remove
    //return Integer.parseInt(range.substring(range.lastIndexOf("-") + 1)) + 1;
    //The + 1 at the end is because Vimeo gives you 0-whatever byte where 0 = the first byte
}

public static Response signAndSendToVimeo(OAuthRequest request, String description, boolean printBody) throws org.scribe.exceptions.OAuthException {
    String newline = "\n";

    System.out.println(newline + newline
            + "Signing " + description + " request:"
            + ((printBody && !request.getBodyContents().isEmpty()) ? newline + "\tBody Contents:" + request.getBodyContents() : "")
            + ((!request.getHeaders().isEmpty()) ? newline + "\tHeaders: " + request.getHeaders() : ""));
    service.signRequest(OAuthConstants.EMPTY_TOKEN, request);



    Response response = request.send();
   // AppLog.e("Uplaod Video aftre Response", "" + response.getCode());

    return response;
}

Can anyone help with a working code for Android?? Thanks in advance!!

like image 402
Yyy Avatar asked Oct 06 '16 07:10

Yyy


1 Answers

I recently had the same problem with vimeo. The api returns the state VIMUploadState_Succeeded for the upload process, but if you try to watch the video at vimeo.com it is stucked in the uploading state and it shows a black screen in the app when you try to reproduce the video.

I got the following answers from their support team:

It looks like this specific video didn't change from the uploaded state to a failure state.

Sorry but the videos provided in those links never finished uploading and are lost. They will need to be re-uploaded.

In our platform there are several videos uploaded everyday and it seems to have no pattern to identify when this uploading problem will happen. If it is not a problem for you to re-upload the video, vimeo can be a good solution since its price is really good in comparison to other video platforms, otherwise you should look for another video storage/playback solution.

like image 92
Naka Avatar answered Nov 10 '22 08:11

Naka