Player congela vídeo!

Flutter

20/11/2022

Olá galera tenho um projeto de um app de filmes e ao executar o filme ele roda de boa mais o problema é que depois de uns 15 a 20 minutos o vídeo congela e não reproduz, mas e fica com a imagem congelada.
Alguém poderia min ajudar a resolver isto? estou usando os seguintes códigos.

video_player.dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import ''dart:async'';

import ''package:better_player/better_player.dart'';
import ''package:chewie/chewie.dart'';
import ''package:flutter/cupertino.dart'';
import ''package:flutter/foundation.dart'';
import ''package:flutter/material.dart'';
import ''package:flutter/services.dart'';
import ''package:flutter_app_tv/api/api_rest.dart'';
import ''package:flutter_app_tv/model/channel.dart'';
import ''package:flutter_app_tv/model/episode.dart'';
import ''package:flutter_app_tv/model/season.dart'';
import ''package:flutter_app_tv/ui/dialogs/subscribe_dialog.dart'';
import ''package:flutter_app_tv/ui/dialogs/subtitles_dialog.dart'' as ui;
import ''package:flutter_app_tv/model/subtitle.dart'' as model;
import ''package:flutter_app_tv/ui/dialogs/sources_dialog.dart'' as ui;
import ''package:flutter_app_tv/model/poster.dart'';
import ''package:flutter_app_tv/model/source.dart'';
import ''package:flutter_app_tv/model/subtitle.dart'';
import ''package:flutter_app_tv/ui/setting/settings.dart'';
import ''package:flutter_app_tv/ui/player/video_controller_widget.dart'' as ui;
import ''package:flutter_app_tv/ui/home/home.dart'';
import ''package:flutter_app_tv/key_code.dart'';
import ''package:flutter_app_tv/ui/player/subtitle_widget.dart'';
import ''package:scrollable_positioned_list/scrollable_positioned_list.dart'';
import ''package:seekbar/seekbar.dart'';
import ''package:shared_preferences/shared_preferences.dart'';

import ''dart:convert'' as convert;

import ''package:url_launcher/url_launcher.dart'';

/// An example of using the plugin, controlling lifecycle and playback of the
/// video.

class VideoPlayer extends StatefulWidget {
List sourcesList = [];
List sourcesListDialog = [];
Poster poster;
Channel channel;
int episode;
int season;

int next_episode;
int next_season;
String next_title = "";

List seasons = [];
int selected_source = 0;
int focused_source = 0;
bool next = false;
bool live = false;
bool _play_next_episode = false;

VideoPlayer(
{this.sourcesList,
this.selected_source,
this.focused_source,
this.poster,
this.episode,
this.seasons,
this.season,
this.channel});

@OverRide
_VideoPlayerState createState() => _VideoPlayerState();
}

class _VideoPlayerState extends State
with SingleTickerProviderStateMixin {
List _list_text_bg = [
Colors.transparent,
Colors.black,
Colors.white,
Colors.red,
Colors.green,
Colors.blue,
Colors.yellow,
Colors.orange,
Colors.brown,
Colors.purple,
Colors.pink,
Colors.teal
];
List _list_text_color = [
Colors.black,
Colors.white,
Colors.red,
Colors.green,
Colors.blue,
Colors.yellow,
Colors.orange,
Colors.brown,
Colors.purple,
Colors.pink,
Colors.teal
];
BetterPlayerController _betterPlayerController;

AnimationController _animated_controller;
ItemScrollController _subtitlesScrollController = ItemScrollController();
ItemScrollController _sourcesScrollController = ItemScrollController();

bool _visibile_controllers = true;
bool _visibile_subtitles_dialog = false;
bool visibileSourcesDialog = false;
bool _visibile_subtitles_loading = true;

Timer _visibile_controllers_future;

FocusNode video_player_focus_node = FocusNode();

int _selected_subtitle = 0;
int _focused_subtitle = 0;

int _video_controller_play_position = 0;
int _video_controller_slider_position = 1;
int _video_controller_settings_position = 2;
bool visible_subscribe_dialog = false;

List<model.Subtitle> _subtitlesList = [];

int post_x = 0;
int post_y = 0;
double _slider_video_value = 0;

bool isPlaying = true;

SharedPreferences prefs;

bool _subtitle_enabled = true;
int _subtitle_size = 11;
int _subtitle_color = 0;
int _subtitle_background = 0;
bool logged = false;
String subscribed = "FALSE";

@OverRide
void initState() {
Future.delayed(Duration.zero, () {
widget.next = (widget.episode != null) ? true : false;
widget.live = (widget.channel != null) ? true : false;
FocusScope.of(context).requestFocus(video_player_focus_node);
_prepareNext();
_getSubtitlesList();
_checkLogged();
});

initSettings();
super.initState();
}

void _checkLogged() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
this.logged = prefs.getBool("LOGGED_USER");
this.subscribed = prefs.getString("NEW_SUBSCRIBE_ENABLED");
}

