1

Currently, I have managed to display movies with the .mkv extension, but these movies have several languages ​​or subtitles, in other video players there is the ability to switch between audio and subtitles, but nothing is displayed in my video player. It should be noted that I can add audio or subtitles to the video, but I want to use the sound and subtitles attached to the .mkv video file. What do you think is the solution to this problem?

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

 
var src =
    'https://dl5.freeserver.top/www2/film/animation2/The.Croods.2013.1080p.BluRay.SoftSub.DigiMoviez.mkv';

class SubtitlesPage extends StatefulWidget {
  @override
  _SubtitlesPageState createState() => _SubtitlesPageState();
}

final videoPlayerController = VideoPlayerController.network(src);

class _SubtitlesPageState extends State<SubtitlesPage> {
  late BetterPlayerController _betterPlayerController;

  @override
  void initState() {
    BetterPlayerConfiguration betterPlayerConfiguration =
        const BetterPlayerConfiguration(
      aspectRatio: 16 / 9,
      fit: BoxFit.contain,
      subtitlesConfiguration: BetterPlayerSubtitlesConfiguration(
        backgroundColor: Colors.green,
        fontColor: Colors.white,
        outlineColor: Colors.black,
        fontSize: 20,
      ),
    );

    _betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
    _betterPlayerController.addEventsListener((event) {
      if (event.betterPlayerEventType == BetterPlayerEventType.progress) {
        log("Current subtitle line: ${_betterPlayerController.renderedSubtitle}");
      }
    });
    _setupDataSource();
    super.initState();
  }

  void _setupDataSource() async {
    BetterPlayerDataSource dataSource = BetterPlayerDataSource(
      BetterPlayerDataSourceType.network,
      src,
      subtitles: BetterPlayerSubtitlesSource.single(
        type: BetterPlayerSubtitlesSourceType.file,
        url: src,
        name: "My subtitles",
        selectedByDefault: true,
      ),
    );
    _betterPlayerController.setupDataSource(dataSource);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Subtitles"),
      ),
      body: Column(children: [
        const SizedBox(height: 8),
        AspectRatio(
          aspectRatio: 16 / 9,
          child: BetterPlayer.network(src),
        )
      ]),
    );
  }
}
Mohammad
  • 36
  • 1
  • 8
  • Hi @Mohammad, can you share how to play the MKV file? Thank you in advance! – leegor Jul 17 '22 at 02:42
  • @leegor Hi The main problem was related to the implementation of video codecs There was no problem in **better_player** about playing the video and the original sound, but to select the sound tracks or subtitles, this feature is possible by finding tracks. To solve this problem, our team used **exoplayer** and designed a new video player In general, using flutter creates limitations for these cases, and it is better to use native This was the solution we found, and if there is another solution, I don't know about it – Mohammad Jul 17 '22 at 05:45
  • you can try flutter_vlc_player – Sheikh Haziq Jul 21 '22 at 07:07

0 Answers0