Truvideo Media SDK

This Flutter plugin integrates the TruvideoMediaSdk for uploading media files (videos, images, etc.) with rich metadata and tags. It also allows retrieving upload progress and searching media based on tags.

Supported Platforms

  • Android
  • iOS

Features

  • Upload media files (e.g., videos) with tags and metadata
  • Track upload progress, success, and errors with callbacks
  • Search media based on uploaded tags
  • Retrieve upload metadata by ID or fetch all uploads

Requirements

  • TruvideoMediaSdk Plugin

Setup

  1. Add TruvideoMediaSdk Plugin to your project.
  2. Install dependencies:
    flutter pub get
    
  3. Ensure proper permissions in AndroidManifest.xml & Info.plist.
  4. Run the app:
    flutter run
    

Usage

Upload Request:

  • Create new upload request with a file path.
  • Set tags and metadata for the upload (optional).
  • Build the request and start the upload.
  • Track upload progress, success, and errors with callbacks.
Future<void> createUploadRequest(String filePath) async {
  try {
    // Create a new MediaBuilder with a test file path
    final builder = MediaBuilder(filePath)
      ..setTag("color", "blue")
      ..setTag("source", "flutter-sdk")
      ..setMetaData("uploadedBy", "truvideo");

    // Build the media upload request
    await builder.build();

    final mediaId = builder.getMediaId();
    print("Upload media ID is: $mediaId");

    // Start the upload with event callbacks
    await builder.upload(
      onProgress: (e) => print("Upload Progess: ${e['progress']}%"),
      onComplete: (e) => print("Upload Complete: ${e['remoteURL']}"),
      onError: (e) => print("Upload Failed: ${e['error']}"),
    );
  } catch (e) {
    debugPrint('Upload flow failed: $e');
  }
}

Get request by ID

  • Use getFileUploadRequestById function to fetch request associated with the id. The function will return MediaBuilder? object.
void getRequestById(String id) async {
  try {
    MediaBuilder? requests =  await TruvideoMediaSdk.getFileUploadRequestById(id);

    if (requests != null) {
      print(request.mediaDetail?.id);
    }
  } on PlatformException catch (e) {
    print('Error while fetching upload request: ${e.message}');
  }
}

Get all requests

  • Use getAllFileUploadRequests function to fetch all the file upload request. The function will return List
void getAllUploadRequest() async {
  try {
    List<MediaBuilder>? result = await TruvideoMediaSdk.getAllFileUploadRequests();

    if (result != null) {
      for(var request in result){
          print(request.mediaDetail?.id);
      }
    }
  } on PlatformException catch (e) {
    print('Error while fetching upload requests: ${e.message}');
  }
}

Get All Stream Upload Requests

  • Use getAllStreamUploadRequests function to fetch all the stream upload requests. The function will return List
void getAllStreamUploadRequests() async {
  try {
    List<TruvideoSdkStreamUploadRequest>? result = await TruvideoMediaSdk.getAllStreamUploadRequests();

    if (result != null) {
      for (var request in result) {
        print(request.id);
      }
    }
  } on PlatformException catch (e) {
    print('Error while fetching stream upload requests: ${e.message}');
  }
}

Get Stream Upload Request by ID

  • Use getStreamUploadRequestById function to fetch a specific stream upload request using it's id. The function will return TruvideoSdkStreamUploadRequest?.
void getStreamUploadRequestById(String id) async {
  try {
    TruvideoSdkStreamUploadRequest? request = await TruvideoMediaSdk.getStreamUploadRequestById(id);

    if (request != null) {
      print(request.id);
    }
  } on PlatformException catch (e) {
    print('Error while fetching stream upload request: ${e.message}');
  }
}

Upload Stream Upload Request

  • Use streamUploadMedia function to start uploading a stream media by providing required id and other optional parameters.
void uploadStreamRequest(String id, String? title, String? tagJson, String? metadataJson) async {
  try {
    String? result = await TruvideoMediaSdk.streamUploadMedia(
      id: id,
      title: title,
      tagJson: tagJson,
      metaDataJson: metadataJson,
      includeInReport: false,
      isLibrary: false,
    );

    if (result != null) {
      print(result);
    }
  } on PlatformException catch (e) {
    print('Error while uploading stream media: ${e.message}');
  }
}

Pause Stream Upload Request

  • Use streamPauseMedia function to pause an ongoing stream upload.
void pauseStreamRequest(String id) async {
  try {
    String? result = await TruvideoMediaSdk.streamPauseMedia(id);

    if (result != null) {
      print(result);
    }
  } on PlatformException catch (e) {
    print('Error while pausing stream media: ${e.message}');
  }
}

Resume Stream Upload Request

  • Use streamResumeMedia function to resume a paused stream upload.
void resumeStreamRequest(String id) async {
  try {
    String? result = await TruvideoMediaSdk.streamResumeMedia(id);

    if (result != null) {
      print(result);
    }
  } on PlatformException catch (e) {
    print('Error while resuming stream media: ${e.message}');
  }
}

Retry Stream Upload Request

  • Use streamRetryMedia function to retry a failed stream upload.
void retryStreamRequest(String id) async {
  try {
    String? result = await TruvideoMediaSdk.streamRetryMedia(id);

    if (result != null) {
      print(result);
    }
  } on PlatformException catch (e) {
    print('Error while retrying stream media: ${e.message}');
  }
}

Delete Stream Upload Request

  • Use streamDeleteMedia function to delete a stream upload request.
void deleteStreamRequest(String id) async {
  try {
    String? result = await TruvideoMediaSdk.streamDeleteMedia(id);

    if (result != null) {
      print(result);
    }
  } on PlatformException catch (e) {
    print('Error while deleting stream media: ${e.message}');
  }
}

Search Media

  • Search/fetch uploaded Media
  Future<void> searchMedia() async {
  try {
    Map<String, String> tags = {"color": "blue", "source": "flutter-sdk"};

    final response = await mediaSdkWrapper.search(
      tagJson: jsonEncode(tags),
      type: 'all', // 'all', 'video', 'image'
      page: 1,
      pageSize: 10,
      addedToLibrary: true,
    );

    if (response != null && response.data != null) {
      print(response.data.toString());
    }
  } on PlatformException catch (e) {
    print('Error on search media: ${e.message}');
  }
}

License

MIT

Support

If you have any questions or suggestions regarding the SDK, please contact us at support@truvideo.com.