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] iOS: Player doesn't open a video with whitespaces in the path #51031

Open
AAverin1994 opened this issue Feb 19, 2020 · 7 comments
Labels
found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@AAverin1994
Copy link

AAverin1994 commented Feb 19, 2020

Steps to Reproduce

  1. Create VideoPlayerController.file using the path with whitespaces
  2. Play video

Expected results: Video played

Actual results: Video isn't played, because of player not created

I think the problem is at the moment of creating the link in player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:uriArg], NSURL URLWithString:uriArg will be returned nil and the player isn't created.

@AAverin1994 AAverin1994 changed the title [video_player] Player doesn't open a video with whitespaces in the path [video_player] iOS: Player doesn't open a video with whitespaces in the path Feb 19, 2020
@TahaTesser
Copy link
Member

Hi @AAverin1994
can you please provide your flutter doctor -v and flutter run --verbose while trying to play the video?
Also, to better address the issue, would be helpful
if you could post a minimal code sample to reproduce the problem
Thank you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 19, 2020
@AAverin1994
Copy link
Author

AAverin1994 commented Feb 19, 2020

Flutter doctor

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.14.6 18G2022, locale en-RU)
    • Flutter version 1.12.13+hotfix.8 at /Users/andrewaverin/Development/flutter
    • Framework revision 0b8abb4724 (8 days ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at /Users/andrewaverin/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    ✗ Android license status unknown.
      Try reinstalling or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.7.1

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 37.1.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

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

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Flutter run

After starting the video shows nothing special

[   +2 ms] Result: {type: FlutterViewList, views: [{type: FlutterView, id: _flutterView/0x105028820, isolate: {type: @Isolate, fixedId: true, id: isolates/4425524013491043, name:
main.dart$main-4425524013491043, number: 4425524013491043}}]}
[        ] <- accept
[        ] Connected to _flutterView/0x105028820.

Sample code

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:flutter/scheduler.dart';
import 'package:async/async.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';

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

class MyApp extends StatelessWidget {
 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  VideoPlayerController _controller;
  CancelableOperation _task;
  Future<void> _initializeVideoPlayerFuture;

 @override
  void initState() {
    SchedulerBinding.instance.addPostFrameCallback((_) {
        _task = CancelableOperation.fromFuture(
            _getTestVideoPath().then((file) {
              setState(() {
                if (mounted) {
                  _controller = VideoPlayerController.file(file);
                  _initializeVideoPlayerFuture = _controller.initialize();
                  _controller.play();
                }
              });
            })
        );
    });


    super.initState();
  }

  Future<File> _getTestVideoPath() async {
    Directory documentDirectoryPath = await getApplicationDocumentsDirectory();
    return File(documentDirectoryPath.path + "/" + "test 1.mp4");
  }

  @override
  void dispose() {
    _task?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: _controller != null ? FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot) {
          return snapshot.connectionState == ConnectionState.done ? Container(
            alignment: Alignment.center,
            child: AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: VideoPlayer(_controller),
            ),
          ) : Container();
        },
      ) : Container(),// This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Test 1.mp4 - file which lies in the document directory in the phone

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 19, 2020
@TahaTesser TahaTesser added p: video_player The Video Player plugin plugin platform-ios iOS applications specifically labels Feb 19, 2020
@ihrankouski
Copy link

Observing the same issue on iOS Simulator with video_player 1.0.1

flutter doctor -v
[✓] Flutter (Channel stable, 1.22.3, on Mac OS X 10.15.7 19H2, locale en-BY)
    • Flutter version 1.22.3 at /Users/ihrankouski/Tools/flutter
    • Framework revision 8874f21e79 (9 weeks ago), 2020-10-29 14:14:35 -0700
    • Engine revision a1440ca392
    • Dart version 2.10.3

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/ihrankouski/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.10.0

[!] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

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

[✓] Connected device (1 available)
    • iPhone 11 Pro Max (mobile) • A5781925-96DF-4E0C-BCA1-3ED9074A68D4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

! Doctor found issues in 1 category.

