Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video player initialization become false when WiFi is turned off. #107802

Closed
rohaitas opened this issue Jul 17, 2022 · 3 comments
Closed

Video player initialization become false when WiFi is turned off. #107802

rohaitas opened this issue Jul 17, 2022 · 3 comments
Labels
r: timeout Issue is closed due to author not providing the requested details in time

Comments

@rohaitas
Copy link

rohaitas commented Jul 17, 2022

I wanted to create my custom player on top of the video player. flutter is new to me.

StackOverflow : https://stackoverflow.com/questions/72994826/flutter-videoplayer-isinitialized-become-false-when-wifi-turn-off

VideoPlayer(_controller,)

The scenario is when the controller is successfully initialized video gets played. when I turn off wifi of device & video playback has reached the buffering position. The videoplayer becomes uninitialized on real device

I/flutter (31130): ERROR : true isInitialized : false

Same is the case with emulator, if I turn the laptop wifi off. The player is initialized true. but if i goto setting and turn emulator wifi off then it becomes false

I/flutter ( 4366): ERROR : false isInitialized : true

Now that the player initialization has become false. If I turn wifi on. I cannot play that player. if I play() the video image disappears screen becomes black. nothing happens.

_controller.play();

so i had to initialize it again to playWhen I initialize it again. The buffering is lost. and video is played from the beginning. But storing the duration I can seek to that position. but is there a way to avoid that what should i do? Why player is losing initialization on wifi?

 print("ERROR : " + _controller.value.hasError.toString()  + " isInitialized : "+ _controller.value.isInitialized.toString());

                      if (_controller.value.isInitialized && !_controller.value.hasError ) {

                        if (_controller.value.isPlaying) {
                          _controller.pause();
                        } else {
                          _controller.play();
                        }
                      }

init method

 void initState() {
super.initState();
// Set landscape orientation
SystemChrome.setPreferredOrientations([
  DeviceOrientation.landscapeLeft,
  DeviceOrientation.landscapeRight,
]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
    overlays: [SystemUiOverlay.bottom]);

isPlayerInitializing = true;

_controller = VideoPlayerController.network(widget.title);
_controller
    .initialize()
    .then((_) => setState(() {
          isPlayerInitializing = false;
          controllerVisible = false;

        }))
    .onError((error, stackTrace) => setState(() {
          print("${widget.tag} $error xxx  $stackTrace");
          isPlayerInitializing = false;
          controllerVisible = true;
        }));

_controller.addListener(() {
  //   controllerVisible = !_controller.value.isInitialized;
  //  error = _controller.value.hasError;

  //if (!_controller.value.hasError) setState(() {});
});
_controller.play();
}
@maheshmnj maheshmnj added the in triage Presently being triaged by the triage team label Jul 18, 2022
@maheshmnj
Copy link
Member

maheshmnj commented Jul 18, 2022

Hi @rohaitas, Thanks for filing the issue. Is it happening with any specific video or all videos, I tried turning off the network, But I didn't see any issue, it continues playing the buffer.

Screen.Recording.2022-07-18.at.7.24.43.PM.mov

Please share a minimal and complete code sample along with the output of flutter doctor -v

code sample
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';

void main() => runApp(VideoApp());

class VideoApp extends StatefulWidget {
  @override
  _VideoAppState createState() => _VideoAppState();
}

class _VideoAppState extends State<VideoApp> {
  late VideoPlayerController _controller;
  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4')
      ..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video Demo',
      home: Scaffold(
        body: Center(
          child: _controller.value.isInitialized
              ? AspectRatio(
                  aspectRatio: _controller.value.aspectRatio,
                  child: VideoPlayer(_controller),
                )
              : Container(),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              _controller.value.isPlaying
                  ? _controller.pause()
                  : _controller.play();
            });
          },
          child: Icon(
            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
flutter doctor -v (mac)
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-IN)
    • Flutter version 3.0.5 at /Users/mahesh/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (5 days ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-32, build-tools 33.0.0-rc4
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.67.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.44.0

[✓] Connected device (3 available)
    • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64  • Android 11 (API 30) (emulator)
    • macOS (desktop)           • macos         • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)              • chrome        • web-javascript • Google Chrome 103.0.5060.114

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@maheshmnj maheshmnj added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 18, 2022
@github-actions
Copy link

github-actions bot commented Aug 8, 2022

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.

@github-actions github-actions bot closed this as completed Aug 8, 2022
@maheshmnj maheshmnj added r: timeout Issue is closed due to author not providing the requested details in time and removed waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds in triage Presently being triaged by the triage team labels Aug 9, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: timeout Issue is closed due to author not providing the requested details in time
Projects
None yet
Development

No branches or pull requests

2 participants