78.1.1+

Upload Media

TruvideoSdkMedia is a single class containing all functions required to manage the media module these are the methods required:

  • upload(TruvideoSdkMediaFileUploadCallback): uploadFile function upload file i.e. photo or video by takingTruvideoSdkMediaFileUploadCallback as input in the callback it provides the status as onComplete, onError, onProgressChanged.

  • Our transcriptions module simplifies video transcription. Upload videos effortlessly, initiate transcription, and retrieve results seamlessly, it's ideal for content management, media monitoring, and educational platforms.

Tags:

  • Option 1: Tags can be added directly to the TruvideoSdkMedia.FileUploadRequestBuilder using the addTag method.

    • Example:

builder.addTag("key", "value");
builder.addTag("color", "red");
builder.addTag("order-number", "123");
  • Option 2: Tags can be created using the TruvideoSdkMediaTags.builder() and then set on the builder.

    • Example:

TruvideoSdkMediaTags tags = TruvideoSdkMediaTags.builder()
                .set("key", "value")
                .set("color", "red")
                .set("order-number", "123")
                .build();
builder.setTags(tags);

Metadata:

  • Option 1: Metadata can be added directly to the TruvideoSdkMedia.FileUploadRequestBuilder using the addMetadata method.

    • Example:

builder.addMetadata("key", "value");
builder.addMetadata("list", new String[]{"value1", "value2"});
builder.addMetadata("nested", TruvideoSdkMediaMetadata.builder()
                .set("key", "value")
                .set("list", new String[]{"value1", "value2"})
                .build()
        );
  • Option 2: Metadata can be created using the TruvideoSdkMediaMetadata.builder() and then set on the builder.

    • Example:

TruvideoSdkMediaMetadata metadata = TruvideoSdkMediaMetadata
                .builder()
                .set("key", "value")
                .set("list", new String[]{"value1", "value2"})
                .set("nested", TruvideoSdkMediaMetadata.builder()
                        .set("key", "value")
                        .set("list", new String[]{"value1", "value2"})
                        .build()
                )
                .build();
builder.setMetadata(metadata);

Example Usage :

import com.truvideo.sdk.media.TruvideoSdkMedia;
import com.truvideo.sdk.media.builder.TruvideoSdkMediaFileUploadRequestBuilder;
import com.truvideo.sdk.media.interfaces.TruvideoSdkMediaCallback;
import com.truvideo.sdk.media.interfaces.TruvideoSdkMediaFileUploadCallback;
import com.truvideo.sdk.media.model.TruvideoSdkMediaFileType;
import com.truvideo.sdk.media.model.TruvideoSdkMediaFileUploadRequest;
import com.truvideo.sdk.media.model.TruvideoSdkMediaMetadata;
import com.truvideo.sdk.media.model.TruvideoSdkMediaTags;

