I was looking for a Flutter package that supports RSTP for my personal project and I found this flutter_vlc_player package on pub.dev.
So, I did install the package on my project, and it worked very well on my Android simulator, but didn't worked on iOS because of some problems during the project compilation.
Then, I went into this github page and I saw a specific note that says about using the flutter_vlc_player class instead of vlc_player (like it was previously showed in pub.dev).
I followed this example on the main page but I think the code is outdated.
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
class ExampleVideo extends StatefulWidget {
@override
_ExampleVideoState createState() => _ExampleVideoState();
}
class _ExampleVideoState extends State<ExampleVideo> {
final String urlToStreamVideo = 'http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4';
final VlcPlayerController controller = new VlcPlayerController(
// Start playing as soon as the video is loaded.
onInit: (){
controller.play();
}
// you need to instantiate the controller inside the of the initState life-cycle method
);
final int playerWidth = 640; // this variable should be double, not int
final int playerHeight = 360; // this variable should be double, not int
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
height: playerHeight,
width: playerWidth,
child: new VlcPlayer(
aspectRatio: 16 / 9,
url: urlToStreamVideo,
controller: controller,
placeholder: Center(child: CircularProgressIndicator()),
)
)
);
}
}
If you copy and paste the code you’ll need to fix some issues to compile the project without errors, but still will not work neither on Android or iOS.
Finally, I did a clone of the example repository and thankfully the project worked on Android and iOS. The first difference that I saw was into the pubspec.yaml file
flutter_vlc_player:
path: ../
As we can see, it is referring a path, not a package version. If we change the code to reference the package version (^1.0.0), the project will build without errors, but will show the spinning circle Widget like a infinite loop.
The second difference in the example code that I saw, was into the Podfile on ios folder. Like I said at the beginning, my personal project fails to compile on iOS. Here is my Podfile.
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end
target 'Runner' do
use_frameworks! #my personal project have this line
use_modular_headers! #and also this line
# Flutter Pod
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'
# Plugin Pods
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
If I comment the use_framewoks! and use_modular_headers! lines my code runs perfectly on iOS.
In resume:
-
The example code on pub.dev can work in iOS if you modify the Podfile, but I don’t know if doing this can cause problems to other packages inside the project or performance issues.
-
The example code on github will not work if you change the reference for the flutter_vlc_player package.
-
It is an amazing project but I think the examples could be improved. Besides the fact that my project is working, I'm not sure if what I did is the best solution. It's okay if you need extra configuration on Android and iOS files, but this configuration needs to be very clear.
I was looking for a Flutter package that supports RSTP for my personal project and I found this flutter_vlc_player package on pub.dev.
So, I did install the package on my project, and it worked very well on my Android simulator, but didn't worked on iOS because of some problems during the project compilation.
Then, I went into this github page and I saw a specific note that says about using the flutter_vlc_player class instead of vlc_player (like it was previously showed in pub.dev).
I followed this example on the main page but I think the code is outdated.
If you copy and paste the code you’ll need to fix some issues to compile the project without errors, but still will not work neither on Android or iOS.
Finally, I did a clone of the example repository and thankfully the project worked on Android and iOS. The first difference that I saw was into the pubspec.yaml file
As we can see, it is referring a path, not a package version. If we change the code to reference the package version (^1.0.0), the project will build without errors, but will show the spinning circle Widget like a infinite loop.
The second difference in the example code that I saw, was into the Podfile on ios folder. Like I said at the beginning, my personal project fails to compile on iOS. Here is my Podfile.
If I comment the use_framewoks! and use_modular_headers! lines my code runs perfectly on iOS.
In resume:
The example code on pub.dev can work in iOS if you modify the Podfile, but I don’t know if doing this can cause problems to other packages inside the project or performance issues.
The example code on github will not work if you change the reference for the flutter_vlc_player package.
It is an amazing project but I think the examples could be improved. Besides the fact that my project is working, I'm not sure if what I did is the best solution. It's okay if you need extra configuration on Android and iOS files, but this configuration needs to be very clear.