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

Failed to load video: The operation could not be completed #10

Open
chenliang0571 opened this issue Jul 18, 2022 · 10 comments
Open

Failed to load video: The operation could not be completed #10

chenliang0571 opened this issue Jul 18, 2022 · 10 comments

Comments

@chenliang0571
Copy link

Unhandled Exception: PlatformException(VideoError, Failed to load video: The operation could not be completed, null, null)

for both network and file:

  • VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'...
  • VideoPlayerController.file(File('/tmp/Butterfly-209.mp4'))
dependencies:
  flutter:
    sdk: flutter
  video_player: ^2.4.5
  video_player_macos: 1.0.6

sample: https://github.com/chenliang0571/video_player/tree/master/video_player/example

@ollyde
Copy link
Owner

ollyde commented Jul 18, 2022

@chenliang0571

Hey, here is an example of our MacOS video view.

Please let me know if this helps, I need to update the docs.

import 'package:bap/components/label_text.dart';
import 'package:bap/utils/langauge.dart';
import 'package:chewie/chewie.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:video_player/video_player.dart';

class VideoViewMacOS extends StatefulWidget {
  final String url;

  const VideoViewMacOS({
    Key? key,
    required this.url,
  }) : super(key: key);

  @override
  State<VideoViewMacOS> createState() => _VideoViewMacOSState();
}

class _VideoViewMacOSState extends State<VideoViewMacOS> {
  late VideoPlayerController? _videoPlayerController;
  ChewieController? _chewieController;
  bool _wasError = false;

  @override
  void initState() {
    initAsync();
    super.initState();
  }

  initAsync() async {
    try {
      _videoPlayerController = VideoPlayerController.network(widget.url);
      await _videoPlayerController!.initialize();

      _chewieController = ChewieController(
        videoPlayerController: _videoPlayerController!,
        autoPlay: false,
        looping: false,
      );
      setState(() {});
    } catch (e) {
      setState(() {
        _wasError = true;
      });
      if (kDebugMode) {
        print("There was an issue loading the video player.");
        print(e);
      }
    }
  }

  @override
  void dispose() {
    _videoPlayerController?.dispose();
    _chewieController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints(
        maxHeight: 400,
      ),
      child: _loadingOrPlayer(),
    );
  }

  _loadingOrPlayer() {
    if (_chewieController == null || _wasError) {
      return _loading();
    }

    return _player();
  }

  _player() {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: AspectRatio(
        aspectRatio: 16 / 9,
        child: Chewie(
          controller: _chewieController!,
        ),
      ),
    );
  }

  _loading() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SpinKitCircle(
          color: Theme.of(context).highlightColor,
        ),
        SizedBox(height: 8),
        LabelText(lang.loadingVideo)
      ],
    );
  }
}

@chenliang0571
Copy link
Author

chenliang0571 commented Jul 18, 2022

@OllyDixon
Thank you for your quick response. It's still not working.

it hangs/stuck here:
await _videoPlayerController!.initialize();

sample code:
https://github.com/chenliang0571/video_player/tree/master/video_player/example/lib

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.4 21F79 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google
    Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] VS Code (version 1.69.1)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

@ollyde
Copy link
Owner

ollyde commented Jul 19, 2022

@chenliang0571 it has to be an issue with how the assets are delivered. Can you try hosting the asset somewhere else?

The example I've given seems to work for us :-/

@chenliang0571
Copy link
Author

@chenliang0571 it has to be an issue with how the assets are delivered. Can you try hosting the asset somewhere else?

The example I've given seems to work for us :-/

it works for network now, turns out I didn't add network access in the relevant .entitlements files.

I understand that VideoPlayerController.asset is not working for now.
How about VideoPlayerController.file? it seems not working neither.

@chenliang0571
Copy link
Author

my bad, VideoPlayerController.file works fine.

@ekuleshov
Copy link

ekuleshov commented Jul 27, 2022

my bad, VideoPlayerController.file works fine.

Could you advise what location you are opening videos from and what entitlements have you added to the macos app?

My files are under the getApplicationDocumentsDirectory() from the path_provider plugin, e.g. in a folder like:

/Users/{user name}/Library/Containers/{app id}/Data/Documents/{app name}/

The macos video player controller code never returns from the .initialize() method and I don't see any exception caught in the surrounding try/catch:

  _controller = VideoPlayerController.file(file);
  await _controller!.initialize();

Oddly if I move file to /Users/{user name}/Downloads/ the .initialize() method works.
Any ideas how to make it work with the application's own document folder?

@OllyDixon it would be great if you'd include a complete macos example project with your plugin implementation

@ollyde
Copy link
Owner

ollyde commented Aug 1, 2022

@ekuleshov hey I've been away for a few weeks. I'm mainly using this for HTTPs links.

@ekuleshov
Copy link

ekuleshov commented Aug 4, 2022

@ekuleshov hey I've been away for a few weeks. I'm mainly using this for HTTPs links.

@OllyDixon right. It works for http and some shared dirs like "Downloads" once the app has corresponding permissions.

But it does not work (with no error or anything) for the app's own internal data folder like /Users/{user name}/Library/Containers/{app id}/Data/Documents/{app name}/ the starting part of that path is returned by the official macos's path_provider plugin. I presumed there is no special permissions required for that location, yet there we are.

I'd appreciate any ideas how to debug this.

@ollyde
Copy link
Owner

ollyde commented Aug 5, 2022

@ekuleshov I think on MacOS you need to request access to other directories which is out of the scope of this library.

@ekuleshov-idexx
Copy link

@OllyDixon I'd agree with that if the folder wasn't the app-owned data folder. Besides, the app can successfully write and read files from that folder. Just the video player doesn't work when file is given from that same location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants