truvideo_media_sdk 1.0.2
truvideo_media_sdk: ^1.0.2 copied to clipboard
Manages cloud-based media operations, including uploading photos/videos and generating links, with support for canceling uploads.
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:truvideo_media_sdk/media_builder.dart';
import 'package:truvideo_media_sdk/truvideo_media_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
performUploadFlow();
}
Future<void> performUploadFlow() async {
try {
// Create a new MediaBuilder with a test file path
final builder = MediaBuilder("/sdcard/DCIM/test.mp4")
..setTag("color", "blue")
..setTag("source", "flutter-sdk")
..setMetaData("uploadedBy", "truvideo");
// Build the media upload request
await builder.build();
final mediaId = builder.getMediaId();
debugPrint("Upload media ID is: $mediaId");
// Start the upload with event callbacks
await builder.upload(
onProgress: (e) => debugPrint("Progress: ${e['progress']}%"),
onComplete: (e) => debugPrint("Upload Complete: ${e['remoteURL']}"),
onError: (e) => debugPrint("Upload Failed: ${e['error']}"),
);
// Get info about the same file by ID (replace with actual ID)
final json = await TruvideoMediaSdk.getFileUploadRequestById(
builder.getMediaId()!);
debugPrint("Single Upload Request:\n$json");
// Get all saved upload requests
final all = await TruvideoMediaSdk.getAllFileUploadRequests();
debugPrint("All Upload Requests:\n$all");
} catch (e) {
debugPrint('Upload flow failed: $e');
}
}
Future<void> initPlatformState() async {
try {
final version = await TruvideoMediaSdk.getPlatformVersion();
setState(() {
_platformVersion = version ?? 'Unknown';
});
} catch (e) {
setState(() {
_platformVersion = 'Failed to get version: $e';
});
}
}
Future<void> searchMediaExample() async {
try {
// Define a tag map to search by (same keys used during upload)
Map<String, String> tagMap = {
"color": "blue",
"source": "flutter-sdk",
};
// Convert to JSON string
String tagJson = jsonEncode(tagMap);
// Call the search method (you already exposed it in your SDK)
String? response = await TruvideoMediaSdk.search(
tagJson: tagJson,
type: "All", // Or: Video, AUDIO, PDF, Picture
page: 1,
pageSize: 10,
);
debugPrint("Search result:\n$response");
} catch (e) {
debugPrint("Search failed: $e");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Truvideo SDK Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Running on: $_platformVersion'),
const SizedBox(height: 24),
ElevatedButton(
onPressed: performUploadFlow,
child: const Text("Test MediaBuilder Upload"),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: searchMediaExample,
child: const Text("Search Media"),
),
],
),
),
),
);
}
}