Skip to main content

Flutter SDK quick integration

The current plugin is meshstream_p2p 1.0.8, published on pub.dev. It exposes the native playback URL and status to your Flutter player; it does not provide a player or decoder.

Before running the code, complete Installation and setup, prepare your SDK Key and playable media URL, and configure the application network policy.

Minimal integration​

import 'package:meshstream_p2p/meshstream_p2p.dart';
import 'package:video_player/video_player.dart';

final client = await MeshStream.create(
MeshStreamConfig(key: 'your_sdk_key'),
);
final session = await client.createPlaybackSession(
PlaybackSessionOptions(
url: 'https://cdn.example.com/live/playlist.m3u8',
contentId: 'live-channel-42',
mimeType: MeshStreamMimeType.m3u8,
),
);
final controller = VideoPlayerController.networkUrl(
Uri.parse(session.playbackUrl),
);
await controller.initialize();
await controller.play();

Dispose the player first, then close the session and client:

await controller.dispose();
await session.close();
await client.close();

When P2P is unavailable, the session playback URL continues through CDN. Use session.getStats(), session.getDiagnostics(), and client.getStatus() for diagnostics; do not stop the player because acceleration is unavailable.

Run the official example​

Get the example from the Flutter SDK repository, then run these commands from its example directory:

flutter pub get
flutter devices
flutter run --target lib/main.dart

Add -d DEVICE_ID when multiple devices are connected. Enter your SDK Key from the console and a playable media URL, then select Create session to view playback and P2P/CDN statistics. Replace the input hints with your own valid values.

Standalone Android Demo and APK​

To use the Demo independently of your development tools, build and launch a Release version from example. Replace YOUR_ANDROID_DEVICE_ID with the ID shown by flutter devices:

flutter run --release --target lib/main.dart -d YOUR_ANDROID_DEVICE_ID

To produce an APK for distribution, run:

flutter build apk --release --target lib/main.dart

The APK is written to build/app/outputs/flutter-apk/app-release.apk. Before publishing your own application, configure its application ID, version, and production signing according to Flutter's Android release process.

Preload and lifecycle​

For a content list, create a separate session for the next item and call await session.preload(). Reuse that session only when playback starts, and close it when the candidate is discarded. Cancel event subscriptions and release the player, session, and client when the screen is destroyed.

Version and verification​

The Flutter package version is independent of the native SDK versions. Record the package, native Android/iOS SDK, platform, and player versions in diagnostics. See the Flutter SDK repository for the example and release records.

Related guides: Installation and setup · Advanced usage.