Video plays nicely when VideoPlayerController.network() is used, but once the file is downloaded and I try to switch to .file() constructor then controller.initialize() never completes.

To make sure that the reason is whitespaces in the path I tried to save files under path_provider.getTemporaryDirectory() instead of path_provider.getApplicationSupportDirectory() (that brings whitespace in my case) - and it started to work.

@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label May 24, 2021
@maheshmnj
Copy link
Member

This issue seems related to ##40429

@maheshmnj
Copy link
Member

maheshmnj commented Jun 28, 2021

Hi @AAverin1994,
Thanks for filing the issue, I was able to reproduce this issue on the latest stable and master channel of flutter with video_player: ^2.1.6. This was the path of my video asset on my system (with space in the video name)

/Users/mahesh/Library/Developer/CoreSimulator/Devices/6A434744-B348-4FB3-AB10-131292174456/data/Containers/Data/Application/E23A8883-97B4-4746-B110-586161E6797E/Documents/dir/video 2021.mov;

I tried to play the video by using the above path but the video_player never got initialized with this path, because of a space between the video name. But when I replaced the space with utf-8 character %20 and changed the url to this

/Users/mahesh/Library/Developer/CoreSimulator/Devices/6A434744-B348-4FB3-AB10-131292174456/data/Containers/Data/Application/E23A8883-97B4-4746-B110-586161E6797E/Documents/dir/video%202021.mov;

The video is getting initialized.

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-arm, locale en-IN)
    • Flutter version 2.2.2 at /Users/mahesh/Documents/flutter
    • Framework revision d79295af24 (2 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2021.1.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

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

[✓] Connected device (3 available)
    • iPhone 12 Pro Max (mobile) • 6A434744-B348-4FB3-AB10-131292174456 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4
      (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 11.4 20F71 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 91.0.4472.114

• No issues found!
[✓] Flutter (Channel master, 2.3.0-17.0.pre.538, on macOS 11.4 20F71 darwin-arm, locale en-IN)
    • Flutter version 2.3.0-17.0.pre.538 at /Users/mahesh/Documents/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 1fd2f7c400 (6 hours ago), 2021-06-27 22:51:02 -0400
    • Engine revision 5d287a2061
    • Dart version 2.14.0 (build 2.14.0-250.0.dev)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[!] Android Studio
    • Android Studio at /Users/mahesh/.Trash/Android Studio Preview 9.57.13 PM.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2021.1.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

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

[✓] Connected device (3 available)
    • iPhone 12 Pro Max (mobile) • 6A434744-B348-4FB3-AB10-131292174456 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4
      (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 11.4 20F71 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 91.0.4472.114

! Doctor found issues in 2 categories.

@slmolloy
Copy link

I ran into this issue as well when using the VideoPlayerController.file constructor. I resolved this by using Uri.encodeFull(path). The sample code above would look something like this

Future<File> _getTestVideoPath() async {
  Directory documentDirectoryPath = await getApplicationDocumentsDirectory();
  var path = documentDirectoryPath.path + "/" + "test 1.mp4"
  return File(Uri.encodeFull(path));
}

Looks like the issue is occurring in video_player_avfoundation. URLWithString requires strings to be properly escaped.

One possible fix would be to ensure CreateMessage properly encodes the uri. Not 100% sure of best practice but might want to decode and re-encode the Uri here to prevent double encoding incase the uri provided is already encoded.
uri: Uri.encodeFull(Uri.decodeFull(uri)),

@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
@Hixie Hixie removed the plugin label Jul 6, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@vanvixi
Copy link

vanvixi commented Dec 25, 2023

Using File(Uri.encodeFull(path)) does not seem to solve this problem thoroughly. I have copied it to a new file and defined a valid name for myself:

  final newPath = await getPathDirectoryCacheFile(keyName: '${DateTime.now().toIso8601String()}copy.mp4');
  File(videoPath).copySync(newPath);
        
  final controller = VideoPlayerController.file(File(newPath))
  await controller.initialize();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
Development

No branches or pull requests

8 participants