bmdrm_mobile 0.0.1 copy "bmdrm_mobile: ^0.0.1" to clipboard
bmdrm_mobile: ^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_mobile/bmdrm_video_player.dart';
import 'package:bmdrm_mobile/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> {
  final DrmMethod _selectedMethod = DrmMethod.drmFromBackendSession;

  // Replace with your actual credentials from BMDRM dashboard
  final String _apiKey = "YOUR_API_KEY_HERE";
  final String _userId = "YOUR_USER_ID_HERE";
  final String _videoId = "YOUR_VIDEO_ID_HERE";

  // Replace with your actual pre-generated backend session JSON
  final String _preGeneratedSessionJson = '''
  {
    "edge": "https://your-edge-server.example.com",
    "videoId": "your-video-id-here",
    "signature": "your-signature-here",
    "userId": "your-user-id-here",
    "subscriptionId": "your-subscription-id-here",
    "sessionId": "your-session-id-here",
    "nonce": "your-nonce-here",
    "date": 0
  }
''';

  // Replace with your actual DRM session data
  final String _drmSessionDataJson = '''
{
  "edgeName": "https://your-edge-server.com",
  "token": "your-session-token",
  "ecdsaKey": "your-ecdsa-key",
  "drmServerUrl": "https://your-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,
            ),
          ),
        ),
      );
    }
  }
}
2
likes
140
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

crypto, flutter, http, plugin_platform_interface, pointycastle

More

Packages that depend on bmdrm_mobile

Packages that implement bmdrm_mobile