I am using youtube_player_flutter: ^7.0.0+7 to display youtube videos in my flutter app. When users play videos, the screen becomes black and sound of video continues. Users are unable to watch videos. They only listen to it. The problem occurs in some devices(usually in oppo phones). Any kind of help is much appreciated. Kindly help! Here is my code:

import 'package:ali_patente/constant/style.dart';
import 'package:flutter/material.dart';
import 'package:flutter_windowmanager/flutter_windowmanager.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';

class Player extends StatefulWidget {
  final Map video;

  Player({this.video});

  @override
  _PlayerState createState() => _PlayerState();
}

class _PlayerState extends State<Player> {
  YoutubePlayerController myController;

  void runYoutubePlayer() {
    myController = YoutubePlayerController(
      initialVideoId: YoutubePlayer.convertUrlToId(widget.video['link']),
      flags: YoutubePlayerFlags(
        enableCaption: false,
        isLive: false,
        autoPlay: true,
      ),
    );
  }

  @override
  void initState() {
    runYoutubePlayer();
    // TODO: implement initState
    super.initState();
  }

  @override
  void deactivate() {
    myController.pause();
    // TODO: implement deactivate
    super.deactivate();
  }

  @override
  void dispose() {
    myController.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
    return Scaffold(
        body: Card(
          child: YoutubePlayer(
            controller: myController,
            showVideoProgressIndicator: true,
            progressIndicatorColor: Colors.amber,
            progressColors: ProgressBarColors(
              handleColor: Colors.red,
              playedColor: Colors.amber,
            ),
          ),
        ),
      );
  }
}

Thank you in advance!


Solution 1: Jeel Bhatti

https://pub.dev/packages/youtube_player_flutter

dependencies:
  youtube_player_flutter: ^8.0.0

Android: minSdkVersion 17 and add support for androidx (see AndroidX Migration)
Set minSdkVersion of your android/app/build.gradle file to at least 17

check your minSdkVersion.