jhomlala / betterplayer

Better video player for Flutter, with multiple configuration options. Solving typical use cases!
Apache License 2.0
889 stars 929 forks source link

[BUG] Wrong duration when playing Clear Key encrypted video #1262

Open mouhandalkadri opened 8 months ago

mouhandalkadri commented 8 months ago

History check No issues mentioned this bug before

Describe the bug When trying to play a video encrypted by Clear Key better_player shows wrong duration. for example we tried to play the video provided in the examples we are getting duration of 00:00. Even though the video is playing perfectly fine but the total duration is stuck at 00:00.

  To Reproduce

  1. Install better_player
  2. Initialize video with clear key
  3. Use this link https://github.com/tinusneethling/betterplayer/raw/ClearKeySupport/example/assets/testvideo_encrypt.mp4 (The one provided in the example)
  4. Use the following keys { "f3c5e0361e6654b28f8049c778b23946": "a4631a153a443df9eed0593043db7519", "abba271e8bcf552bbd2e86a434a9a5d9": "69eaa802a6763af979e8d1940fb88392" }

*Example code

import 'package:better_player/better_player.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const BetterPlayerWithBug(),
    );
  }
}

class BetterPlayerWithBug extends StatefulWidget {
  const BetterPlayerWithBug({Key? key}) : super(key: key);

  @override
  State<BetterPlayerWithBug> createState() => _BetterPlayerWithBugState();
}

class _BetterPlayerWithBugState extends State<BetterPlayerWithBug> {

  late BetterPlayerController _betterPlayerController;

  @override
  void initState() {

    BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource(
      BetterPlayerDataSourceType.network,
      "https://github.com/tinusneethling/betterplayer/raw/ClearKeySupport/example/assets/testvideo_encrypt.mp4",

      drmConfiguration: BetterPlayerDrmConfiguration(
        drmType: BetterPlayerDrmType.clearKey,
        clearKey: BetterPlayerClearKeyUtils.generateKey(({
            "f3c5e0361e6654b28f8049c778b23946":
                "a4631a153a443df9eed0593043db7519",
            "abba271e8bcf552bbd2e86a434a9a5d9":
                "69eaa802a6763af979e8d1940fb88392"
          })),
      ),
    );
    _betterPlayerController = BetterPlayerController(
      const BetterPlayerConfiguration(
        autoPlay: true,
      ),
    );

    _betterPlayerController.setupDataSource(betterPlayerDataSource);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          const SizedBox(height: 40,),
          Container(
            margin: const EdgeInsets.only(bottom: 15.0),
            height: 220,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(15.0),
              child: SizedBox(
                child: BetterPlayer(
                  controller: _betterPlayerController,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Expected behavior The player should show the right duration

Better Player version