void _prepareNext() {
if (widget.episode != null) {
if ((widget.episode + 1) <
widget.seasons[widget.season].episodes.length) {
widget.next_episode = widget.episode + 1;
widget.next_season = widget.season;
widget.next = true;
widget.next_title = widget.seasons[widget.next_season].title +
" : " +
widget.seasons[widget.next_season].episodes[widget.next_episode]
.title;
} else {
if ((widget.season + 1) < widget.seasons.length) {
if (widget.seasons[widget.season + 1].episodes.length > 0) {
widget.next_episode = 0;
widget.next_season = widget.season + 1;
widget.next = true;
widget.next_title = widget.seasons[widget.next_season].title +
" : " +
widget.seasons[widget.next_season].episodes[widget.next_episode]
.title;
} else {
widget.next = false;
}
} else {
widget.next = false;
}
}
setState(() {});
}
}

void _getSubtitlesList() async {
if (widget.channel != null) return;
_subtitlesList.clear();
setState(() {
_visibile_subtitles_loading = true;
});
model.Subtitle subtitle;
_subtitlesList.add(subtitle);
var response;
if ((widget.episode == null))
response = await apiRest.getSubtitlesByMovie(widget.poster.id);
else
response = await apiRest.getSubtitlesByEpisode(
widget.seasons[widget.season].episodes[widget.episode].id);

if (response != null) {
if (response.statusCode == 200) {
var jsonData = convert.jsonDecode(response.body);
for (Map language in jsonData) {
int count = 1;
for (Map subtitle in language["subtitles"]) {
print(subtitle["url"]);
model.Subtitle _subtitle = model.Subtitle(
id: subtitle["id"],
type: subtitle["type"],
url: subtitle["url"],
image: language["image"],
language:
language["language"] + " (" + (count).toString() + ")");
_subtitlesList.add(_subtitle);
count++;
}
}
}
}
setState(() {
_visibile_subtitles_loading = false;
});
}

void _setupDataSource(int index) async {
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network, widget.sourcesList[index].url,
videoFormat: ((widget.sourcesList[index].type == "m3u8")
? BetterPlayerVideoFormat.hls
: null),
liveStream: (widget.channel == null) ? false : true);
_betterPlayerController.setupDataSource(dataSource);
}

@OverRide
void dispose() {
// TODO: implement dispose
super.dispose();
_visibile_controllers_future.cancel();
_betterPlayerController.dispose();
_animated_controller.dispose();
video_player_focus_node.dispose();
}

@OverRide
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (visible_subscribe_dialog) {
setState(() {
visible_subscribe_dialog = false;
});
return false;
}
widget._play_next_episode = false;
if (_visibile_subtitles_dialog) {
_hideSubtitlesDialog();
return false;
}
if (visibileSourcesDialog) {
_hideSourcesDialog();
return false;
}
if (_visibile_controllers) {
_hideControllersDialog();
return false;
}
return true;
},
child: Scaffold(
backgroundColor: Colors.black,
body: RawKeyboardListener(
focusNode: video_player_focus_node,
onKey: (RawKeyEvent event) {
if (event is RawKeyDownEvent &&
event.data is RawKeyEventDataAndroid) {
RawKeyDownEvent rawKeyDownEvent = event;
RawKeyEventDataAndroid rawKeyEventDataAndroid =
rawKeyDownEvent.data;
print("Focus Node 0 ${rawKeyEventDataAndroid.keyCode}");
if (!_visibile_controll
Kleber

Kleber

Curtidas 1
POSTAR