public void upload(Context context, String filePath) {
    Loader loader = new Loader(context);
    loader.showLoader();
    final TruvideoSdkMediaFileUploadRequestBuilder builder = TruvideoSdkMedia.getInstance().FileUploadRequestBuilder(filePath);
    //Uri.fromFile(new File(filepath))

    // Option 1: use the file upload request builder directly
    builder.addTag("key", "value");
    builder.addTag("color", "red");
    builder.addTag("order-number", "123");

    // Option 2: use the tag builder
    TruvideoSdkMediaTags tags = TruvideoSdkMediaTags.builder()
            .set("key", "value")
            .set("color", "red")
            .set("order-number", "123")
            .build();
    builder.setTags(tags);

    // --------------------------
    // Metadata
    // --------------------------
    // Option 1: use the file upload request builder directly
    builder.addMetadata("key", "value");
    builder.addMetadata("list", new String[]{"value1", "value2"});
    builder.addMetadata("nested", TruvideoSdkMediaMetadata.builder()
            .set("key", "value")
            .set("list", new String[]{"value1", "value2"})
            .build()
    );


    // Option 2: use the metadata builder
    TruvideoSdkMediaMetadata metadata = TruvideoSdkMediaMetadata
            .builder()
            .set("key", "value")
            .set("list", new String[]{"value1", "value2"})
            .set("nested", TruvideoSdkMediaMetadata.builder()
                    .set("key", "value")
                    .set("list", new String[]{"value1", "value2"})
                    .build()
            )
            .build();
    builder.setMetadata(metadata);

    // Build request
    builder.build(new TruvideoSdkMediaCallback<TruvideoSdkMediaFileUploadRequest>() {
        @Override
        public void onComplete(TruvideoSdkMediaFileUploadRequest data) {
            // File upload request created successfully
            // Send to upload
            data.upload(new TruvideoSdkMediaCallback<Unit>() {
                        @Override
                        public void onComplete(Unit data) {
                            // Upload started successfully
                        }
                        @Override
                        public void onError(@NonNull TruvideoSdkException exception) {
                            // Upload started with error
                        }
                    },
                    new TruvideoSdkMediaFileUploadCallback() {
                        @Override
                        public void onError(@NonNull String id, @NonNull TruvideoSdkException ex) {
                            // Handle error uploading the file
                        }

                        @Override
                        public void onProgressChanged(@NonNull String id, float progress) {
                            // Handle uploading progress
                        }
                        @Override
                        public void onComplete(@NonNull String id, @NonNull TruvideoSdkMediaFileUploadRequest response) {
                            // File uploaded successfully
                        }
                }
            );
        }

        @Override
        public void onError(@NonNull TruvideoSdkException exception) {
            // Handle error creating the file upload request
        }
    });
}

Search Media -

The search function is designed to search for media files within the Truvideo SDK based on specified tags and media file type. The function constructs a tag set using the TruvideoSdkMediaTags builder and then performs a search for media files of the specified type, within the provided pagination limits.

Tags:

  • The function builds a set of tags using the TruvideoSdkMediaTags.builder() method.

TruvideoSdkMediaTags tags = TruvideoSdkMediaTags.builder()
    .set("key", "value")
    .set("color", "red")
    .set("order-number", "123")
    .build();

Search Query:

  • The search is performed using the TruvideoSdkMedia.search method with the following parameters:

    • tags: TruvideoSdkMediaTags: The tags to filter the search results.

    • type: TruvideoSdkMediaFileType: The type of media files to search for (e.g., Picture, Video).

    • pageNumber: Int: The starting point for the search results (used for pagination).

    • pageSize: Int: The maximum number of results to return.

Returns:

  • result: List<TruvideoSdkMediaFile>

    • The search results, which consist of a list of media files that match the specified tags and file type. The size of the list is limited by the limit parameter.

Example Usage :

import com.truvideo.sdk.media.TruvideoSdkMedia;
import com.truvideo.sdk.media.interfaces.TruvideoSdkMediaCallback;
import com.truvideo.sdk.media.model.TruvideoSdkMediaFileType;
import com.truvideo.sdk.media.model.TruvideoSdkMediaPaginatedResponse;
import com.truvideo.sdk.media.model.TruvideoSdkMediaResponse;
import com.truvideo.sdk.media.model.TruvideoSdkMediaTags;

public void search(){
    TruvideoSdkMediaTags tags = TruvideoSdkMediaTags
                .builder()
                .set("key", "value")
                .set("color", "red")
                .set("order-number", "123")
                .build();
    TruvideoSdkMedia.getInstance().search(tags, TruvideoSdkMediaFileType.Picture, 0, 10, new TruvideoSdkMediaCallback<TruvideoSdkMediaPaginatedResponse<TruvideoSdkMediaResponse>>() {
            @Override
            public void onComplete(TruvideoSdkMediaPaginatedResponse<TruvideoSdkMediaResponse> response) {

            }

            @Override
            public void onError(@androidx.annotation.NonNull TruvideoSdkException e) {

            }
        });

}

Note

  • The search function is a suspend function, indicating that it is designed to be called within a coroutine or another suspend function, as it may perform asynchronous operations.

  • The pageNumber and pageSize parameters allow for pagination, enabling the retrieval of a specific subset of the search results.

Last updated

Was this helpful?