Search in sources :

Example 1 with ShareVideo

use of com.facebook.share.model.ShareVideo in project facebook-android-sdk by facebook.

the class VideoUploader method uploadAsync.

public static synchronized void uploadAsync(ShareVideoContent videoContent, String graphNode, FacebookCallback<Sharer.Result> callback) throws FileNotFoundException {
    if (!initialized) {
        registerAccessTokenTracker();
        initialized = true;
    }
    Validate.notNull(videoContent, "videoContent");
    Validate.notNull(graphNode, "graphNode");
    ShareVideo video = videoContent.getVideo();
    Validate.notNull(video, "videoContent.video");
    Uri videoUri = video.getLocalUrl();
    Validate.notNull(videoUri, "videoContent.video.localUrl");
    UploadContext uploadContext = new UploadContext(videoContent, graphNode, callback);
    uploadContext.initialize();
    pendingUploads.add(uploadContext);
    enqueueUploadStart(uploadContext, 0);
}
Also used : ShareVideo(com.facebook.share.model.ShareVideo) Uri(android.net.Uri)

Example 2 with ShareVideo

use of com.facebook.share.model.ShareVideo in project facebook-android-sdk by facebook.

the class RequestTests method testUploadVideoFile.

@LargeTest
public void testUploadVideoFile() throws IOException, URISyntaxException {
    File tempFile = null;
    try {
        tempFile = createTempFileFromAsset("DarkScreen.mov");
        ShareVideo video = new ShareVideo.Builder().setLocalUrl(Uri.fromFile(tempFile)).build();
        ShareVideoContent content = new ShareVideoContent.Builder().setVideo(video).build();
        final ShareApi shareApi = new ShareApi(content);
        final AtomicReference<String> videoId = new AtomicReference<>(null);
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                shareApi.share(new FacebookCallback<Sharer.Result>() {

                    @Override
                    public void onSuccess(Sharer.Result result) {
                        videoId.set(result.getPostId());
                        notifyShareFinished();
                    }

                    @Override
                    public void onCancel() {
                        notifyShareFinished();
                    }

                    @Override
                    public void onError(FacebookException error) {
                        notifyShareFinished();
                    }

                    private void notifyShareFinished() {
                        synchronized (shareApi) {
                            shareApi.notifyAll();
                        }
                    }
                });
            }
        });
        synchronized (shareApi) {
            shareApi.wait(REQUEST_TIMEOUT_MILLIS);
        }
        assertNotNull(videoId.get());
    } catch (Exception ex) {
        fail();
    } finally {
        if (tempFile != null) {
            tempFile.delete();
        }
    }
}
Also used : ShareVideo(com.facebook.share.model.ShareVideo) AtomicReference(java.util.concurrent.atomic.AtomicReference) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) IOException(java.io.IOException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) Sharer(com.facebook.share.Sharer) File(java.io.File) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 3 with ShareVideo

use of com.facebook.share.model.ShareVideo in project facebook-android-sdk by facebook.

the class RequestTests method testUploadVideoFileToUserId.

@LargeTest
public void testUploadVideoFileToUserId() throws IOException, URISyntaxException {
    File tempFile = null;
    try {
        GraphRequest meRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), null);
        GraphResponse meResponse = meRequest.executeAndWait();
        JSONObject meJson = meResponse.getJSONObject();
        assertNotNull(meJson);
        String userId = meJson.optString("id");
        assertNotNull(userId);
        tempFile = createTempFileFromAsset("DarkScreen.mov");
        ShareVideo video = new ShareVideo.Builder().setLocalUrl(Uri.fromFile(tempFile)).build();
        ShareVideoContent content = new ShareVideoContent.Builder().setVideo(video).build();
        final ShareApi shareApi = new ShareApi(content);
        shareApi.setGraphNode(userId);
        final AtomicReference<String> videoId = new AtomicReference<>(null);
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                shareApi.share(new FacebookCallback<Sharer.Result>() {

                    @Override
                    public void onSuccess(Sharer.Result result) {
                        videoId.set(result.getPostId());
                        notifyShareFinished();
                    }

                    @Override
                    public void onCancel() {
                        notifyShareFinished();
                    }

                    @Override
                    public void onError(FacebookException error) {
                        notifyShareFinished();
                    }

                    private void notifyShareFinished() {
                        synchronized (shareApi) {
                            shareApi.notifyAll();
                        }
                    }
                });
            }
        });
        synchronized (shareApi) {
            shareApi.wait(REQUEST_TIMEOUT_MILLIS);
        }
        assertNotNull(videoId.get());
    } catch (Exception ex) {
        fail();
    } finally {
        if (tempFile != null) {
            tempFile.delete();
        }
    }
}
Also used : ShareVideo(com.facebook.share.model.ShareVideo) AtomicReference(java.util.concurrent.atomic.AtomicReference) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) ShareVideoContent(com.facebook.share.model.ShareVideoContent) Sharer(com.facebook.share.Sharer) File(java.io.File) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 4 with ShareVideo

use of com.facebook.share.model.ShareVideo in project facebook-android-sdk by facebook.

the class ShareInternalUtility method getAttachment.

private static NativeAppCallAttachmentStore.Attachment getAttachment(UUID callId, ShareMedia medium) {
    Bitmap bitmap = null;
    Uri uri = null;
    if (medium instanceof SharePhoto) {
        SharePhoto photo = (SharePhoto) medium;
        bitmap = photo.getBitmap();
        uri = photo.getImageUrl();
    } else if (medium instanceof ShareVideo) {
        ShareVideo video = (ShareVideo) medium;
        uri = video.getLocalUrl();
    }
    return getAttachment(callId, uri, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) ShareVideo(com.facebook.share.model.ShareVideo) Uri(android.net.Uri)

Aggregations

ShareVideo (com.facebook.share.model.ShareVideo)4 Uri (android.net.Uri)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 ShareApi (com.facebook.share.ShareApi)2 Sharer (com.facebook.share.Sharer)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 File (java.io.File)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 JSONException (org.json.JSONException)2 Bitmap (android.graphics.Bitmap)1 SharePhoto (com.facebook.share.model.SharePhoto)1 JSONObject (org.json.JSONObject)1