bmdrm_plugin 0.0.1 copy "bmdrm_plugin: ^0.0.1" to clipboard
bmdrm_plugin: ^0.0.1 copied to clipboard

A Flutter plugin for DRM-protected video playback with watermark support.

example/lib/main.dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:bmdrm_plugin/bmdrm_video_player.dart';
import 'package:bmdrm_plugin/dart_drm_service.dart' as drm_service;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'BMDRM Player',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const MyHomePage(),
    );
  }
}

enum DrmMethod {
  drmMinimal,
  drmWithSession,
  drmFromBackendSession,
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DrmMethod _selectedMethod = DrmMethod.drmMinimal;
  
  // Example credentials - replace with your actual values
  final String _apiKey =
      "3oMSMnwas37VzQK8thTuc3rKQdrkqv42UruQkX8crME86z74J8znLkNQh3z4WZabC7vhGSkvX7dADb94YU7vofhQFSVBPc9hb2C2YaAQtPCYkhcQhWPe2rDHuFVBYzkmMKeUFB3pvMcTBYZSWjS22h4JDS3Vf1atTGymVnieLj9e4LcoHjjLfexA5bUZUJdNQT5bL";
  final String _userId = "dfghjk";
  final String _videoId = "a3b3cc07-3fc1-4cea-bfa2-972b9e490dfa";

  final String _preGeneratedSessionJson = '''
{"edge":"https://edge-6.video-crypt.com","videoId":"5af6c922-bc03-43e5-b3d6-af7cc37a2bc2","signature":"3oAP9QVyGjMStAzJ3TnhMAf4zRuHkiTvALRmaUA18pPpAfRMkfzskJBFLWUAcT5HHLrSLJxEoaiRbTdDFmwZLHvL","userId":"appostedhy","subscriptionId":"5af6c922-0f99-4fac-92d1-aecd7aefc180","sessionId":"d948eec5-03c3-463a-9781-060a61e5da53","nonce":"1e9423b5d42b7bf","date":1766582089}
''';

  // Example DrmSessionData JSON - replace with your actual session data
  final String _drmSessionDataJson = '''
{
  "edgeName": "https://edge-6.video-crypt.com",
  "token": "your-session-token",
  "ecdsaKey": "your-ecdsa-key",
  "drmServerUrl": "https://license-server.com/license"
}
''';

  @override
  Widget build(BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;
    final videoHeight = screenWidth * 9 / 16;

    return Scaffold(
      backgroundColor: Colors.red,

      body: SafeArea(
        child: Column(
          children: [
            // Method selector

            // Player
            Expanded(
              child: Center(
                child: _buildPlayer(videoHeight),
              ),
            ),
          ],
        ),
      ),
    );
  }


  Widget _buildPlayer(double videoHeight) {
    try {
      switch (_selectedMethod) {
        case DrmMethod.drmMinimal:
          return _buildDrmMinimalPlayer(videoHeight);
        case DrmMethod.drmWithSession:
          return _buildDrmWithSessionPlayer(videoHeight);
        case DrmMethod.drmFromBackendSession:
          return _buildDrmFromBackendSessionPlayer(videoHeight);
      }
    } catch (e) {
      return Container(
        width: double.infinity,
        height: videoHeight,
        color: Colors.black,
        child: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text(
              'Error: $e',
              style: const TextStyle(color: Colors.red),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      );
    }
  }

  Widget _buildDrmMinimalPlayer(double videoHeight) {
    return BmdrmVideoPlayer.drmMinimal(
      apiKey: _apiKey,
      userId: _userId,
      videoId: _videoId,
      watermarkConfig: null,
      width: double.infinity,
      height: videoHeight,
      autoPlay: true,
      onError: (error) {
        debugPrint('DRM Minimal Error: $error');
      },
      onPlay: () {
        debugPrint('DRM Minimal: Video started playing');
      },
      onPause: () {
        debugPrint('DRM Minimal: Video paused');
      },
    );
  }

  Widget _buildDrmWithSessionPlayer(double videoHeight) {
    try {
      final sessionMap = jsonDecode(_drmSessionDataJson);
      final drmSessionData = drm_service.DrmSessionData.fromJson(sessionMap);
      
      return BmdrmVideoPlayer.drmWithSession(
        drmSessionData: drmSessionData,
        watermarkConfig: null,
        width: double.infinity,
        height: videoHeight,
        autoPlay: true,
        onError: (error) {
          debugPrint('DRM With Session Error: $error');
        },
        onPlay: () {
          debugPrint('DRM With Session: Video started playing');
        },
        onPause: () {
          debugPrint('DRM With Session: Video paused');
        },
      );
    } catch (e) {
      return Container(
        width: double.infinity,
        height: videoHeight,
        color: Colors.black,
        child: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text(
              'Error parsing session data: $e\n\nPlease update _drmSessionDataJson with valid session data.',
              style: const TextStyle(color: Colors.red),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      );
    }
  }

  Widget _buildDrmFromBackendSessionPlayer(double videoHeight) {
    try {
      final sessionMap = jsonDecode(_preGeneratedSessionJson);
      return BmdrmVideoPlayer.drmFromBackendSession(
        backendSession: sessionMap,
        watermarkConfig: null,
        width: double.infinity,
        height: videoHeight,
        autoPlay: true,
        onError: (error) {
          debugPrint('DRM From Backend Session Error: $error');
        },
        onPlay: () {
          debugPrint('DRM From Backend Session: Video started playing');
        },
        onPause: () {
          debugPrint('DRM From Backend Session: Video paused');
        },
      );
    } catch (e) {
      return Container(
        width: double.infinity,
        height: videoHeight,
        color: Colors.black,
        child: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text(
              'Error parsing backend session: $e',
              style: const TextStyle(color: Colors.red),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      );
    }
  }
}
0
likes
120
points
150
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for DRM-protected video playback with watermark support.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

crypto, flutter, http, plugin_platform_interface, pointycastle

More

Packages that depend on bmdrm_plugin

Packages that implement bmdrm_plugin